-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·81 lines (72 loc) · 1.91 KB
/
deploy.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
77
78
79
80
81
#!/bin/env bash
case $(uname) in
Darwin)
echo "This does not work on a Mac. Please use mac_deploy.sh" 1>&2
exit 1
;;
esac
exclude=("README.md" "scripts" "mac_deploy.sh")
dryrun=false
function print_usage () {
echo "Usage: $0 [-n] TARGET..."
echo "Create a symbolic link to each TARGET in your home directory."
echo ""
echo " -n: only print files to be linked without actually doing anything"
echo ""
echo "Existing files or or symlinks (to files or directories) will not be"
echo "touched, but directories will be linked recursively, if the directory"
echo "already exists in home."
echo "This script and files starting with an underscore will be ignored."
echo ""
echo "In order to deploy all files issue"
echo " $0 *"
echo ""
}
function create_symlink () {
if [[ -e "$HOME/.$1" ]] ; then
if [[ -h "$HOME/.$1" ]] ; then
printf "\033[0;32m"
echo "$HOME/.$1: symlink exists"
printf "\033[0m"
elif [[ -f "$HOME/.$1" ]] ; then
printf "\033[0;31m"
echo "$HOME/.$1: file exists"
printf "\033[0m"
else
for arg in "$1"/* ; do
create_symlink "$arg"
done
fi
else
printf "\033[1;34m"
echo "$HOME/.$1 --> $1"
printf "\033[0m"
if ! $dryrun ; then
ln -rs "$1" "$HOME/.$1"
fi
fi
}
if [[ $# -le 0 ]] ; then
print_usage
exit
fi
if [[ "$1" = "-n" ]] ; then
dryrun=true
shift
fi
declare -A exclude_map
for file in "${exclude[@]}" ; do
exclude_map[$file]=1
done
for arg in "$@" ; do
if [[ "$arg" != _* && "$0" != *"$arg" && ! ${exclude_map[$arg]} ]]
then
if [[ -e "$arg" ]] ; then
create_symlink "$arg"
else
echo "$arg: file not found"
print_usage
exit
fi
fi
done