-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·76 lines (61 loc) · 1.62 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
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -eou pipefail
export USER=$(whoami)
function usage() {
echo "usage: $0 [PACKAGE]"
exit 0;
}
UPDATE=0
# environment
path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. ${path}/functions
while getopts ":hu" arg; do
case ${arg} in
h)
usage
;;
u)
UPDATE=1
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
exit 1;
;;
esac
done
shift $((OPTIND-1))
[[ $# -gt 1 ]] && usage
# install prerequisite packages
for package in "curl wget"; do
hash curl &> /dev/null || sudo apt-get install -y ${package}
done
# install and configure packages
packages=${1:-$(cd ${path} && ls -d */ | tr -d '/')}
while read package; do
install_script=${path}/${package}/install.sh
[[ -x ${install_script} ]] || {
echo "${install_script} does not exist or is not executable - skipping"
continue
}
echo "++ Installing ${package}"
UPDATE=${UPDATE} ${install_script}
# link dot files
ls ${path}/${package} | while read file; do
target=${path}/${package}/${file}
link_name=${HOME}/.${file}
# ignore +x files as assumed to be install.sh
if [ ! -x ${target} ]; then
# if the dotfile exists but differs from the configuration file detailed
# in the package, then remove and re-link
[[ -e ${link_name} ]] && diff -q ${target} ${link_name} && {
echo "${link_name} already in place... skipping"
continue
}
# backup existing configuration and link dotfile
[[ -e ${link_name} ]] && mv ${link_name} ${link_name}.bak
ln -s ${target} ${link_name}
fi
done
done <<< "${packages}"
echo
echo "Done!"