-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·106 lines (85 loc) · 2.06 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
#!/usr/bin/env bash
function usage() {
cat << EOF
usage: $0 options
This script installs dotfiles in your user directory
OPTIONS:
-h Show this message
-q Quiet
EOF
}
function log() {
builtin echo $@
}
function update() {
log Updating...
pushd "$1" > /dev/null
# if [ detect dirty work tree ]; then
# log - Work tree is dirty, stashing
# git stash > /dev/null 2>&1
# fi
if [ master != "$(git rev-parse --abbrev-ref HEAD)" ]; then
log - HEAD is not "master"
# git checkout master > /dev/null 2>&1
fi
# log - Pull from origin/master
# git pull origin master 1> /dev/null 2>&1
# if [ previous branch wasnt master ]; then
# git checkout previous_branch > /dev/null 2>&1
# fi
# if [ work tree was dirty ]; then
# git stash pop > /dev/null 2>&1
# fi
popd > /dev/null
}
function locate() {
local SOURCE="$1"
local TARGET
while [ -h "$SOURCE" ]; do
TARGET="$(readlink "$SOURCE")"
if [[ $SOURCE == /* ]]; then
SOURCE="$TARGET"
else
SOURCE="$(dirname "$SOURCE")/$TARGET"
fi
done
echo $SOURCE
}
function copy_files() {
rsync -a --no-perms "$1" "$2"${3:+ --exclude="$3"}
}
function install() {
log Installing...
if [ -d "$1/install.d" ]; then
for FILE in $1/install.d/*.sh; do
if [ -r "$FILE" ]; then
log - Module $(basename "$FILE")
if [ -h "$FILE" ]; then
FILE=$(locate "$FILE")
fi
. "$FILE" "$(cd "$(dirname "$FILE")" && pwd)" $2
fi
done
fi
}
while getopts "hq" OPTION
do
case $OPTION in
h) usage
exit 1
;;
q) function log() {
# Overload function so no extra info will be echoed
return
}
;;
esac
done
SOURCE=$(dirname "$BASH_SOURCE")
if [ -f "$SOURCE/install.conf" ]; then
source "$SOURCE/install.conf"
fi
FROM=$SOURCE
TO=~/
update "$FROM"
install "$FROM" "$TO"