-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·59 lines (47 loc) · 1.1 KB
/
deploy.sh
File metadata and controls
executable file
·59 lines (47 loc) · 1.1 KB
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
#!/bin/bash
# -----------------------
# Link dotfiles under ~.
# execute './deploy.sh' for normal node and './deploy.sh force' for force mode.
# -----------------------
# Stop all if some error ocurred or undefined variable catched.
set -eu
set +u
DIR_NAME="${HOME}/dotfiles"
DOT_DIR__="${DIR_NAME}/_dotfiles"
DOT_DIR="${DIR_NAME}/dotfiles"
BACKUP_DIR="${DIR_NAME}/backup"
DEPLOY_MODE=${1}
DEPLOY_MODE=${DEPLOY_MODE:="normal"}
force_mode="force"
set -u
cd ${DIR_NAME}
link_file()
{
if [ -f "$2" ] && [ ! -L "$2" ] ; then
if [ "$DEPLOY_MODE" = "$force_mode" ] ; then
mkdir -p $(dirname $3)
mv -fv $2 $3
mkdir -p $(dirname $2)
ln -snfv $1 $2
fi
else
mkdir -p $(dirname $2)
ln -snfv $1 $2
fi
}
cd $DOT_DIR
for f in `find . -type f`
do
g=${f:2}
[ "$g" = "README.md" ] && continue
link_file "$DOT_DIR/$g" "$HOME/$g" "$BACKUP_DIR/$g"
done
cd $DOT_DIR__
for f in `find . -type f`
do
g=${f:2}
if [ ! -e "$DOT_DIR/$g" ] ; then
link_file "$DOT_DIR__/$g" "$HOME/$g" "$BACKUP_DIR/$g"
fi
done
cd ${DIR_NAME}