forked from SynoCommunity/spksrc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspksrc.service.installer.functions
More file actions
119 lines (95 loc) · 3.09 KB
/
spksrc.service.installer.functions
File metadata and controls
119 lines (95 loc) · 3.09 KB
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
### common installer functions and variables for synocommunity generic service installer
#
# functions are common for all DSM versions
#
# 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"
RSYNC="/bin/rsync -avh"
TAR="/bin/tar"
INST_ETC="/var/packages/${SYNOPKG_PKGNAME}/etc"
INST_VARIABLES="${INST_ETC}/installer-variables"
if [ -z "${SYNOPKG_PKGVAR}" ]; then
# define SYNOPKG_PKGVAR for compatibility with DSM7 (replaces former INST_VAR)
SYNOPKG_PKGVAR="${SYNOPKG_PKGDEST}/var"
fi
### Functions library
log_step ()
{
install_log "===> Step $1. STATUS=${SYNOPKG_PKG_STATUS} USER=$USER GROUP=$GROUP SHARE_PATH=${SHARE_PATH}"
}
initialize_variables ()
{
# 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
if [ -n "${wizard_volume}" ]; then
SHARE_PATH="${wizard_volume}/${SHARE_PATH}"
fi
SHARE_VOLUME=$(echo "${SHARE_PATH}" | awk -F/ '{print "/"$2}')
SHARE_NAME=$(echo "${SHARE_PATH}" | awk -F/ '{print $3}')
fi
}
install_python_virtualenv ()
{
# Output Python version (confirming PATH)
python3 --version
# Create a Python virtualenv
python3 -m venv --system-site-packages ${SYNOPKG_PKGDEST}/env
# Update to latest pip package installer
python3 -m pip install --upgrade pip
}
install_python_wheels ()
{
# default PATH to wheelhouse
cachedir=${SYNOPKG_PKGVAR}/pip-cache
wheelhouse=${SYNOPKG_PKGDEST}/share/wheelhouse
requirements=${wheelhouse}/requirements.txt
# Install the wheels
echo "Install packages from wheels"
if [ -s ${requirements} ]; then
echo "Install packages from wheels [${requirements}]"
pip install $([ $# -gt 0 ] && echo $*) \
--force-reinstall \
--cache-dir ${cachedir} \
--find-links ${wheelhouse} \
--requirement ${requirements}
fi
echo "Installed modules:"
pip freeze
}
reload_inst_variables ()
{
# Reload wizard variables stored by postinst
if [ -r "${INST_VARIABLES}" ]; then
# we cannot source the file to reload the variables, when values have special characters like <, >, ...
for _line in $(cat "${INST_VARIABLES}"); do
_key="$(echo ${_line} | awk -F'=' '{print $1}')"
_value="$(echo ${_line} | awk -F'=' '{print $2}')"
declare "${_key}=${_value}"
done
fi
}
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
}