-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·64 lines (48 loc) · 1.63 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
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
# In case this script is symbolically linked from elsewhere
# Taken from https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
source "${SCRIPT_DIR}/_shared.sh"
echo ""
echo "########## CIAO Setup: Begin ##########"
if [[ ! -d $D ]]; then
echo "--- creating ${D}"
mkdir $D
fi
if [[ ! -f $F ]]; then
echo "--- creating ${F}"
touch $F
fi
if [[ ! -f $CONFIG_PATH ]] && [[ ! -h $CONFIG_PATH ]]
then
echo "--- create default configuration file"
CONFIG_EXAMPLE_PATH=${SCRIPT_DIR}/config.example
cp $CONFIG_EXAMPLE_PATH $CONFIG_PATH
fi
if [[ ! -f $SRC_PATH ]]; then
echo "--- creating ${DEST_PATH} backup at ${SRC_PATH}"
cp $DEST_PATH $SRC_PATH
fi
if [[ ! -f $STATE ]]; then
echo "--- set initial ON state"
touch $STATE
fi
if [[ ! -d $OVERRIDES ]]; then
echo "--- creating ${OVERRIDES}"
mkdir $OVERRIDES
fi
for file_path in $(find "${SCRIPT_DIR}/overrides" -type f); do
file_name=$(basename "$file_path")
if [[ ! -h ${OVERRIDES}/${file_name} ]]; then
echo "--- linking global override ${file_name}"
ln -s ${file_path} ${OVERRIDES}/
fi
done
echo ""
echo "########## CIAO Setup: Fin ##########\n"