-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·89 lines (78 loc) · 3.14 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
DOTFILES_DIR="."
XDG_CONFIG_HOME="$HOME/.config"
# --- Import Helper Functions ---
source ./helper.sh
# --- Create config dir ---
mkdir -p "$XDG_CONFIG_HOME"
# --- Different Operations based on OS ---
# MacOS
if [ "$(uname)" == "Darwin" ]; then
# Run MacOS installation script
chmod +x ./OS/MacOS/macos_install.sh
./OS/MacOS/macos_install.sh
# Ubuntu
elif [ "$(lsb_release -i 2>/dev/null | cut -f 2)" == "Ubuntu" ]; then
# Run Ubuntu installation script
chmod +x ./OS/Linux/ubuntu/ubuntu_install.sh
./OS/Linux/ubuntu/ubuntu_install.sh
# Arch
elif [ "$(lsb_release -i 2>/dev/null | cut -f 2)" == "Arch" ]; then
# Run Arch installation script
chmod +x ./OS/Linux/arch/arch_install.sh
./OS/Linux/arch/arch_install.sh
else
error "OS is not supported"
fi
# --- Install Software on System ---
ansible-playbook --ask-become-pass setup.yml
# --- Create symlinks for config files using stow ---
stow_config_directory="CONFIG"
stow_home_directory="HOME"
# MacOS
macos_stow_config_directory="./OS/MacOS/CONFIG"
macos_stow_home_directory="./OS/MacOS/HOME"
# Ubuntu
ubuntu_stow_config_directory="./OS/Linux/ubuntu/CONFIG"
ubuntu_stow_home_directory="./OS/Linux/ubuntu/HOME"
# Arch
arch_stow_config_directory="./OS/Linux/arch/CONFIG"
arch_stow_home_directory="./OS/Linux/arch/HOME"
# Linux
linux_stow_config_directory="./OS/Linux/CONFIG"
linux_stow_home_directory="./OS/Linux/HOME"
## Function to handle conflicts and convert dot- to .
handle_conflicts() {
local stow_dir="$1"
local target_dir="$2"
# Handle both files and directories within stow_dir
for item_path in $(find $stow_dir -type f -or -type d); do
local item=$(basename "$item_path")
local target_item="${item/dot-/.}" # Replace 'dot-' with '.' for target item
if [[ -e "$target_dir/$target_item" ]]; then
# Rename the conflicting item in the target directory
mv "$target_dir/$target_item" "$target_dir/$target_item.bak"
info "Renamed $target_item to $target_item.bak to resolve conflict."
fi
done
}
# Resolve conflicts by renaming existing files in the target directories
handle_conflicts "$DOTFILES_DIR/$stow_config_directory" "$XDG_CONFIG_HOME"
handle_conflicts "$DOTFILES_DIR/$stow_home_directory" "$HOME"
# MacOS
if [ "$(uname)" == "Darwin" ]; then
handle_conflicts "$DOTFILES_DIR/$macos_stow_config_directory" "$XDG_CONFIG_HOME"
handle_conflicts "$DOTFILES_DIR/$macos_stow_home_directory" "$HOME"
# Ubuntu
elif [ "$(lsb_release -i 2>/dev/null | cut -f 2)" == "Ubuntu" ]; then
handle_conflicts "$DOTFILES_DIR/$ubuntu_stow_config_directory" "$XDG_CONFIG_HOME"
handle_conflicts "$DOTFILES_DIR/$ubuntu_stow_home_directory" "$HOME"
handle_conflicts "$DOTFILES_DIR/$linux_stow_config_directory" "$XDG_CONFIG_HOME"
handle_conflicts "$DOTFILES_DIR/$linux_stow_home_directory" "$HOME"
# Arch
elif [ "$(lsb_release -i 2>/dev/null | cut -f 2)" == "Arch" ]; then
handle_conflicts "$DOTFILES_DIR/$arch_stow_config_directory" "$XDG_CONFIG_HOME"
handle_conflicts "$DOTFILES_DIR/$arch_stow_home_directory" "$HOME"
handle_conflicts "$DOTFILES_DIR/$linux_stow_config_directory" "$XDG_CONFIG_HOME"
handle_conflicts "$DOTFILES_DIR/$linux_stow_home_directory" "$HOME"
make