-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·55 lines (47 loc) · 1.17 KB
/
setup.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
#!/bin/bash
# set +x
SCRIPT_DIR=$(cd $(dirname $0); pwd)
SETUP_FILES=`ls -1a | grep -E '^\.' | grep -v -E '^(.|..|.git|.gitignore|.config|bin)$'`
CONFIGS=`ls -1a ${SCRIPT_DIR}/configs/. | grep -v -E '^(.|..|.git)$'`
BINS=`ls -1a ${SCRIPT_DIR}/bin/. | grep -v -E '^(.|..|.git)$'`
function create_symbolic_link() {
if [ ! -e "$2" ]; then
echo "create Symbolic link" "$2"
ln -s "$1" "$2"
else
echo "skip Symbolic link" "$2"
fi
}
function create_symbolic_links() {
for file in ${SETUP_FILES[@]}
do
create_symbolic_link "${SCRIPT_DIR}/${file}" "${HOME}/${file}"
done
}
function create_config_symbolic_links() {
if [ ! -d "${HOME}/.config" ]; then
mkdir "${HOME}/.config"
fi
for file in ${CONFIGS[@]}
do
create_symbolic_link "${SCRIPT_DIR}/configs/${file}" "${HOME}/.config/${file}"
done
}
function create_bin_symbolic_links() {
if [ ! -d "${HOME}/bin" ]; then
mkdir "${HOME}/bin"
fi
for file in ${BINS[@]}
do
create_symbolic_link "${SCRIPT_DIR}/bin/${file}" "${HOME}/bin/${file}"
done
}
function error() {
echo 'error'
exit 1
}
(
create_symbolic_links &&
create_config_symbolic_links &&
create_bin_symbolic_links
) || error