-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
97 lines (82 loc) · 2.01 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
89
90
91
92
93
94
95
96
97
#!/usr/bin/env sh
BASEDIR="$(dirname "$(cd "$(dirname "$0")" && pwd -P)/$(basename "$0")")"
BACKDIR=$BASEDIR/backups
HOMEDIR=$BASEDIR/home
BINDIR=$BASEDIR/bin
MISCDIR=$BASEDIR/misc
CONFIGDIR=$BASEDIR/config
HOMEDEST="$HOME"
BINDEST="$HOME"/.local/bin
CONFIGDEST="$HOME"/.config
# test_file function
## Checks whether the file is a real file, a symlink or doesn't exist.
## 0: file does not exist
## 1: file is symlink
## 2: file is real
test_file () {
if [ -L "$1" ]; then
echo 1
elif [ -e "$1" ]; then
echo 2
else
echo 0
fi
}
# link_file function
## Handles all the linking
## arg1: file source path
## arg2: file destination path
## arg3: prefix to commands (like sudo) [optional]
link_file () {
case $(test_file "$2") in
2)
fname=$(basename $2)
echo "Moving $2 to $BACKDIR/$fname"
mkdir -p "$BACKDIR"
$3 mv "$2" "$BACKDIR/$fname"
;;
1)
# echo "Removing $2"
$3 rm "$2"
;;
esac
echo "Creating link at $2"
$3 ln -s "$1" "$2"
}
# link_all_files function
## Handles all files in a folder
## arg1: Folder where files reside (source)
## args2: Target folder to link to (destination)
link_all_files () {
mkdir -p "$2"
for file in "$1"/*; do
file=$(basename "$file")
link_file "$1/$file" "$2/$file"
done
}
shopt -s dotglob
echo "Updating submodules..."
(cd "$BASEDIR" && git submodule init && git submodule update --remote --recursive)
echo
link_all_files "$HOMEDIR" "$HOMEDEST"
echo
link_all_files "$CONFIGDIR" "$CONFIGDEST"
echo
link_all_files "$BINDIR" "$BINDEST"
echo
echo "Setup less..."
lesskey "$CONFIGDIR"/less/config
echo
echo "Setup wallpaper and icons..."
yes | sudo cp "$MISCDIR/wallpaper.jpg" "/usr/share/backgrounds/"
yes | sudo cp "$MISCDIR/arch_icon.svg" "/usr/share/icons/"
echo
echo "Setup GnuPG..."
agenthome="$CONFIGDEST"/gnupg
mkdir -p "$agenthome"
link_file "$MISCDIR/gpg-agent.conf" "$agenthome/gpg-agent.conf"
echo
echo "Setup LightDM..."
yes | sudo cp "$MISCDIR"/lightdm-gtk-greeter.conf "/etc/lightdm/"
echo
shopt -u dotglob