-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·77 lines (62 loc) · 1.94 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
#!/bin/bash
PROFILES_ROOT=$(git rev-parse --show-toplevel) || exit
echo $PROFILES_ROOT
OVERRIDE=true
[[ ! -z $2 && $2 = F ]] && OVERRIDE=true
VERBOSE=true
# must PROG
function must() {
if !(command -v "$1" >/dev/null 2>&1); then
echo "$1 not installed, exiting..."
exit 1
fi
}
# link SRC_FILE DST_DIR
# link SRC_FILE DST_DIR DST_FILE
function link() {
SRC_FILE=$1
SRC_PATH=$SRC_DIR/$SRC_FILE
DST_DIR=$2
DST_FILE=$3
# https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
# https://stackoverflow.com/questions/3427872/whats-the-difference-between-and-in-bash
# https://unix.stackexchange.com/questions/114402/inline-conditionals-for-assignment
[[ -z ${DST_FILE} ]] && DST_PATH=${DST_DIR}/$SRC_FILE || DST_PATH=${DST_DIR}/${DST_FILE}
if [[ -d ${DST_PATH} || -f ${DST_PATH} ]]; then
if [[ $OVERRIDE == true ]]; then
[[ $VERBOSE = true ]] && echo removing ${DST_PATH}
rm -rf ${DST_PATH}
else
[[ $VERBOSE = true ]] && echo ${DST_PATH} exists, skipping...
return
fi
fi
[[ $VERBOSE = true ]] && echo linking ${SRC_PATH} "->" ${DST_PATH}
# https://superuser.com/questions/645842/how-to-overwrite-a-symbolic-link-of-a-directory
ln -snf ${SRC_PATH} ${DST_PATH}
}
function source_config() {
config=$1
SRC_DIR=$PROFILES_ROOT/$(dirname $config)
[[ $VERBOSE = true ]] && echo running $SRC_DIR
source ${config}
[[ $VERBOSE = true ]] && echo
}
echo OVERRIDE: $OVERRIDE
echo VERBOSE: $VERBOSE
must git
if [[ ! -d $HOME/.oh-my-zsh ]]; then
echo oh-my-zsh not installed, try this first...
echo 'sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"'
exit
fi
# [[ ! -f $HOME/.secretrc ]] && touch $HOME/.secretrc
# chmod 600 $HOME/.secretrc
[[ $VERBOSE = true ]] && echo
if [[ ! -z $1 ]]; then
[[ -f $1/config.sh ]] && source_config $1/config.sh
else
for config in **/config.sh; do
source_config $config
done
fi