-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·64 lines (52 loc) · 1.46 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
BACKUP_DIR="$HOME/.config_backup/$(date +%Y%m%d_%H%M%S)"
CONFIG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/configs"
backup_file() {
local file="$1"
if [ -f "$file" ]; then
mkdir -p "$BACKUP_DIR"
cp "$file" "$BACKUP_DIR/"
fi
}
deploy_config() {
local src="$1"
local dest="$2"
backup_file "$dest"
mkdir -p "$(dirname "$dest")"
cp "$src" "$dest"
}
detect_os() {
if [ -f /etc/debian_version ]; then
echo "debian"
elif [ -f /etc/fedora-release ]; then
echo "fedora"
elif [ -f /etc/arch-release ]; then
echo "arch"
elif [ "$(uname)" == "Darwin" ]; then
echo "mac"
else
echo "unknown"
fi
}
# メイン処理
main() {
local os=$(detect_os)
# OS固有のセットアップ
if [ -f "scripts/${os}.sh" ]; then
# shellcheck source=/dev/null
source "scripts/${os}.sh"
else
echo "Warning: No specific setup for ${os}"
fi
# 共通設定の配置
deploy_config "$CONFIG_DIR"/zsh/env.zsh "$HOME"/env.zsh
echo "source $HOME/env.zsh" >> "$HOME"/.zprofile
deploy_config "$CONFIG_DIR"/git/.gitignore "$HOME"/.gitignore
git config --global core.excludesfile "$HOME"/.gitignore
# 環境固有の設定があれば適用
if [ -f "configs/hosts/$(hostname)/zshrc" ]; then
cat "configs/hosts/$(hostname)/zshrc" >> "$HOME/.zshrc"
fi
echo "Configuration deployed successfully"
}
main "$@"