-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathspksrc.service.installer.dsm7
229 lines (178 loc) · 5.35 KB
/
spksrc.service.installer.dsm7
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/sh
# DSM 5 -> 7 upgrade path:
# Not supported
# DSM 6 -> 7 upgrade path:
# files are migrated from ${SYNOPKG_PKGDEST}/var to ${SYNOPKG_PKGVAR}
# Not supported (yet)
INST_ETC="/var/packages/${SYNOPKG_PKGNAME}/etc"
INST_VARIABLES="${INST_ETC}/installer-variables"
INST_VAR="${SYNOPKG_PKGVAR}"
# Optional FWPORTS file
FWPORTS_FILE="/var/packages/${SYNOPKG_PKGNAME}/conf/${SYNOPKG_PKGNAME}.sc"
TMP_DIR="${SYNOPKG_TEMP_UPGRADE_FOLDER}/var"
# Source package specific variable and functions
SVC_SETUP=`dirname $0`"/service-setup"
if [ -r "${SVC_SETUP}" ]; then
. "${SVC_SETUP}"
fi
# Reload wizard variables stored by postinst
if [ -r "${INST_VARIABLES}" ]; then
. "${INST_VARIABLES}"
fi
# Expect user to be set from package specific variables
if [ -n "${USER}" -a -z "${USER_DESC}" ]; then
USER_DESC="User running $SYNOPKG_PKGNAME"
fi
# Default description if group name provided by UI
if [ -n "${GROUP}" -a -z "${GROUP_DESC}" ]; then
GROUP_DESC="SynoCommunity Package Group"
fi
# Extract share volume and share name from download location if provided
if [ -n "${SHARE_PATH}" ]; then
SHARE_VOLUME=$(echo "${SHARE_PATH}" | awk -F/ '{print "/"$2}')
SHARE_NAME=$(echo "${SHARE_PATH}" | awk -F/ '{print $3}')
fi
# Tools shortcuts
MV="/bin/mv -f"
RM="/bin/rm -rf"
CP="/bin/cp -rfp"
MKDIR="/bin/mkdir -p"
LN="/bin/ln -nsf"
TEE="/usr/bin/tee -a"
### Functions library
log ()
{
echo "$1" 1>&2 # /var/log/packages/{package}.log
}
log_step ()
{
log $(date)
log "===> Step $1. USER=$USER GROUP=$GROUP SHARE_PATH=${SHARE_PATH}"
}
save_wizard_variables ()
{
if [ -e "${INST_VARIABLES}" ]; then
$RM "${INST_VARIABLES}"
fi
if [ -n "${GROUP}" ]; then
echo "GROUP=${GROUP}" >> ${INST_VARIABLES}
fi
if [ -n "${SHARE_PATH}" ]; then
echo "SHARE_PATH=${SHARE_PATH}" >> ${INST_VARIABLES}
fi
}
set_unix_permissions ()
{
log "${SYNOPKG_PKGNAME} has not been updated to DSM7 yet. set_unix_permissions() is no longer supported."
}
syno_remove_user ()
{
log "${SYNOPKG_PKGNAME} has not been updated to DSM7 yet. syno_remove_user() is no longer supported."
}
syno_group_create ()
{
log "${SYNOPKG_PKGNAME} has not been updated to DSM7 yet. syno_group_create() is no longer supported."
}
syno_group_remove ()
{
log "${SYNOPKG_PKGNAME} has not been updated to DSM7 yet. syno_group_remove() is no longer supported."
}
syno_user_add_to_group ()
{
log "${SYNOPKG_PKGNAME} has not been updated to DSM7 yet. syno_user_add_to_group() is no longer supported."
}
set_syno_permissions ()
{
log "${SYNOPKG_PKGNAME} has not been updated to DSM7 yet. set_syno_permissions() is no longer supported."
}
syno_user_add_to_legacy_group () {
log "${SYNOPKG_PKGNAME} has not been updated to DSM7 yet. syno_user_add_to_legacy_group() is no longer supported."
}
### Generic package behaviors
preinst ()
{
log_step "preinst"
call_func "service_preinst"
# Check volume exists
if [ -n "${SHARE_PATH}" ]; then
if [ ! -d "${SHARE_VOLUME}" ]; then
echo "Volume ${SHARE_VOLUME} does not exist." | $TEE 1>&2
exit 1
fi
fi
exit 0
}
postinst ()
{
log_step "postinst"
save_wizard_variables
# copy target/var data to permanent storage
# and don't override old configurations
if [ -d ${SYNOPKG_PKGDEST}/var ] && [ "$(find ${SYNOPKG_PKGVAR} -mindepth 1 -not -name '*.log' -print)" = "" ]; then
$CP -RT ${SYNOPKG_PKGDEST}/var/. ${SYNOPKG_PKGVAR}
fi
if [ "${SYNOPKG_PKG_STATUS}" == "INSTALL" ]; then
# Add firewall config
if [ -r "${FWPORTS_FILE}" ]; then
echo "Installing service configuration ${FWPORTS_FILE}" >> ${INST_LOG}
servicetool --install-configure-file --package "${FWPORTS_FILE}" >> ${INST_LOG} 2>&1
fi
fi
call_func "service_postinst"
call_func "service_create_links"
exit 0
}
preuninst ()
{
log_step "preuninst"
if [ "${SYNOPKG_PKG_STATUS}" == "UNINSTALL" ]; then
# Remove firewall config
if [ -r "${FWPORTS_FILE}" ]; then
echo "Removing service configuration ${SYNOPKG_PKGNAME}.sc" >> ${INST_LOG}
servicetool --remove-configure-file --package "${SYNOPKG_PKGNAME}.sc" >> ${INST_LOG} 2>&1
fi
fi
call_func "service_preuninst"
exit 0
}
postuninst ()
{
log_step "postuninst"
call_func "service_postuninst"
call_func "service_remove_links"
if [ "$wizard_delete_data" = "true" ]; then
if [ "$(ls -A ${SYNOPKG_PKGHOME})" != "" ]; then
rm -rf ${SYNOPKG_PKGHOME}/
fi
if [ "$(ls -A ${SYNOPKG_PKGVAR})" != "" ]; then
rm -rf ${SYNOPKG_PKGVAR}/
fi
if [ "$(ls -A /var/packages/${SYNOPKG_PKGNAME}/etc)" != "" ]; then
rm -rf /var/packages/${SYNOPKG_PKGNAME}/etc/
fi
if ["$(ls -A ${SYNOPKG_PKGTMP})" != "" ]; then
rm -rf ${SYNOPKG_PKGTMP}/
fi
fi
exit 0
}
preupgrade ()
{
log_step "preupgrade"
# dsm6 -> dsm7
# Migrate data to permanent storage
if [ ! "$(ls -A ${SYNOPKG_PKGVAR})" ]; then
# only migrate when destination is empty
$CP -RT ${SYNOPKG_PKGDEST}/var/. ${SYNOPKG_PKGVAR}
fi
call_func "service_preupgrade"
call_func "service_save"
exit 0
}
postupgrade ()
{
log_step "postupgrade"
call_func "service_restore"
call_func "service_postupgrade"
exit 0
}