forked from ndejay/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·52 lines (45 loc) · 1.14 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
#!/usr/bin/env bash
declare -a resource
while read line ; do
resource+=("$line")
done < "manifest"
case "$1" in
'rm' )
for r in "${resource[@]}" ; do
target="$HOME/$r"
if [[ -e "$target" ]] || [[ -L "$target" ]]; then
rm -i -r "$target"
echo "$target removed"
else
echo "$target does not exist: skipping"
fi
done
;;
'init' )
git submodule update --init
for r in "${resource[@]}" ; do
src="$(pwd)/$r"
target="$HOME/$r"
if [[ ! -e "$target" ]] ; then
src="${src#$HOME/}"
slashes=$(($(echo "${target/$HOME/}" | grep -o '/' | wc -l) - 1))
until [ "$slashes" -le 0 ] ; do
src="../$src"
slashes=$(($slashes - 1))
done
ln -s "$src" "$target"
echo "$target linked"
else
echo "$target already exists: skipping"
fi
done
SCRIPTPATH=`dirname ${BASH_SOURCE[0]}`
chmod 700 $SCRIPTPATH $SCRIPTPATH/.ssh $HOME/.ssh
chmod 600 $SCRIPTPATH/.ssh/authorized_keys
;;
*)
echo "install.sh: illegal mode $1" 1>&2
echo "usage: ./install.sh [init|rm]" 1>&2
exit 1
;;
esac