forked from SynoCommunity/spksrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.sh
129 lines (99 loc) · 2.85 KB
/
installer.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
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
#!/bin/sh
# Package
PACKAGE="homeassistant"
DNAME="Home Assistant"
# Others
INSTALL_DIR="/usr/local/${PACKAGE}"
SSS="/var/packages/${PACKAGE}/scripts/start-stop-status"
PYTHON_DIR="/usr/local/python3"
PATH="${INSTALL_DIR}/env/bin:${PYTHON_DIR}/bin:${PATH}"
USER="homeassistant"
GROUP="users"
VIRTUALENV="${PYTHON_DIR}/bin/virtualenv"
CONFIG_DIR="${INSTALL_DIR}/var"
TMP_DIR="${SYNOPKG_PKGDEST}/../../@tmp"
SERVICETOOL="/usr/syno/bin/servicetool"
FWPORTS="/var/packages/${PACKAGE}/scripts/${PACKAGE}.sc"
SYNO_GROUP="sc-download"
SYNO_GROUP_DESC="SynoCommunity's download related group"
syno_group_create ()
{
# Create syno group (Does nothing when group already exists)
synogroup --add ${SYNO_GROUP} ${USER} > /dev/null
# Set description of the syno group
synogroup --descset ${SYNO_GROUP} "${SYNO_GROUP_DESC}"
# Add user to syno group (Does nothing when user already in the group)
addgroup ${USER} ${SYNO_GROUP}
}
syno_group_remove ()
{
# Remove user from syno group
delgroup ${USER} ${SYNO_GROUP}
# Check if syno group is empty
if ! synogroup --get ${SYNO_GROUP} | grep -q "0:"; then
# Remove syno group
synogroup --del ${SYNO_GROUP} > /dev/null
fi
}
preinst ()
{
exit 0
}
postinst ()
{
# Link
ln -s ${SYNOPKG_PKGDEST} ${INSTALL_DIR}
# Install busybox stuff
${INSTALL_DIR}/bin/busybox --install ${INSTALL_DIR}/bin
# Create a Python virtualenv
${VIRTUALENV} --system-site-packages ${INSTALL_DIR}/env > /dev/null
# Install the wheels
${INSTALL_DIR}/env/bin/pip install --no-deps --no-index -U --force-reinstall -f ${INSTALL_DIR}/share/wheelhouse ${INSTALL_DIR}/share/wheelhouse/*.whl > /dev/null 2>&1
# Create user
adduser -h ${INSTALL_DIR}/var -g "${DNAME} User" -G ${GROUP} -s /bin/sh -S -D ${USER}
syno_group_create
# Correct the files ownership
chown -R ${USER}:root ${SYNOPKG_PKGDEST}
# Add firewall config
${SERVICETOOL} --install-configure-file --package ${FWPORTS} >> /dev/null
exit 0
}
preuninst ()
{
# Stop the package
${SSS} stop > /dev/null
# Remove the user if uninstalling
if [ "${SYNOPKG_PKG_STATUS}" == "UNINSTALL" ]; then
syno_group_remove
delgroup ${USER} ${GROUP}
deluser ${USER}
fi
# Remove firewall config
if [ "${SYNOPKG_PKG_STATUS}" == "UNINSTALL" ]; then
${SERVICETOOL} --remove-configure-file --package ${PACKAGE}.sc >> /dev/null
fi
exit 0
}
postuninst ()
{
# Remove link
rm -f ${INSTALL_DIR}
exit 0
}
preupgrade ()
{
# Stop the package
${SSS} stop > /dev/null
# Save some stuff
rm -fr ${TMP_DIR}/${PACKAGE}
mkdir -p ${TMP_DIR}/${PACKAGE}
mv ${CONFIG_DIR}/* ${TMP_DIR}/${PACKAGE}/
exit 0
}
postupgrade ()
{
# Restore some stuff
mv ${TMP_DIR}/${PACKAGE}/* ${CONFIG_DIR}/
rm -fr ${TMP_DIR}/${PACKAGE}
exit 0
}