-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·71 lines (60 loc) · 1.79 KB
/
bootstrap.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
#!/bin/sh
recursive_setup() {
# TODO: split this up in composable function so that different functions are used for copy and link
# $1 is the root directory
# $2 is the command that should be used to link/copy
dir_path=$project_root/$1
for file in $(find $dir_path ! -path $dir_path); do
base_file=${file#$dir_path}
home_twin=$HOME$base_file
if [ -d $file ] && [ ! -d $home_twin ]; then
if [ -e $home_twin ]; then
printf "Error: can't create directory $home_twin; a file is present already. Aborting\n"
exit 1
else
mkdir $home_twin
fi
elif [ -h $home_twin ] && type readlink > /dev/null 2>&1 && [ $(readlink $home_twin) != $file ]; then
ln -sf $file $home_twin #overwrite incorrect links
elif [ -f $file ] && [ ! -h $home_twin ]; then
if [ -f $home_twin ]; then
printf "The file $file already exists. Overwrite it? (y=yes n=no a=archive) "
while true; do
read choice
case $choice in
n)
continue 2
;;
a)
archi_path=$HOME/dotarchive
if [ ! -e $archi_path ]; then
mkdir $archi_path
fi
if [ ! -e $archi_path$base_file ]; then
mv $home_twin $archi_path
break
else
printf "Error: another $base_file file is present in $archi_path. Aborting\n"
exit 1
fi
;;
y)
break
;;
*)
printf 'Invalid choice. Try again, shall I overwrite it ? (y=yes n=no a=archive) '
;;
esac
done
fi
$2 $file $home_twin
fi
done
}
cd $(dirname $0) # go to the directory containing this script
project_root=$(pwd -P) # get cwd so we are sure `$project_root` is not a symlink
link='ln -sf'
recursive_setup 'public' "$link"
if [ $USER = 'getkey' -o $USER = 'mourerj' -o $USER = 'julien' ]; then
recursive_setup 'personal' "$link"
fi