Improve support for DSM 7.0

This commit is contained in:
Matige 2021-02-06 19:51:59 +01:00
parent 0f29464e44
commit 7999e50941
10 changed files with 39 additions and 42 deletions

View File

@ -76,7 +76,7 @@ install: all
install $(WG_TARGET) $(DESTDIR)/wireguard/ install $(WG_TARGET) $(DESTDIR)/wireguard/
install $(WG_QUICK_TARGET) $(DESTDIR)/wireguard/ install $(WG_QUICK_TARGET) $(DESTDIR)/wireguard/
install $(WG_MODULE_TARGET) $(DESTDIR)/wireguard/ install $(WG_MODULE_TARGET) $(DESTDIR)/wireguard/
install $(ROOT_DIR)/wireguard/wg-init $(DESTDIR)/wireguard/ install $(ROOT_DIR)/wireguard/wg-autostart $(DESTDIR)/wireguard/
clean: clean:
rm -rf $(LIBMNL_TAR) $(LIBMNL_DIR) $(WIREGUARD_TAR) $(WIREGUARD_DIR) $(WIREGUARD_TOOLS_TAR) $(WIREGUARD_TOOLS_DIR) rm -rf $(LIBMNL_TAR) $(LIBMNL_DIR) $(WIREGUARD_TAR) $(WIREGUARD_DIR) $(WIREGUARD_TOOLS_TAR) $(WIREGUARD_TOOLS_DIR)

View File

@ -150,22 +150,22 @@ SSH session.
Adding WireGuard to autostart Adding WireGuard to autostart
----------------------------- -----------------------------
DSM since version 7.0 comes with `systemd unit <https://www.freedesktop.org/software/systemd/man/systemd.unit.html>`_ support, while for previous versions you can use the built-in `upstart <http://upstart.ubuntu.com/>`_. DSM since version 7.0 comes with `systemd unit <https://www.freedesktop.org/software/systemd/man/systemd.unit.html>`_ support, while for previous versions you can use the built-in `upstart <http://upstart.ubuntu.com/>`_.
To standardize the process of adding the WireGuard interface to the autostart, a simple ``wg-init`` script has been developed. To standardize the process of adding the WireGuard interface to the autostart, a simple ``wg-autostart`` script has been developed.
**Important note:** before adding the interface to the autostart, start it manually by ``sudo wg-quick up wg0`` ensure that it does not cause the system to to crash and that you can still access your NAS properly. Otherwise, you may not be able to start the NAS or you may not be able to access the device after a reboot.
To add the ``wg0`` interface to the autostart, run the command: To add the ``wg0`` interface to the autostart, run the command:
.. code-block:: .. code-block::
sudo wg-init enable wg0 sudo wg-autostart enable wg0
To remove the ``wg0`` interface from the autostart, run the command: To remove the ``wg0`` interface from the autostart, run the command:
.. code-block:: .. code-block::
sudo wg-init disable wg0 sudo wg-autostart disable wg0
**Important note:** before adding the interface to the autostart, start it manually by ``sudo wg-quick up wg0`` ensure that it does not cause the system to crash. Otherwise, it may not be possible to start the NAS.
Compiling Compiling

View File

@ -56,7 +56,7 @@ if [[ "$DSM_VER" =~ ^7\.[0-9]+$ ]]; then
# not signed by Synology from running with root privileges. # not signed by Synology from running with root privileges.
# Change the permission to run the package to lower in order # Change the permission to run the package to lower in order
# to successfully install the package. # to successfully install the package.
sed -i "s/root/package/" /source/WireGuard/conf/privilege run_as="package"
# For Virtual DSM 7.0 (vkmx64) the wireguard kernel module # For Virtual DSM 7.0 (vkmx64) the wireguard kernel module
# requires a spinlock implementation patch # requires a spinlock implementation patch
@ -65,6 +65,7 @@ if [[ "$DSM_VER" =~ ^7\.[0-9]+$ ]]; then
fi fi
else else
os_min_ver="6.0-5941" os_min_ver="6.0-5941"
run_as="root"
pkgscripts_args="-S" pkgscripts_args="-S"
# Temporary workaround for some architectures that are not part properly set as # Temporary workaround for some architectures that are not part properly set as
@ -76,8 +77,10 @@ else
fi fi
fi fi
sed -i "s/DSM_VER/$DSM_VER/" /source/WireGuard/SynoBuildConf/depends package_dir=`dirname $0`
sed -i "s/OS_MIN_VER/$os_min_ver/" /source/WireGuard/INFO.sh cp -p "$package_dir/template/INFO.sh" "$package_dir/INFO.sh" && sed -i "s/OS_MIN_VER/$os_min_ver/" "$package_dir/INFO.sh"
cp -p "$package_dir/template/conf/privilege" "$package_dir/conf/privilege" && sed -i "s/RUN_AS/$run_as/" "$package_dir/conf/privilege"
cp -p "$package_dir/template/SynoBuildConf/depends" "$package_dir/SynoBuildConf/depends" && sed -i "s/DSM_VER/$DSM_VER/" "$package_dir/SynoBuildConf/depends"
# Install the toolchain for the given package arch and DSM version # Install the toolchain for the given package arch and DSM version
build_env="/build_env/ds.$PACKAGE_ARCH-$DSM_VER" build_env="/build_env/ds.$PACKAGE_ARCH-$DSM_VER"
@ -133,6 +136,9 @@ pkgscripts-ng/PkgCreate.py \
# a non-zero exit code on errors. # a non-zero exit code on errors.
pkg_status=$? pkg_status=$?
# Clean up the build environment
rm "$package_dir/INFO.sh" "$package_dir/conf/privilege" "$package_dir/SynoBuildConf/depends"
echo "Build log" echo "Build log"
echo "=========" echo "========="
cat "$build_env/logs.build" cat "$build_env/logs.build"

View File

@ -1,5 +1,5 @@
{ {
"usr-local-linker": { "usr-local-linker": {
"bin": ["wireguard/wg", "wireguard/wg-quick", "wireguard/wg-init"] "bin": ["wireguard/wg", "wireguard/wg-quick", "wireguard/wg-autostart"]
} }
} }

View File

@ -2,12 +2,11 @@
Description=WireGuard via wg-quick(8) for %I Description=WireGuard via wg-quick(8) for %I
After=pkgctl-WireGuard.service After=pkgctl-WireGuard.service
Wants=pkgctl-WireGuard.service Wants=pkgctl-WireGuard.service
Documentation=man:wg-quick(8) Documentation=https://github.com/runfalk/synology-wireguard
Documentation=man:wg(8)
Documentation=https://www.wireguard.com/
Documentation=https://www.wireguard.com/quickstart/
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8 Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8 Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8
Documentation=https://www.wireguard.com/
Documentation=https://www.wireguard.com/quickstart/
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -1,7 +1,6 @@
#!/bin/sh #!/bin/sh
if [ "$EUID" -ne 0 ] if [ "$EUID" -ne 0 ]; then
then
echo "This script must be run as root" echo "This script must be run as root"
exit 1 exit 1
fi fi
@ -10,8 +9,7 @@ dir=`dirname $0`
sed -i 's/package/root/' "$dir/../conf/privilege" sed -i 's/package/root/' "$dir/../conf/privilege"
synopkg start WireGuard > /dev/null synopkg start WireGuard > /dev/null
if [ "$?" -eq 0 ] if [ "$?" -eq 0 ]; then
then
echo "WireGuard has been successfully started" echo "WireGuard has been successfully started"
exit 0 exit 0
else else

View File

@ -1,5 +1,5 @@
{ {
"defaults": { "defaults": {
"run-as": "root" "run-as": "RUN_AS"
} }
} }

View File

@ -1,5 +1,8 @@
#!/bin/sh #!/bin/sh
# This script standardizes the process of adding the WireGuard interface to the autostart. Type wg-autostart for usage instruction.
# For DSM 7, systemd is used. Upstart script (init_script) method is used for DSM without systemd support (DSM 6).
read -r -d '' init_script <<EOF read -r -d '' init_script <<EOF
start on syno.pkgctl.started WireGuard start on syno.pkgctl.started WireGuard
@ -10,19 +13,16 @@ end script
EOF EOF
enable() { enable() {
if command -v systemctl &> /dev/null if command -v systemctl &> /dev/null; then
then
systemctl is-enabled --quiet "pkg-wg-quick@${1}" &> /dev/null systemctl is-enabled --quiet "pkg-wg-quick@${1}" &> /dev/null
if [ "$?" -ne 0 ] if [ "$?" -ne 0 ]; then
then
systemctl enable "pkg-wg-quick@${1}" &> /dev/null systemctl enable "pkg-wg-quick@${1}" &> /dev/null
return 0 return 0
else else
return 1 return 1
fi fi
else else
if [ ! -f "/etc/init/wireguard-${1}.conf" ] if [ ! -f "/etc/init/wireguard-${1}.conf" ]; then
then
echo -e "$init_script" > "/etc/init/wireguard-${1}.conf" echo -e "$init_script" > "/etc/init/wireguard-${1}.conf"
sed -i "s/%i/${1}/g" "/etc/init/wireguard-${1}.conf" sed -i "s/%i/${1}/g" "/etc/init/wireguard-${1}.conf"
return 0 return 0
@ -33,19 +33,16 @@ enable() {
} }
disable() { disable() {
if command -v systemctl &> /dev/null if command -v systemctl &> /dev/null; then
then
systemctl is-enabled --quiet "pkg-wg-quick@${1}" &> /dev/null systemctl is-enabled --quiet "pkg-wg-quick@${1}" &> /dev/null
if [ "$?" -eq 0 ] if [ "$?" -eq 0 ]; then
then
systemctl disable "pkg-wg-quick@${1}" &> /dev/null systemctl disable "pkg-wg-quick@${1}" &> /dev/null
return 0 return 0
else else
return 1 return 1
fi fi
else else
if [ -f "/etc/init/wireguard-${1}.conf" ] if [ -f "/etc/init/wireguard-${1}.conf" ]; then
then
rm -rf "/etc/init/wireguard-${1}.conf" rm -rf "/etc/init/wireguard-${1}.conf"
return 0 return 0
else else
@ -54,8 +51,7 @@ disable() {
fi fi
} }
if [ "$EUID" -ne 0 ] if [ "$EUID" -ne 0 ]; then
then
echo "This script must be run as root" echo "This script must be run as root"
exit 1 exit 1
fi fi
@ -63,23 +59,21 @@ fi
case "$1" in case "$1" in
enable) enable)
enable "$2" enable "$2"
if [ "$?" -eq 0 ] if [ "$?" -eq 0 ]; then
then echo "wg-autostart $2 has been enabled successfully"
echo "wg-init $2 has been enabled successfully"
exit 0 exit 0
else else
echo "wg-init $2 is already enabled" 1>&2 echo "wg-autostart $2 is already enabled" 1>&2
exit 1 exit 1
fi fi
;; ;;
disable) disable)
disable "$2" disable "$2"
if [ "$?" -eq 0 ] if [ "$?" -eq 0 ]; then
then echo "wg-autostart $2 has been disabled successfully"
echo "wg-init $2 has been disabled successfully"
exit 0 exit 0
else else
echo "wg-init $2 is already disabled" 1>&2 echo "wg-autostart $2 is already disabled" 1>&2
exit 1 exit 1
fi fi
;; ;;