Skip to content

Commit f4fa309

Browse files
authored
Merge pull request #136 from riiengineering/feature/dsm-support
Add basic support for Synology DSM
2 parents 10baea4 + 1dd009c commit f4fa309

10 files changed

Lines changed: 112 additions & 17 deletions

File tree

explorer/disks

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ in
6767
then
6868
# shellcheck disable=SC2012
6969
ls -1 /sys/block/ \
70-
| awk -v ign_majors="$(echo "${ign_majors}" | tr ' ' '|')" '
70+
| awk -v ign_majors="${ign_majors}" '
71+
BEGIN {
72+
gsub(/ /, "|", ign_majors)
73+
}
7174
{
7275
devfile = "/sys/block/" $0 "/dev"
7376
getline devno < devfile

explorer/init

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
# systemd, upstart, sysvinit, openrc, ???
4040
# Devuan:
4141
# sysvinit, sysvinit+openrc
42+
# DSM:
43+
# busybox-init+syno, upstart-syno, systemd
4244
# Gentoo:
4345
# sysvinit+openrc, openrc-init, systemd
4446
# Haiku:
@@ -155,11 +157,15 @@ check_busybox_init() (
155157
test -x "${busybox_path}" || return 1
156158
grep -q 'BusyBox v[0-9]' "${busybox_path}" || return 1
157159

158-
# It is quite common to use Busybox init to stack other init systemd
160+
# It is quite common to use BusyBox’s init to stack other service managers
159161
# (like OpenRC) on top of it. So we check for that, too.
160162
if stacked=$(check_openrc)
161163
then
162164
echo "busybox-init+${stacked}"
165+
elif stacked=$(check_synoinit)
166+
then
167+
# Synology DSM < 5.0 uses BusyBox + synoservice(8)
168+
echo "busybox-init+${stacked}"
163169
else
164170
echo busybox-init
165171
fi
@@ -229,6 +235,13 @@ check_smf() {
229235
echo smf
230236
}
231237

238+
check_synoinit() {
239+
# synoservice(8)
240+
test -x /usr/syno/sbin/synoservice || return 1
241+
242+
echo syno
243+
}
244+
232245
check_systemd() {
233246
# NOTE: sd_booted(3)
234247
test -d /run/systemd/system/ || return 1
@@ -263,7 +276,12 @@ check_upstart() {
263276
case $(initctl version)
264277
in
265278
(*'(upstart '*')')
266-
if test -d /etc/init
279+
if test -x /usr/syno/sbin/synoservice \
280+
&& test -x /usr/syno/sbin/synoservicectl
281+
then
282+
# upstart-based Synology init system
283+
echo upstart-syno
284+
elif test -d /etc/init
267285
then
268286
# modern (DBus-based?) upstart >= 0.5
269287
echo upstart
@@ -300,11 +318,11 @@ find_init_procfs() (
300318
# /sbin/init (deleted)
301319
# [root@fedora-12 ~]# ls -l /proc/1/exe
302320
# lrwxrwxrwx. 1 root root 0 2020-01-30 23:00 /proc/1/exe -> /sbin/init (deleted)
303-
304321
init_exe=${init_exe% (deleted)}
305-
test -x "${init_exe}" || return 1
306322
fi
307323

324+
test -x "${init_exe}" || return 1
325+
308326
echo "${init_exe}"
309327
)
310328

@@ -400,10 +418,11 @@ check_list() (
400418
)
401419

402420

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

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

explorer/os

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ then
213213
exit 0
214214
fi
215215

216+
if test -f /etc/synoinfo.conf && test -f /etc/VERSION
217+
then
218+
# Synology DiskStation Manager
219+
echo dsm
220+
exit 0
221+
fi
222+
223+
216224
# Appliances
217225

218226
if grep -q '^Check Point Gaia' /etc/cp-release 2>/dev/null

explorer/os_version

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@ in
139139

140140
echo "${devuan_version}"
141141
;;
142+
(dsm)
143+
# e.g. 4.1-2668, 6.2.3-25426 Update 3
144+
145+
# shellcheck source=/dev/null
146+
. /etc/VERSION || exit 0
147+
148+
# productversion is available on DSM 5.2+ only.
149+
# For older versions fall back to concatenation of majorversion and minorversion.
150+
: "${productversion:=${majorversion:-0}${minorversion:+.${minorversion}}}"
151+
152+
# some versions define smallfixnumber=0, which would produce
153+
# "Update 0" and makes no sense.
154+
test $((smallfixnumber)) -gt 0 || smallfixnumber=
155+
156+
printf '%s%s%s\n' \
157+
"${productversion}" \
158+
"${buildnumber:+-${buildnumber}}" \
159+
"${smallfixnumber:+ Update ${smallfixnumber}}"
160+
;;
142161
(fedora)
143162
sed -e 's/^Fedora\( Core\)* release \(.*\) (.*)$/\2/' /etc/fedora-release
144163
;;

type/__cron/explorer/cron-allowed

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh -e
22
#
3-
# 2022 Dennis Camera (dennis.camera at riiengineering.ch)
3+
# 2022,2025 Dennis Camera (dennis.camera at riiengineering.ch)
44
#
55
# This file is part of skonfig-base.
66
#
@@ -25,6 +25,11 @@ cron_fail() { printf '%s\n' "$1" >&2; exit "$2"; }
2525

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

28+
command -v crontab >/dev/null 2>&1 || {
29+
echo 'Cannot find crontab(1). This type does not work without it.' >&2
30+
exit 1
31+
}
32+
2833
case $(uname -s)
2934
in
3035
(SunOS)

type/__cron/explorer/entry

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh -e
22
#
3-
# 2022 Dennis Camera (dennis.camera at riiengineering.ch)
3+
# 2022,2025 Dennis Camera (dennis.camera at riiengineering.ch)
44
#
55
# This file is part of skonfig-base.
66
#
@@ -34,7 +34,15 @@ crontab_list() {
3434
}
3535

3636
grep_suffix() {
37-
awk -v suffix="$1" 'substr($0, length($0) - length(suffix) + 1) == suffix'
37+
awk -v suffix="$1" '
38+
# skip comment lines
39+
/^[[:blank:]]*#/ { next }
40+
41+
{
42+
if (substr($0, length($0) - length(suffix) + 1) == suffix) {
43+
print
44+
}
45+
}'
3846
}
3947

40-
crontab_list | grep -v '^[[:blank:]]*#' | grep_suffix " # ${name}"
48+
crontab_list | grep_suffix " # ${name}"

type/__hostname/gencode-remote

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ in
6767
"&& hostnamectl set-hostname '${name_should}'" \
6868
"|| hostname '${name_should}'"
6969
;;
70-
(centos|fedora|redhat|scientific|oraclelinux|crux|freebsd|netbsd|openbsd|gentoo|void)
70+
(centos|fedora|redhat|scientific|oraclelinux|crux|freebsd|netbsd|openbsd|gentoo|void|dsm)
7171
echo "hostname '${name_should}'"
7272
;;
7373
(openwrt)

type/__hostname/manifest

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,30 @@ in
104104
--key 'HOSTNAME' \
105105
--value "${name_should}"
106106
;;
107+
(dsm)
108+
read -r os_version <"${__global:?}/explorer/os_version"
109+
case ${os_version%%-*}
110+
in
111+
([123]|[123].*|4.[12]|4.[12].*)
112+
# before DSM 4.3
113+
__file /etc/sysconfig/network \
114+
--state exists \
115+
--owner 0 --group 0 --mode 0644
116+
require=__file/etc/sysconfig/network \
117+
__key_value /etc/sysconfig/network:HOSTNAME \
118+
--file /etc/sysconfig/network \
119+
--delimiter '=' --exact_delimiter \
120+
--key 'HOSTNAME' \
121+
--value "${name_should}"
122+
;;
123+
(*)
124+
# DSM 4.3 and later
125+
printf '%s\n' "${name_should}" | __file /etc/hostname \
126+
--owner 0 --group 0 --mode 0644 \
127+
--source -
128+
;;
129+
esac
130+
;;
107131
(gentoo)
108132
# Only write to /etc/conf.d/hostname on OpenRC-based installations.
109133
# On systemd use hostnamectl(1) in gencode-remote.

type/__locale_system/manifest

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ in
9696
locale_conf='/etc/sysconfig/i18n'
9797
fi
9898
;;
99+
(dsm)
100+
locale_conf='/etc/profile'
101+
quote_value=false
102+
key_prefix='export '
103+
;;
99104
(fedora)
100105
read -r os_version <"${__global:?}/explorer/os_version"
101106
if version_ge "${os_version}" 18
@@ -168,7 +173,7 @@ in
168173
# NOTE: lang.csh (csh config) is ignored here.
169174
locale_conf='/etc/profile.d/lang.sh'
170175
locale_conf_mode=0755
171-
key="export ${__object_id:?}"
176+
key_prefix='export '
172177
;;
173178
(suse)
174179
read -r os_version <"${__global:?}/explorer/os_version"
@@ -207,10 +212,10 @@ __file "${locale_conf}" \
207212
--mode "${locale_conf_mode:-0644}"
208213

209214
require="__file${locale_conf}" \
210-
__key_value "${locale_conf}:${key#export }" \
215+
__key_value "${locale_conf}:${key}" \
216+
--state "${state_should}" \
211217
--file "${locale_conf}" \
212-
--key "${key}" \
218+
--key "${key_prefix-}${key}" \
213219
--delimiter '=' --exact_delimiter \
214-
--state "${state_should}" \
215220
--value "${value:-$(catval "${__object:?}/parameter/value")}" \
216221
--onchange "${onchange_cmd-}"

type/__sysctl/manifest

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/bin/sh -e
22
#
33
# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
4+
# 2017 Ľubomír Kučera (lubomir.kucera.jr at gmail.com)
5+
# 2018 Kamila Součková (kamila at ksp.sk)
6+
# 2018 Darko Poljak (darko.poljak at gmail.com)
47
# 2018 Takashi Yoshi (takashi at yoshi.email)
5-
# 2019 Nico Schottelius (nico-cdist at schottelius.org)
8+
# 2016,2017,2019 Nico Schottelius (nico-cdist at schottelius.org)
9+
# 2023,2025 Dennis Camera (dennis.camera at riiengineering.ch)
610
#
711
# This file is part of skonfig-base.
812
#
@@ -26,7 +30,7 @@ os=$(cat "${__global:?}/explorer/os")
2630
case ${os}
2731
in
2832
# Linux
29-
(alpine|redhat|centos|almalinux|eurolinux|rocky|oraclelinux|ubuntu|debian|devuan|archlinux|coreos)
33+
(alpine|redhat|centos|almalinux|eurolinux|rocky|oraclelinux|ubuntu|debian|devuan|archlinux|coreos|dsm)
3034
:
3135
;;
3236
# BSD

0 commit comments

Comments
 (0)