Skip to content

Add basic support for Synology DSM #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion explorer/disks
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ in
then
# shellcheck disable=SC2012
ls -1 /sys/block/ \
| awk -v ign_majors="$(echo "${ign_majors}" | tr ' ' '|')" '
| awk -v ign_majors="${ign_majors}" '
BEGIN {
gsub(/ /, "|", ign_majors)
}
{
devfile = "/sys/block/" $0 "/dev"
getline devno < devfile
Expand Down
29 changes: 24 additions & 5 deletions explorer/init
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
# systemd, upstart, sysvinit, openrc, ???
# Devuan:
# sysvinit, sysvinit+openrc
# DSM:
# busybox-init+syno, upstart-syno, systemd
# Gentoo:
# sysvinit+openrc, openrc-init, systemd
# Haiku:
Expand Down Expand Up @@ -155,11 +157,15 @@ check_busybox_init() (
test -x "${busybox_path}" || return 1
grep -q 'BusyBox v[0-9]' "${busybox_path}" || return 1

# It is quite common to use Busybox init to stack other init systemd
# It is quite common to use BusyBox’s init to stack other service managers
# (like OpenRC) on top of it. So we check for that, too.
if stacked=$(check_openrc)
then
echo "busybox-init+${stacked}"
elif stacked=$(check_synoinit)
then
# Synology DSM < 5.0 uses BusyBox + synoservice(8)
echo "busybox-init+${stacked}"
else
echo busybox-init
fi
Expand Down Expand Up @@ -229,6 +235,13 @@ check_smf() {
echo smf
}

check_synoinit() {
# synoservice(8)
test -x /usr/syno/sbin/synoservice || return 1

echo syno
}

check_systemd() {
# NOTE: sd_booted(3)
test -d /run/systemd/system/ || return 1
Expand Down Expand Up @@ -263,7 +276,12 @@ check_upstart() {
case $(initctl version)
in
(*'(upstart '*')')
if test -d /etc/init
if test -x /usr/syno/sbin/synoservice \
&& test -x /usr/syno/sbin/synoservicectl
then
# upstart-based Synology init system
echo upstart-syno
elif test -d /etc/init
then
# modern (DBus-based?) upstart >= 0.5
echo upstart
Expand Down Expand Up @@ -300,11 +318,11 @@ find_init_procfs() (
# /sbin/init (deleted)
# [root@fedora-12 ~]# ls -l /proc/1/exe
# lrwxrwxrwx. 1 root root 0 2020-01-30 23:00 /proc/1/exe -> /sbin/init (deleted)

init_exe=${init_exe% (deleted)}
test -x "${init_exe}" || return 1
fi

test -x "${init_exe}" || return 1

echo "${init_exe}"
)

Expand Down Expand Up @@ -400,10 +418,11 @@ check_list() (
)


# BusyBox's versions of ps and pgrep do not support some options
# BusyBoxs versions of ps and pgrep do not support some options
# depending on which compile-time options have been used.

find_init_pgrep() {
command -v pgrep >/dev/null 2>&1 || return 1
pgrep -P0 -fl 2>/dev/null | awk -F '[[:blank:]]' '$1 == 1 { print $2 }'
}

Expand Down
8 changes: 8 additions & 0 deletions explorer/os
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ then
exit 0
fi

if test -f /etc/synoinfo.conf && test -f /etc/VERSION
then
# Synology DiskStation Manager
echo dsm
exit 0
fi


# Appliances

if grep -q '^Check Point Gaia' /etc/cp-release 2>/dev/null
Expand Down
19 changes: 19 additions & 0 deletions explorer/os_version
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ in

echo "${devuan_version}"
;;
(dsm)
# e.g. 4.1-2668, 6.2.3-25426 Update 3

# shellcheck source=/dev/null
. /etc/VERSION || exit 0

# productversion is available on DSM 5.2+ only.
# For older versions fall back to concatenation of majorversion and minorversion.
: "${productversion:=${majorversion:-0}${minorversion:+.${minorversion}}}"

# some versions define smallfixnumber=0, which would produce
# "Update 0" and makes no sense.
test $((smallfixnumber)) -gt 0 || smallfixnumber=

printf '%s%s%s\n' \
"${productversion}" \
"${buildnumber:+-${buildnumber}}" \
"${smallfixnumber:+ Update ${smallfixnumber}}"
;;
(fedora)
sed -e 's/^Fedora\( Core\)* release \(.*\) (.*)$/\2/' /etc/fedora-release
;;
Expand Down
7 changes: 6 additions & 1 deletion type/__cron/explorer/cron-allowed
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh -e
#
# 2022 Dennis Camera (dennis.camera at riiengineering.ch)
# 2022,2025 Dennis Camera (dennis.camera at riiengineering.ch)
#
# This file is part of skonfig-base.
#
Expand All @@ -25,6 +25,11 @@ cron_fail() { printf '%s\n' "$1" >&2; exit "$2"; }

user=$(cat "${__object:?}/parameter/user")

command -v crontab >/dev/null 2>&1 || {
echo 'Cannot find crontab(1). This type does not work without it.' >&2
exit 1
}

case $(uname -s)
in
(SunOS)
Expand Down
14 changes: 11 additions & 3 deletions type/__cron/explorer/entry
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh -e
#
# 2022 Dennis Camera (dennis.camera at riiengineering.ch)
# 2022,2025 Dennis Camera (dennis.camera at riiengineering.ch)
#
# This file is part of skonfig-base.
#
Expand Down Expand Up @@ -34,7 +34,15 @@ crontab_list() {
}

grep_suffix() {
awk -v suffix="$1" 'substr($0, length($0) - length(suffix) + 1) == suffix'
awk -v suffix="$1" '
# skip comment lines
/^[[:blank:]]*#/ { next }

{
if (substr($0, length($0) - length(suffix) + 1) == suffix) {
print
}
}'
}

crontab_list | grep -v '^[[:blank:]]*#' | grep_suffix " # ${name}"
crontab_list | grep_suffix " # ${name}"
2 changes: 1 addition & 1 deletion type/__hostname/gencode-remote
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ in
"&& hostnamectl set-hostname '${name_should}'" \
"|| hostname '${name_should}'"
;;
(centos|fedora|redhat|scientific|oraclelinux|crux|freebsd|netbsd|openbsd|gentoo|void)
(centos|fedora|redhat|scientific|oraclelinux|crux|freebsd|netbsd|openbsd|gentoo|void|dsm)
echo "hostname '${name_should}'"
;;
(openwrt)
Expand Down
24 changes: 24 additions & 0 deletions type/__hostname/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ in
--key 'HOSTNAME' \
--value "${name_should}"
;;
(dsm)
read -r os_version <"${__global:?}/explorer/os_version"
case ${os_version%%-*}
in
([123]|[123].*|4.[12]|4.[12].*)
# before DSM 4.3
__file /etc/sysconfig/network \
--state exists \
--owner 0 --group 0 --mode 0644
require=__file/etc/sysconfig/network \
__key_value /etc/sysconfig/network:HOSTNAME \
--file /etc/sysconfig/network \
--delimiter '=' --exact_delimiter \
--key 'HOSTNAME' \
--value "${name_should}"
;;
(*)
# DSM 4.3 and later
printf '%s\n' "${name_should}" | __file /etc/hostname \
--owner 0 --group 0 --mode 0644 \
--source -
;;
esac
;;
(gentoo)
# Only write to /etc/conf.d/hostname on OpenRC-based installations.
# On systemd use hostnamectl(1) in gencode-remote.
Expand Down
13 changes: 9 additions & 4 deletions type/__locale_system/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ in
locale_conf='/etc/sysconfig/i18n'
fi
;;
(dsm)
locale_conf='/etc/profile'
quote_value=false
key_prefix='export '
;;
(fedora)
read -r os_version <"${__global:?}/explorer/os_version"
if version_ge "${os_version}" 18
Expand Down Expand Up @@ -168,7 +173,7 @@ in
# NOTE: lang.csh (csh config) is ignored here.
locale_conf='/etc/profile.d/lang.sh'
locale_conf_mode=0755
key="export ${__object_id:?}"
key_prefix='export '
;;
(suse)
read -r os_version <"${__global:?}/explorer/os_version"
Expand Down Expand Up @@ -207,10 +212,10 @@ __file "${locale_conf}" \
--mode "${locale_conf_mode:-0644}"

require="__file${locale_conf}" \
__key_value "${locale_conf}:${key#export }" \
__key_value "${locale_conf}:${key}" \
--state "${state_should}" \
--file "${locale_conf}" \
--key "${key}" \
--key "${key_prefix-}${key}" \
--delimiter '=' --exact_delimiter \
--state "${state_should}" \
--value "${value:-$(catval "${__object:?}/parameter/value")}" \
--onchange "${onchange_cmd-}"
8 changes: 6 additions & 2 deletions type/__sysctl/manifest
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/sh -e
#
# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
# 2017 Ľubomír Kučera (lubomir.kucera.jr at gmail.com)
# 2018 Kamila Součková (kamila at ksp.sk)
# 2018 Darko Poljak (darko.poljak at gmail.com)
# 2018 Takashi Yoshi (takashi at yoshi.email)
# 2019 Nico Schottelius (nico-cdist at schottelius.org)
# 2016,2017,2019 Nico Schottelius (nico-cdist at schottelius.org)
# 2023,2025 Dennis Camera (dennis.camera at riiengineering.ch)
#
# This file is part of skonfig-base.
#
Expand All @@ -26,7 +30,7 @@ os=$(cat "${__global:?}/explorer/os")
case ${os}
in
# Linux
(alpine|redhat|centos|almalinux|eurolinux|rocky|oraclelinux|ubuntu|debian|devuan|archlinux|coreos)
(alpine|redhat|centos|almalinux|eurolinux|rocky|oraclelinux|ubuntu|debian|devuan|archlinux|coreos|dsm)
:
;;
# BSD
Expand Down