-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·110 lines (83 loc) · 2.89 KB
/
install
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
#!/usr/bin/bash
################################################################################
### File: install
### Auth: a
### Date: 2019-12-25
### Info: Update local copies of the config file and creates symbolic links
################################################################################
# TODO
# create a merge function with an interactive option or clobber
# add getopts for clap
################################################################################
### Vars
################################################################################
# Check if homie env var is set, else, find it
if [ -z $HOMIE ]; then
HOMIE_DIR=$(find $HOME -name "homie")
else
HOMIE_DIR=$HOMIE
fi
CONFIG_DIR="${HOME}/.config"
SCRIPT_DIR="${HOME}/.local/scripts"
if ! [ -d $CONFIG_DIR ]; then
printf "CREATE: Config dir not found; making config dir\n"
mkdir -p $CONFIG_DIR
fi
if ! [ -d $SCRIPT_DIR ]; then
printf "CREATE: Scripts dir not found; making scripts dir\n"
mkdir -p $SCRIPT_DIR
fi
shopt -s nullglob
CONFIGS=( $HOMIE_DIR/config/* )
SCRIPTS=( $HOMIE_DIR/scripts/* )
shopt -u nullglob
# if debug
printf "Configs: \n"
for c in ${CONFIGS[@]}; do
printf "\t${c}\n"
done
# if debug
printf "Scripts: \n"
for s in ${SCRIPTS[@]}; do
printf "\t${s}\n"
done
# update homie repo
printf "UPDATING: Pulling latest version from Github"
git pull
################################################################################
### Config
################################################################################
# Make sure the config directory exist
if [ ! -d $CONFIG_DIR ]; then
mkdir -p $CONFIG_DIR
else
for entry in ${CONFIGS[@]}; do
# If it is a dir, remove existing dir in .config and symlink
if [ -d $entry ] && ! [ -h $CONFIG_DIR/$(basename $entry) ]; then
printf "LINKING: ${entry} -> ${CONFIG_DIR}/$(basename ${entry})\n"
ln -sf "${entry}" "${CONFIG_DIR}/$(basename ${entry})"
# If it is a file, symlink in home
elif [ -f $entry ] && ! [ -h $HOME/.$(basename ${entry}) ]; then
printf "LINKING: ${entry} -> ${HOME}/.$(basename ${entry})\n"
ln -sf "${entry}" "${HOME}/.$(basename ${entry})"
else
printf "SKIPPING: $(basename ${entry}) is already symlinked\n"
fi
done
fi
################################################################################
### Scripts
################################################################################
if ! [ -d $SCRIPT_DIR ]; then
mkdir -p $SCRIPT_DIR
fi
# Symlink dir and leave it at that
for entry in ${SCRIPTS[@]}; do
if ! [ -s "${SCRIPT_DIR}/$(basename ${entry})" ]; then
printf "LINKING: ${entry} -> ${SCRIPT_DIR}/$(basename ${entry})\n"
ln -sf "${entry}" "${SCRIPT_DIR}/$(basename ${entry})"
else
printf "SKIPPING: $(basename ${entry}) is already symlinked\n"
fi
done
#vim: ts=4:ss=4:ff=sh