rustdesk-server/spk/scripts/installer

163 lines
6.8 KiB
Plaintext
Raw Normal View History

2021-04-03 23:52:29 +08:00
#!/bin/sh
PACKAGE_NAME="$SYNOPKG_PKGNAME"
PACKAGE_BASE="/var/packages/${PACKAGE_NAME}/target"
PACKAGE_SSS="/var/packages/${PACKAGE_NAME}/scripts/start-stop-status"
SERVICETOOL="/usr/syno/bin/servicetool"
GETKEYVALUE="/usr/syno/bin/synogetkeyvalue"
SETKEYVALUE="/usr/syno/bin/synosetkeyvalue"
FWFILENAME="RustDesk_Server.sc"
[ "${hbbr_port}" == "" ] && hbbr_port="21117"
[ "${hbbs_port}" == "" ] && hbbs_port="21116"
2021-04-04 01:44:14 +08:00
[ "${key}" == "" ] && key=""
2021-04-03 23:52:29 +08:00
nat_port=`expr ${hbbs_port} - 1`
preinst() {
exit 0
}
postinst() {
if [ "${SYNOPKG_PKG_STATUS}" == "INSTALL" ]; then
# 导入另一个RustDesk服务器数据
import_db="false"
import_all="false"
if [ "${rds_old_import_all}" == "true" ]; then
rds_old_import_db="true"
import_all="true"
elif [ "${rds_import_all}" == "true" ]; then
rds_import_db="true"
import_all="true"
fi
if [ "${rds_old_import_db}" == "true" ]; then
import_db="true"
PACKAGE_IMPORT_DIR="/var/packages/RustDesk_Server"
elif [ "${rds_import_db}" == "true" ]; then
import_db="true"
PACKAGE_IMPORT_DIR="/var/packages/RustDesk Server"
fi
if [ "${import_db}" == "true" ]; then
[ -x "${PACKAGE_IMPORT_DIR}/scripts/start-stop-status" ] \
&& SYNOPKG_PKGNAME="RustDesk Server" "${PACKAGE_IMPORT_DIR}/scripts/start-stop-status" stop 2>&1
[ -f "${PACKAGE_IMPORT_DIR}/enabled" ] && rm -f "${PACKAGE_IMPORT_DIR}/enabled"
[ -d "${PACKAGE_IMPORT_DIR}/target/hbbs.db" ] && cp -prf "${PACKAGE_IMPORT_DIR}/target/hbbs.db" "${PACKAGE_BASE}"
fi
if [ "${import_all}" == "true" ]; then
[ -d "${PACKAGE_IMPORT_DIR}/target/logs" ] && cp -prf "${PACKAGE_IMPORT_DIR}/target/logs" "${PACKAGE_BASE}"
fi
# 添加应用配置
2021-04-04 01:44:14 +08:00
sed -i "s/relay port: 21117/relay port: ${hbbr_port}/" "/var/packages/${PACKAGE_NAME}/INFO"
sed -i "s/ID\/rendezvous port: 21116/ID\/rendezvous port: ${hbbs_port}/" "/var/packages/${PACKAGE_NAME}/INFO"
sed -i "s/NAT test port: 21115/NAT test port: ${nat_port}/" "/var/packages/${PACKAGE_NAME}/INFO"
sed -i "s/Key: ()/Key: (${key})/" "/var/packages/${PACKAGE_NAME}/INFO"
2021-04-03 23:52:29 +08:00
sed -i "s/21117/${hbbr_port}/" "/var/packages/${PACKAGE_NAME}/scripts/${FWFILENAME}"
sed -i "s/21116/${hbbs_port}/" "/var/packages/${PACKAGE_NAME}/scripts/${FWFILENAME}"
sed -i "s/21115/${nat_port}/" "/var/packages/${PACKAGE_NAME}/scripts/${FWFILENAME}"
sed -i "s/port=[^ ]*/port=${hbbr_port}/g" "${PACKAGE_BASE}/config/hbbr.conf"
sed -i "s/port=[^ ]*/port=${hbbs_port}/g" "${PACKAGE_BASE}/config/hbbs.conf"
2021-04-04 01:44:14 +08:00
sed -i "s/key=[^ ]*/key=${key}/g" "${PACKAGE_BASE}/config/hbbs.conf"
2021-04-03 23:52:29 +08:00
# 添加防火墙配置
cat "/var/packages/${PACKAGE_NAME}/scripts/${FWFILENAME}" >"/tmp/${FWFILENAME}"
${SERVICETOOL} --install-configure-file --package "/tmp/${FWFILENAME}" >/dev/null
rm -f "/tmp/${FWFILENAME}"
# 设置文件权限
chmod -R 755 "${PACKAGE_BASE}"/*
chmod -R 755 "/var/packages/${PACKAGE_NAME}/scripts"/*
chmod -R 755 "/var/packages/${PACKAGE_NAME}/WIZARD_UIFILES"/*
chmod 644 "/var/packages/${PACKAGE_NAME}/INFO"
fi
exit 0
}
preuninst() {
# 停用套件
"${PACKAGE_SSS}" stop
# 删除防火墙配置
if [ "${SYNOPKG_PKG_STATUS}" == "UNINSTALL" ]; then
${SERVICETOOL} --remove-configure-file --package "${FWFILENAME}" >/dev/null
fi
exit 0
}
postuninst() {
# 删除不必要的目录...
if [ -d "/usr/syno/etc/packages/${PACKAGE_NAME}" ]; then
rm -rf "/usr/syno/etc/packages/${PACKAGE_NAME}"
fi
exit 0
}
preupgrade() {
# 停用套件
"${PACKAGE_SSS}" stop
# Not working yet...
# # 检索旧设置...
# hbbr_port=`${GETKEYVALUE} "${PACKAGE_BASE}/config/hbbr.conf" port`
# hbbs_port=`${GETKEYVALUE} "${PACKAGE_BASE}/config/hbbs.conf" port`
# sed -i "s/21117/${hbbr_port}/" "/var/packages/${PACKAGE_NAME}/WIZARD_UIFILES/upgrade_uifile"
# sed -i "s/21116/${hbbs_port}/" "/var/packages/${PACKAGE_NAME}/WIZARD_UIFILES/upgrade_uifile"
## Not working yet...
# 备份数据文件...
if [ -d "${SYNOPKG_PKGDEST}" ]; then
DIRS4BACKUP="data logs hbbs.db config"
for DIR in $DIRS4BACKUP; do
if [ -d "${SYNOPKG_PKGDEST}/${DIR}" ]; then
mkdir -p "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade/${DIR}"
mv "${SYNOPKG_PKGDEST}/${DIR}"/* "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade/${DIR}"
rmdir "${SYNOPKG_PKGDEST}/${DIR}"
elif [ -f "${SYNOPKG_PKGDEST}/${DIR}" ]; then
mv "${SYNOPKG_PKGDEST}/${DIR}" "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade"
fi
done
fi
exit 0
}
postupgrade() {
# 恢复数据文件...
if [ -d "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade" ]; then
for DIR in `ls "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade"`
do
if [ -d "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade/${DIR}" ]; then
[ ! -d "${SYNOPKG_PKGDEST}/${DIR}" ] && mkdir "${SYNOPKG_PKGDEST}/${DIR}"
mv "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade/${DIR}"/* "${SYNOPKG_PKGDEST}/${DIR}"
rmdir "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade/${DIR}"
elif [ -f "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade/${DIR}" ]; then
mv "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade/${DIR}" "${SYNOPKG_PKGDEST}"
fi
done
rmdir "${SYNOPKG_PKGDEST}/../${PACKAGE_NAME}_upgrade"
fi
# 恢复设置...
hbbr_port=`${GETKEYVALUE} "${PACKAGE_BASE}/config/hbbr.conf" port` >>/tmp/wakko.txt
hbbs_port=`${GETKEYVALUE} "${PACKAGE_BASE}/config/hbbs.conf" port` >>/tmp/wakko.txt
nat_port=`expr ${hbbs_port} - 1`
2021-04-04 01:44:14 +08:00
key=`${GETKEYVALUE} "${PACKAGE_BASE}/config/hbbs.conf" key` >>/tmp/wakko.txt
sed -i "s/relay port: 21117/relay port: ${hbbr_port}/" "/var/packages/${PACKAGE_NAME}/INFO" >>/tmp/wakko.txt
sed -i "s/ID\/rendezvous port: 21116/ID\/rendezvous port: ${hbbs_port}/" "/var/packages/${PACKAGE_NAME}/INFO" >>/tmp/wakko.txt
sed -i "s/NAT test port: 21115/NAT test port: ${nat_port}/" "/var/packages/${PACKAGE_NAME}/INFO" >>/tmp/wakko.txt
sed -i "s/Key: ()/Key: (${key})/" "/var/packages/${PACKAGE_NAME}/INFO"
2021-04-03 23:52:29 +08:00
sed -i "s/21117/${hbbr_port}/" "/var/packages/${PACKAGE_NAME}/scripts/${FWFILENAME}" >>/tmp/wakko.txt
sed -i "s/21116/${hbbs_port}/" "/var/packages/${PACKAGE_NAME}/scripts/${FWFILENAME}" >>/tmp/wakko.txt
sed -i "s/21115/${nat_port}/" "/var/packages/${PACKAGE_NAME}/scripts/${FWFILENAME}" >>/tmp/wakko.txt
# 设置文件权限
chmod -R 755 "/var/packages/${PACKAGE_NAME}/scripts"/*
chmod -R 755 "/var/packages/${PACKAGE_NAME}/WIZARD_UIFILES"/*
chmod 644 "/var/packages/${PACKAGE_NAME}/INFO"
exit 0
}