-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_symbolic_links.sh
executable file
·115 lines (96 loc) · 2.51 KB
/
create_symbolic_links.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
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
107
108
109
110
111
112
113
114
115
#!/bin/bash
confirm () {
# call with a prompt string or use a default
read -r -p "$1 " response
case $response in
[yY])
true
;;
*)
false
;;
esac
}
display_usage() {
echo "\nDescription:\n\n"
echo "\nUsage:\n$0 "
echo "\nExample:\n$0 \n"
}
# default values for input arguments
ignore=false
# array containing mandatory arguments
#declare -a mandatoryArgs=(repoDir installDir)
# now read and parse the input arguments, some have options, others don't
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{ st = index($0,"=");print substr($0,st+1)}'`
case $PARAM in
"-h"|"--help")
display_usage
exit 1
;;
"-i"|"--ignore")
ignore=true
echo "Existing files will be ignored, i.e. they will *not* be symlinked again *nor* removed"
;;
*)
echo "Option $PARAM not recognized!"
echo "Type '${0} --help' for information on how to use the script"
exit 1
;;
esac
shift
done
dir=$(pwd)
# Check if $HOME/bin directory exists
if [ ! -d "~/bin" ] ; then
mkdir ~/bin
fi
for file in bin/*; do
file_name=$(basename "$file")
new_file=$dir/bin/$file_name
local_file=$HOME/bin/$file_name
if [ -f $local_file ] ; then
if [ "$ignore" = false ] ; then
echo ''
echo WARNING: The $local_file file already exists.
confirm 'Are you sure you want to replace it? (y/n)' && rm $local_file
fi
fi
if [ ! -f $local_file ] ; then
echo Creating symbolic link of $new_file
ln -sf $new_file $local_file
fi
done
# Check if directories exist
files=( .vim .zprezto .tmux )
for file in "${files[@]}"; do
local_file=~/$file
new_file=$dir/$file
if [ -d $local_file ] ; then
if [ "$ignore" = false ] ; then
echo ''
echo WARNING: The $local_file directory already exists.
confirm 'Are you sure you want to replace it? (y/n)' && rm -rf $local_file
fi
fi
if [ ! -d $local_file ] ; then
ln -s $new_file $local_file
fi
done
# Check if files exist
files=( .vimrc .zshrc.local .matplotlib/matplotlibrc .tmux.conf .git-flow-completion.zsh )
for file in "${files[@]}"; do
local_file=~/$file
new_file=$dir/$file
if [ -f $local_file ] ; then
if [ "$ignore" = false ] ; then
echo ''
echo WARNING: The $local_file file already exists.
confirm 'Are you sure you want to replace it? (y/n)' && rm $local_file
fi
fi
if [ ! -f $local_file ] ; then
ln -s $new_file $local_file
fi
done