-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·137 lines (116 loc) · 3.26 KB
/
bootstrap
File metadata and controls
executable file
·137 lines (116 loc) · 3.26 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env bash
# Colors
COLOR_OFF='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[00;34m'
# Logging tag
INFO="\r [ $BLUE..$COLOR_OFF ]"
USER="\r [ $YELLOW??$COLOR_OFF ]"
ALERT="\r [ $RED!!$COLOR_OFF ]"
SUCCESS="\r\033[2K [ ${GREEN}OK$COLOR_OFF ]"
FAIL="\r\033[2K [${RED}FAIL$COLOR_OFF]"
set -eu
setup_nala () {
if ! test $(which nala)
then
printf "$INFO Installing nala (apt wrapper)\n"
sudo apt-get install nala -y
printf "$SUCCESS nala installed\n"
fi
}
setup_stow () {
if ! test $(which stow)
then
printf "$INFO Installing stow (for sym linking)\n"
sudo nala install stow -y
printf "$SUCCESS stow installed\n"
fi
}
delete_dotfiles () {
for file in $1
do
if [ -f $HOME/$file ] || [ -L $HOME/$file ]
then
rm -f "$HOME/$file"
printf "$INFO Deleted dotfile $HOME/$file\n"
fi
done
}
backup_system_files () {
for file in $1
do
if [ -f /$file ] || [ -L /$file ]
then
sudo cp /$file /$file.bak
printf "$INFO backup created: /$file.bak\n"
fi
done
}
delete_system_files () {
for file in $1
do
if [ -f /$file ] || [ -L /$file ]
then
sudo rm -f "/$file"
printf "$INFO Deleted system file: /$file\n"
fi
done
}
install_dotfiles () {
printf "$INFO Installing dotfiles\n"
for package in $(find -mindepth 1 -maxdepth 1 -not -empty -not -path '*/\.git' -not -name 'packages' -not -name 'system' -type d | sed 's|^./||')
do
printf "$INFO Installing dotfiles for $package\n"
CONFLICTS=$(stow --no --verbose $package 2>&1 | awk '/\* existing target is/ {print $NF}')
if [ -n "$CONFLICTS" ]
then
printf "$ALERT Do you want to overwrite the following exising config files?\n"
echo $CONFLICTS | tr ' ' '\n'
read -p "y/N> " -e action
if [ "$action" = 'y' ] || [ "$action" = 'yes' ]
then
delete_dotfiles "$CONFLICTS"
stow --no-folding --verbose $package
printf "$SUCCESS Dotfiles installed for $package\n"
else
printf "$INFO Skipping dotfiles for $package\n"
fi
else
stow --no-folding --verbose $package
printf "$SUCCESS Dotfiles installed for $package\n"
fi
done
}
install_system_dotfiles () {
printf "$INFO Installing system dotfiles\n"
CONFLICTS=$(stow --no --verbose -t / system 2>&1 | awk '/\* existing target is/ {print $NF}')
if [ -n "$CONFLICTS" ]
then
printf "$ALERT The following system files already exists\n"
echo $CONFLICTS | tr ' ' '\n'
read -p "Overwrite? y/N> " -e action
if [ "$action" = 'y' ] || [ "$action" = 'yes' ]
then
read -p "Make a backup? Y/n> " -e backup
if [ "$backup" != 'n' ] || [ "$backup" != 'no' ]
then
backup_system_files "$CONFLICTS"
fi
delete_system_files "$CONFLICTS"
sudo stow --no-folding --verbose -t / system
printf "$SUCCESS Dotfiles installed for system\n"
else
printf "$INFO Skipping dotfiles for system\n"
fi
else
sudo stow --no-folding --verbose -t / system
printf "$SUCCESS Dotfiles installed for system\n"
fi
}
setup_nala
setup_stow
install_dotfiles
# install_system_dotfiles # removing system setup as it was a bad idea to have system files modifiable by user
printf "$SUCCESS Finished!\n"