-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy
executable file
·131 lines (117 loc) · 2.39 KB
/
deploy
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
#!/bin/bash
init=0
copy=0
force=0
script_name=$(basename "$0")
shopt -s nullglob
local_paths=($(realpath -e */))
shopt -u nullglob
if [ -n "${SUDO_USER}" ]; then
HOME="/home/$SUDO_USER"
# TO DO: scan all scripts for used env's and replace them
fi
Help()
{
# Display Help
echo "$script_name script will deploy config files according to their respective deployment scripts with either symlink or copy."
echo
echo "Syntax: deploy [options] [arg]"
echo "options:"
echo "h Print this Help."
echo "l List available package configs."
echo "c Copy files instead of using symlinks."
echo "i Initialize dir name [arg] with script template."
echo "f Force files to replace existing."
echo "x Debug mode."
echo
}
List()
{
for local_path in "${local_paths[@]}"; do
echo "$(basename $local_path)"
done
}
Init()
{
if [ "${#script_args[@]}" -eq 0 ]; then
echo "Init requires arg. Run $script_name -h for more details."
exit 1
fi
for arg in "${script_args[@]}"; do
echo "Initializing: $arg"
if ! [ -d ./$arg ] ; then
echo "Creating $arg directory"
mkdir ./$arg
fi
if [ -e ./$arg/deploy ] && [ ${force} -eq 0 ] ; then
echo "Overwrite permission required to re-init $arg. Run $script_name -f."
continue
fi
echo "Copying template -> $arg/deploy"
cp $cp_args ./template ./$arg/deploy
done
}
Deploy()
{
if [ "${#script_args[@]}" -gt 0 ]; then
local_paths=( $(realpath -e "${script_args[@]}") )
fi
for local_path in "${local_paths[@]}"; do
echo "Deploying: $dir"
if [ -e "${local_path}/deploy" ] ; then
source "${local_path}/deploy"
else
echo "(basename $local_path) deployment missing."
fi
done
}
#########################
# Arguments and options
#########################
while getopts ":hlcif" flag
do
case "$flag" in
h)
Help
exit;;
l)
List
exit;;
c)
copy=1;;
i)
init=1;;
f)
force=1;;
x)
set -x;;
\?)
echo "$0: Error: Invalid option: -${OPTARG}" >&2;
exit 1;;
esac
done
shift $((OPTIND - 1))
script_args=("$@")
##########################
# Construct $cp_args
##########################
cp_args="s"
if [ ${init} -eq 1 ] || [ ${copy} -eq 1 ] ; then
cp_args=""
fi
if [ ${force} -eq 1 ]; then
cp_args="${cp_args}f"
fi
cp_args="-${cp_args}"
if [ ${#cp_args} -eq 1 ] ; then
cp_args=""
fi
#echo "cp args: ${cp_args}"
#############
# Go Button
#############
if [ ${init} -eq 1 ] ; then
Init
exit
fi
Deploy