forked from SynologyOpenSource/pkgscripts-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SynoCustomize
executable file
·123 lines (100 loc) · 2.16 KB
/
SynoCustomize
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
#! /bin/bash
# Copyright (c) 2000-2020 Synology Inc. All rights reserved.
PackageBuilder=true # shellcheck disable=SC2034
PackageInstaller=true # shellcheck disable=SC2034
PackageCollecter=true # shellcheck disable=SC2034
CAN_BE_CLOSED="PackageBuilder PackageInstaller PackageCollecter"
UNIFORM="PackagePacker WorkerFactory EnvPrepareWorker ProjectTraverser ProjectLinker"
CUSTOMIZED="PreBuilder PostBuilder PreInstaller PostInstaller PreCollecter PostCollecter"
DO_CHECK=false
DO_EXECUTE=false
Usage()
{
cat << EOF
$0 [-c|-e] CUSTOMIZE_FILE STAGE_NAME
CUSTOMIZE_FILE the customize file to source
STAGE the stage to execute
Options
-c,
check if the stage is legal
-e,
execute the stage
EOF
}
while getopts "ceh" opt; do
case "$opt" in
c)
DO_CHECK=true
shift
;;
e)
DO_EXECUTE=true
shift
;;
h)
Usage
exit 0
;;
*)
Usage
exit 1
;;
esac
done
CUSTOMIZE_FILE="$1"
STAGE_NAME="$2"
if [ -z "$CUSTOMIZE_FILE" ]; then
exit 0
fi
if [ -f "$CUSTOMIZE_FILE" ]; then
source "$CUSTOMIZE_FILE"
fi
if [ -z "$STAGE_NAME" ]; then
echo "no input stage name"
exit 1
fi
CheckStage()
{
for stage in $CAN_BE_CLOSED; do
if [ "$STAGE_NAME" = "$stage" ]; then
if "${!STAGE_NAME}"; then
return 0
else
return 1
fi
fi
done
for stage in $UNIFORM; do
if [ "$STAGE_NAME" = "$stage" ]; then
return 0
fi
done
local is_stage_exist=false
for stage in $CUSTOMIZED; do
if [ "$STAGE_NAME" = "$stage" ]; then
is_stage_exist=true
break
fi
done
if ! $is_stage_exist; then
echo "stage [$STAGE_NAME] does not allowed."
return 1
fi
if type "$STAGE_NAME" > /dev/null 2>&1; then
return 0
else
return 1
fi
return 0
}
ExecuteStage()
{
$STAGE_NAME || return 1
}
if $DO_CHECK; then
CheckStage || exit 1
fi
if $DO_EXECUTE; then
ExecuteStage || exit 1
fi
exit 0