-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
Β·200 lines (154 loc) Β· 3.81 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env bash
###########################################
# dotfile-installer #
# by Kevin Kandlbinder <[email protected]> #
# https://github.com/Unkn0wnCat/ #
###########################################
# Define parameters.
INSTALL_DIR=$HOME
BACKUP_DIR_BASE=$INSTALL_DIR/dotfiles_backup
BACKUP_DIR=$BACKUP_DIR_BASE/$(date +"%Y-%m-%d_%H-%M-%S")
# Push current directory.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"
pushd $DIR > /dev/null
# Figure out OS and OS-Version.
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
# Older SuSE/etc.
...
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
...
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
OS=${OS/\//_}
OS=${OS/ /_}
VER=${VER/\//_}
VER=${VER/ /_}
# Parse commandline-switches.
for i in "$@"
do
case $i in
--symlink)
SYMLINK=Yes
;;
*)
;;
esac
done
# Define functions.
remove_dot_and_dotdot_dirs()
{
sed \
-e 's/^[.]\{1,2\}\x00//' \
-e 's/\x00[.]\{1,2\}\x00/\x00/g'
}
remove_leading_dotslash()
{
sed \
-e 's/^[.]\///' \
-e 's/\x00[.]\//\x00/g'
}
install_dotfile ()
{
local FILE=$1
echo " Installing $FILE..."
if [ -a "$INSTALL_DIR/$FILE" ]; then
if [ -d "$INSTALL_DIR/$FILE" ]; then
local DIR_BACKED_UP=Yes
fi
if [ -a "$BACKUP_DIR/$FILE" ]; then
if [ -d "$INSTALL_DIR/$FILE" ]; then
echo " Overwrite-merging directory $file..."
else
echo " Overwriting previously installed file $FILE..."
rm -r $INSTALL_DIR/$FILE
fi
else
echo " $FILE exists, backing up..."
mkdir -p $BACKUP_DIR
mv $INSTALL_DIR/$FILE $BACKUP_DIR
fi
fi
if [ "$SYMLINK" == Yes ]; then
ln -s $(realpath $FILE) $INSTALL_DIR/$FILE
else
cp -f -r $FILE $INSTALL_DIR
fi
if [ "$DIR_BACKED_UP" == Yes ]; then
echo " Merging with old directory..."
cp -n -r $BACKUP_DIR/$FILE $INSTALL_DIR
fi
}
install_directory ()
{
local DIRECTORY=$1
pushd $DIRECTORY > /dev/null
find . -maxdepth 1 -print0 |
sort -z |
remove_dot_and_dotdot_dirs |
remove_leading_dotslash |
while read -r -d "" filename
do
install_dotfile $filename
done
popd > /dev/null
}
# Execute pre-install-scripts.
for f in ./scripts/pre-install.d/*.sh; do
bash "$f" -H
done
# Install dotfiles.
## Install base-files.
echo "Installing base..."
install_directory ./base
## Install os-configs.
echo "Searching for OS-base-config at ./os/$OS-base"
if [ -d "./os/$OS-base" ]; then
echo "Installing OS-base-config..."
install_directory ./os/$OS-base
else
echo "No OS-base-config found. Skipping."
fi
echo "Searching for OS-version-config at ./os/$OS-$VER"
if [ -d "./os/$OS-$VER" ]; then
echo "Installing OS-version-config..."
install_directory ./os/$OS-$VER
else
echo "No OS-version-config found. Skipping."
fi
## Install host-config.
echo "Searching for host-config at ./host/$(hostname)"
if [ -d "./host/$(hostname)" ]; then
echo "Installing host-config..."
install_directory ./host/$(hostname)
else
echo "No host-config found. Skipping."
fi
# Execute post-install-scripts.
for f in ./scripts/post-install.d/*.sh; do
bash "$f" -H
done
# Done!
popd > /dev/null
exit 0