-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotfiles.sh
executable file
·103 lines (93 loc) · 2.07 KB
/
dotfiles.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
configDir=$HOME/.config/
rootDir=$HOME/
path=$(realpath "$0")
dir=$(dirname "$path")
configDirs=("termite" "i3" "polybar" "mopidy" "gtk-3.0" "opera" "ncmpcpp")
rootDirs=("git" "vim" "bash" "x")
rootFiles=$(find $rootDirs -type f | awk -F/ '{print $2}')
configFiles=$(find $configDirs -type f)
backupDir=${rootDir}dotfiles.old
helpFunction()
{
echo ""
echo "Usage: $0 [options]"
echo ""
echo "OPTIONS"
echo ""
echo -e "\t-h Display this help"
echo -e "\t-u Uninstall dot files"
exit 1
}
install()
{
cd $dir
echo "Installing..."
for appDir in ${rootDirs[@]}; do
stow -v -t $rootDir $appDir
done
for appDir in ${configDirs[@]}; do
stow -v -t ${configDir}${appDir} ${appDir}
done
echo "Done."
}
backup()
{
echo "Backing up..."
mkdir -p ${backupDir}
cd $dir
for file in ${configFiles[@]}; do
cp -vrL ${configDir}$file ${backupDir}
rm -vrf ${configDir}$file
done
for file in ${rootFiles[@]}; do
cp -vrL ${rootDir}$file ${backupDir}
rm -vrf ${rootDir}$file
done
echo "Done."
}
rollback()
{
echo "Rolling back..."
cd $backupDir
for file in ${configFiles[@]}; do
cp -r $file ${configDir}$file
done
for file in ${rootFiles[@]}; do
cp -r $file ${rootDir}$file
done
cd $rootDir && rm -vrf $backupDir
echo "Done."
}
uninstall()
{
cd $dir
echo "Uninstall in progress..."
for appDir in ${rootDirs[@]}; do
stow -v -D ${appDir} -t ${rootDir}
done
for appDir in ${configDirs[@]}; do
stow -v -D ${appDir} -t ${configDir}${appDir}
done
echo "Done."
}
while getopts "hu" opt
do
case "$opt" in
h ) helpFunction ;;
u ) uninstall ;;
* ) helpFunction ;;
esac
done
if (($OPTIND == 1)); then
backup
install
fi
#stow -t ~ git vim bash x
#stow -t ~/.config/termite termite
#stow -t ~/.config/i3 i3
#stow -t ~/.config/polybar polybar
#stow -t ~/.config/mopidy mopidy
#stow -t ~/.config/gtk-3.0 gtk-3.0
#stow -t ~/.config/opera opera
#stow -t ~/.config/ncmpcpp ncmpcpp