-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·73 lines (58 loc) · 1.82 KB
/
run.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
#!/usr/bin/env bash
set -euo pipefail
base_dir="$(cd "$(dirname "$0")" && pwd)"
LOG_FOLDER="${base_dir}/logs"
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [TARGET]... [OPTION]... [ARGUMENT]...
Basic run for III DevOps Community version.
Targets:
setup Setup III DevOps Community version (default)
clean Remove III DevOps Community version
template Update III DevOps templates to GitLab
upgrade Upgrade III DevOps Community version
runner Add or remove GitLab runner
backup Backup III DevOps Community version (not implemented)
restore Restore III DevOps Community version (not implemented)
Options:
-h, --help Print this help and exit
EOF
exit 0
}
# If $1 exist and start with '-h', or '--help', then it's a help
if [[ -n "${1-}" && "${1-}" =~ ^-h|--help$ ]]; then
usage
fi
# If $1 exist and not start with '-', then it's a target
if [[ -n "${1-}" && "${1-}" != -* ]]; then
target="${1-}"
shift
else
target="setup"
fi
target_list=(
"setup"
"clean"
"template"
"upgrade"
"runner"
"backup"
"restore"
)
# Find target in target_list
if [[ ! " ${target_list[*]} " =~ \ ${target}\ ]]; then
echo -e "\033[1;31mInvalid target\033[0m: ${target}"
usage
fi
script_command="$base_dir/scripts/${target}.sh $*"
if [[ ! -d "${LOG_FOLDER}" ]]; then
mkdir -p "${LOG_FOLDER}"
fi
if [[ -f "${LOG_FOLDER}/${target}.log" ]]; then
# Get file generate time
file_time=$(stat -c %Y "${LOG_FOLDER}/${target}.log")
mv "${LOG_FOLDER}/${target}.log" "${LOG_FOLDER}/${target}.$(date -d @$file_time +%Y%m%d%H%M%S).log"
fi
# Make sure change the working directory to the script's location
cd "$base_dir" || { echo "Cannot change directory to $base_dir" && exit 1; }
script --quiet -c "$script_command" "${LOG_FOLDER}/${target}.log"