-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.bash
executable file
·136 lines (105 loc) · 2.65 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# ERRORS CODE
E_BADARGS=11
E_BADLOCATION=12
E_MISSING_VAR=13
E_UNAVAILABLE_ENV=14
E_MISSING_DEPENDNCIES=15
# CONST
TARGETS_FOLDER="Targets"
usage()
{
cat <<UsagePrint
Usage :
./deploy.bash -t target [-d] [-h]
./deploy.bash --target target [--debug] [--help]
Target: Is mandatory and represent a configuration directory in Tragets
Debug: Stop on exception and show execution script line by line (set -x)
Help : Print this help
UsagePrint
exit $E_BADARGS
}
set -e
options=$(getopt -a "$(basename $0)" -l "target:,help,debug" -- "t:hd" "$@" || { usage >&2 && false; })
# {....} is grouping output see : https://www.linux.com/topic/desktop/all-about-curly-braces-bash/
eval set --$options
while [ ! -z "$1" ]
do
case "$1" in
-t) target="$2"; shift ;;
-h) usage ;;
-d) debug=1 ;;
--target) target="$2"; shift ;;
--help) usage ;;
--debug) debug=1 ;;
esac
shift
done
if [ -z "$target" ]; then
echo "target option is mandatory"
exit $E_BADARGS;
fi
close_stderr_stdout()
{
exec 11>&1 12>&2 1>&- 2>&-
}
restore_stderr_stdout()
{
exec 1>&11 2>&12 11>&- 12>&-
}
clean()
{
rm -${v}f $HOME/{.vimrc,.screenrc,.gitconfig,.gitignore_global,.alacritty.toml,.zshrc,.zsh_bindkey,.tmux.conf}
rm -${v}f $HOME/.bashrc
rm -r${v}f $HOME/.vim/bundle/*
# L'expansion avec les accolad ne semble pas fonctionner pour les dossiers
rm -${v}rf "$HOME/.oh-my-zsh" "$HOME/.vim" $HOME/.config/procps $HOME/.config/nvim
}
deploy()
{
mkdir -p $HOME/.config/procps
ln -s $ACTIVE_PATH/.screenrc $HOME/.screenrc
ln -s $ACTIVE_PATH/.gitignore_global $HOME/.gitignore_global
ln -s $ACTIVE_PATH/.gitconfig $HOME/.gitconfig
ln -s $ACTIVE_PATH/.alacritty.toml $HOME/.alacritty.toml
ln -s $ACTIVE_PATH/toprc $HOME/.config/procps/toprc
ln -s $ACTIVE_PATH/.bashrc $HOME/.bashrc
ln -s $ACTIVE_PATH/.zshrc $HOME/.zshrc
ln -s $ACTIVE_PATH/.zsh_bindkey $HOME/.zsh_bindkey
ln -s $PWD/nvim $HOME/.config/nvim
ln -s $ACTIVE_PATH/.tmux.conf $HOME/.tmux.conf
}
debug()
{
set -x
}
source ./src/check-project.bash
check
if [ $? -ne 0 ]; then
exit $?
fi
cat <<'WARNING'
Be careful all your configuration's file in your home will be supressed and
taken from my git.
WARNING
echo -n 'Are you sure ? (type "No" to quit) '
read answer
if [[ $answer == "No" ]]; then
exit 0
fi
ACTIVE_PATH="$PWD/Targets/$target"
if [[ $debug -eq 1 ]]; then
debug
else
close_stderr_stdout
fi
clean
deploy
CUSTOMS_SCRIPT=$(find $ACTIVE_PATH/custom.d/ -type f -name "*.bash");
if [ ! -z $CUSTOMS_SCRIPT ]; then
for s in $CUSTOMS_SCRIPT; do
source $s
done
fi
restore_stderr_stdout
exit 0