-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.bash
executable file
·76 lines (63 loc) · 1.32 KB
/
deploy.bash
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
#!/bin/bash
#
# Create symlinks for environment files.
set -e
shopt -s extglob
die() {
echo "Error: $1" >&2
exit 1
}
symlink() {
SRC="$1"
DEST="$2"
if [ -e "$DEST" ] && [ ! -L "$DEST" ]; then
die "file exists: $DEST"
fi
echo "deploying: $DEST"
rm -f "$DEST"
ln -s "$SRC" "$DEST"
}
[ -d .git ] || die "run from git root"
REPOS_PATH="$PWD"
# bin scripts
#
if [ -d bin ]; then
scripts=`ls bin/`
mkdir -p ~/bin
cd ~/bin
for file in $scripts; do
symlink "$REPOS_PATH/bin/$file" "${file%.*}"
done
fi
# dotfiles
#
cd $REPOS_PATH/dotfiles
find . -type f -or -type l | sed 's/^..//' | while read path; do
dir=`sed -n '/\//s|/[^/]*$||p' <<< $path` # (empty if at pwd)
file=`basename $path`
if [ "$dir" ]; then
mkdir -p ~/.$dir
cd ~/.$dir
else
file=".$file"
cd ~
fi
symlink "$REPOS_PATH/dotfiles/$path" "$file"
done
# crons
#
if [ "$1" = "do-cron" ]; then
cd $REPOS_PATH/cron
for file in *; do
fields=`grep '^# cron:' $file | sed 's/.*cron: //'`
[ "$fields" = "no-auto-deploy" ] && continue
line="$fields $REPOS_PATH/cron/$file"
if crontab -l | grep -q "$file"; then
echo "updating cron: $file"
crontab -l | sed "/$file/s|.*|$line|" | crontab -
else
echo "adding cron: $file"
( crontab -l ; echo "$line" ) | crontab -
fi
done
fi