-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-dotfiles.sh
executable file
·151 lines (123 loc) · 4.05 KB
/
install-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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#~/bin/sh
USER_HOME="/home/$USER1"
FAKE_USER_HOME="$USER_HOME/home"
DOTFILES_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SYMLINK_FROM_TO=(
"at_login.sh" ".config"
"awesome" ".config"
"nvim" ".config"
"alacritty" ".config"
"ttyper" ".config"
"redshift" ".config"
"copyq" ".config"
"fish" ".config"
"xsessions" ".config"
"cmus/autosave" ".config"
"cmus/red_theme.theme" ".config"
"cmus/notify.sh" ".config"
"topgrade.toml" ".config"
"neofetch" ".config"
"chromium/Default/Extensions" ".config"
"chromium/Default/Sync Extension Settings" ".config"
"chromium/Default/Managed Extension Settings" ".config"
"chromium/Default/Local Extension Settings" ".config"
"BetterDiscord/plugins" ".config"
".bashrc" ""
)
# If path starts with %, will not override
COPY_FROM_TO=(
"chromium/Default/Preferences" ".config"
"chromium/Default/Cookies" "%.config"
"chromium/Local State" ".config"
"chromium-flags.conf" ".config"
"tutanota-desktop/conf.json" ".config"
"discord/settings.json" ".config"
"FreeTube/settings.db" ".config"
"multimc/multimc.cfg" ".local/share"
"tutanota-desktop.desktop" ".local/share/applications"
"gtk-2.0" ".config"
"gtk-3.0" ".config"
"gtk-4.0" ".config"
"qt5ct" ".config"
"kdeglobals" ".config"
"keepassxc" ".config"
)
LINK_HOME_DIRS=(
".config"
".local"
"Documents"
"Downloads"
"Pictures"
"Videos"
"Programming"
"VM"
"Games"
"Temp"
"Music"
)
LGREEN='\033[1;32m'
GREEN='\033[0;32m'
LBLUE='\033[1;34m'
NC='\033[0m'
function confirm() {
echo -en "$LBLUE |||$GREEN Do you want to override ${LGREEN}$1 $2 $3 $LBLUE(Y/n)? >> $NC"
if [ ! -z $YOLO ] && [ $YOLO -eq 1 ]; then
echo "y"
rm -r "$1"
return
fi
read choice
case "$choice" in
y|Y|"" ) rm -r "$1";;
n|N ) return;;
* ) confirm $1 $2 $3; return;;
esac
}
mkdir -p $USER_HOME
mkdir -p $FAKE_USER_HOME
for dir in "${LINK_HOME_DIRS[@]}"; do
DEST="$USER_HOME/$dir"
if [ -h "$DEST" ]; then unlink "$DEST"; fi
if [ -e "$DEST" ]; then confirm $DEST; fi
mkdir -p $FAKE_USER_HOME/$dir
ln -sfT $FAKE_USER_HOME/$dir $DEST
done
for (( i=0; i<${#SYMLINK_FROM_TO[@]}; i+=2 )); do
FROM=${SYMLINK_FROM_TO[i]}
DEST1=${SYMLINK_FROM_TO[$(expr $i + 1)]}
OVERRIDE=1
if [[ $DEST1 = %* ]]; then OVERRIDE=0; DEST1="${DEST1:1}"; fi
DEST="$USER_HOME/$DEST1/$FROM"
FROM="$DOTFILES_DIR/dotfiles/$FROM"
if [ $OVERRIDE -eq 1 ] || [ ! -e "$DEST" ]; then
if [ -h "$DEST" ]; then unlink "$DEST"; fi
if [ -e "$DEST" ]; then confirm "$DEST"; fi
mkdir -p "$(dirname $DEST | head --lines 1)"
ln -sfT "$FROM" "$DEST"
chown -R $USER1:$USER1 "$DEST"
fi
done
for (( i=0; i<${#COPY_FROM_TO[@]}; i+=2 )); do
FROM=${COPY_FROM_TO[i]}
DEST1=${COPY_FROM_TO[$(expr $i + 1)]}
OVERRIDE=1
if [[ $DEST1 = %* ]]; then OVERRIDE=0; DEST1="${DEST1:1}"; fi
DEST="$USER_HOME/$DEST1/$FROM"
FROM="$DOTFILES_DIR/dotfiles/$FROM"
#printf "$FROM -> $DEST\n$OVERRIDE\n"
if [ $OVERRIDE -eq 1 ] || [ ! -e "$DEST" ]; then
if [ -h "$DEST" ]; then unlink "$DEST"; fi
if [ -e "$DEST" ]; then confirm "$DEST"; fi
mkdir -p "$(dirname $DEST | head --lines 1)"
cp -rf "$FROM" "$DEST"
chown -R $USER1:$USER1 "$DEST"
fi
done
ESCAPED_USER_HOME=$(printf '%s\n' "$USER_HOME" | sed -e 's/[\/&]/\\&/g')
sed -i "s/USER_HOME/$ESCAPED_USER_HOME/g" $USER_HOME/.local/share/multimc/multimc.cfg
ESCAPED_HOSTNAME=$(printf '%s\n' "$(hostname)" | sed -e 's/[\/&]/\\&/g')
sed -i "s/HOSTNAME/$ESCAPED_HOSTNAME/g" $USER_HOME/.local/share/multimc/multimc.cfg
chmod +x $USER_HOME/.config/awesome/run/run.sh
chmod +x $USER_HOME/.config/at_login.sh
# Update nvim plugins
nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync' > /dev/null 2>&1