Skip to content
Open
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
13 changes: 13 additions & 0 deletions explorer/disks
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ case $uname_s in
-e 's/^ *[0-9]\{1,\}\. //p' \
| cut -d ' ' -f 1
;;
Sortix)
if command -v disked >/dev/null 2>&1
then
printf '%s\n' devices exit \
| disked \
| awk '
/^#[ \t]/ { t = 1; for (i = 1; i <= NF; i++) cols[$i] = i }
t && $cols["#"] ~ /^[0-9]+$/ {
print $cols["DEVICE"]
}
'
fi
;;
*)
printf "Don't know how to list disks for %s operating system.\n" "${uname_s}" >&2
printf 'If you can please submit a patch\n' >&2
Expand Down
8 changes: 7 additions & 1 deletion explorer/init
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# 2016 Daniel Heule (hda at sfs.biz)
# Copyright 2017, Philippe Gregoire <pg@pgregoire.xyz>
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
# 2020,2022 Dennis Camera (skonfig at dtnr.ch)
#
# This file is part of cdist.
#
Expand Down Expand Up @@ -66,6 +66,9 @@
#
# Solaris/Illumos:
# smf, init???
#
# Sortix:
# init

# NOTE: init systems can be stacked. This is popular to run OpenRC on top of
# sysvinit (Gentoo) or busybox-init (Alpine), but can also be used to run runit
Expand Down Expand Up @@ -412,6 +415,9 @@ find_init() {
Darwin|SunOS)
find_init_ps
;;
Sortix)
echo 'init'
;;
*)
echo "Don't know how to determine init." >&2
echo 'Please send a patch.' >&2
Expand Down
15 changes: 13 additions & 2 deletions explorer/interfaces
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh -e
#
# 2012 Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
# 2019 Ander Punnar (ander-at-kvlt-dot-ee)
# 2022 Dennis Camera (skonfig at dtnr.ch)
#
# This file is part of cdist.
#
Expand All @@ -23,6 +25,15 @@ then
ip -o link show | sed -n 's/^[0-9]\+: \(.\+\): <.*/\1/p'
elif command -v ifconfig >/dev/null
then
ifconfig -a | sed -n -E 's/^(.*)(:[[:space:]]*flags=|Link encap).*/\1/p'
case $(uname -s)
in
(Sortix)
ifconfig | sed -n -e 's/^\([^[:space:]]*\):$/\1/p'
;;
(*)
ifconfig -a \
| sed -n -E 's/^(.*)(:[[:space:]]*flags=|Link encap).*/\1/p'
;;
esac
fi \
| sort -u
| sort -u
41 changes: 38 additions & 3 deletions explorer/memory
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 2014 Daniel Heule (hda at sfs.biz)
# 2014 Thomas Oettli (otho at sfs.biz)
# Copyright 2017, Philippe Gregoire <pg@pgregoire.xyz>
# 2020 Dennis Camera <dennis.camera at ssrq-sds-fds.ch>
# 2020,2022 Dennis Camera (skonfig at dtnr.ch)
#
# This file is part of cdist.
#
Expand All @@ -27,11 +27,13 @@
str2bytes() {
awk -F' ' '
$2 == "B" || !$2 { print $1 }
$2 == "kB" { printf "%.f\n", ($1 * 1000) }
$2 == "kB" ||
$2 == "KB" { printf "%.f\n", ($1 * 1000) }
$2 == "MB" { printf "%.f\n", ($1 * 1000 * 1000) }
$2 == "GB" { printf "%.f\n", ($1 * 1000 * 1000 * 1000) }
$2 == "TB" { printf "%.f\n", ($1 * 1000 * 1000 * 1000 * 1000) }
$2 == "kiB" { printf "%.f\n", ($1 * 1024) }
$2 == "kiB" ||
$2 == "KiB" { printf "%.f\n", ($1 * 1024) }
$2 == "MiB" { printf "%.f\n", ($1 * 1024 * 1024) }
$2 == "GiB" { printf "%.f\n", ($1 * 1024 * 1024 * 1024) }
$2 == "TiB" { printf "%.f\n", ($1 * 1024 * 1024 * 1024 * 1024) }'
Expand All @@ -41,6 +43,10 @@ bytes2kib() {
awk '$0 > 0 { printf "%.f\n", ($0 / 1024) }'
}

sum_lines() {
awk '{ sum += $0 } END { printf "%.f\n", sum }'
}


case $(uname -s)
in
Expand Down Expand Up @@ -84,6 +90,35 @@ in
| bytes2kib
fi
;;
(Sortix)
if command -v memstat >/dev/null 2>&1
then
memstat \
| awk '
NR==1 && /^memory usage: / {
# old format
match($0, /([0-9]+ +[A-Za-z]{0,2}B +)+total/)
total = substr($0, RSTART, RLENGTH)
sub(/ +total$/, "", total)
np = split(total, parts, /B +/)
sub(/B$/, "", parts[np])
for (i = 1; i <= np; i++)
print parts[i] "B"
exit
}
$2 == "total" {
if ($1 ~ /B$/)
sub(/B$/, "", $1)
else
sub(/.$/, " &iB", $1)
print $1
}
' \
| str2bytes \
| bytes2kib \
| sum_lines
fi
;;
(*)
printf "Your kernel (%s) is currently not supported by the memory explorer\n" "$(uname -s)" >&2
printf "Please contribute an implementation for it if you can.\n" >&2
Expand Down
11 changes: 11 additions & 0 deletions explorer/os
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
# Copyright 2017, Philippe Gregoire <pg@pgregoire.xyz>
# 2019-2022 Dennis Camera (skonfig at dtnr.ch)
#
# This file is part of cdist.
#
Expand Down Expand Up @@ -142,6 +143,16 @@ case "$uname_s" in
;;
esac

# Hobby OSes

if [ -f /etc/sortix-release ] || [ "${uname_s}" = 'Sortix' ]; then
echo sortix
exit 0
fi


# Generic os-release file check

if [ -f /etc/os-release ]; then
# after sles15, suse don't provide an /etc/SuSE-release anymore, but there is almost no difference between sles and opensuse leap, so call it suse
# shellcheck disable=SC1091
Expand Down
4 changes: 4 additions & 0 deletions explorer/os_version
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@ in
alpine)
cat /etc/alpine-release
;;
sortix)
rc_getvar /etc/sortix-release VERSION_ID
# alternatively: kernel release `uname -r`
;;
esac
45 changes: 37 additions & 8 deletions type/__directory/explorer/stat
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,45 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#

os=$("$__explorer/os")

destination="/$__object_id"

passwd_lookup() {
# usage: passwd_lookup file needle match_col print_col
awk -F ':' -v needle="${2:?}" -v mcol=$((${3:?})) -v pcol=$((${4:?})) '
$mcol == needle {
print $pcol
f = 1
}
END {
if (!f)
print "UNKNOWN"
}' "${1:?}"
}

fallback() {
# Patch the output together, manually

ls_line=$(ls -ldn "$destination")
if test "${os}" != 'sortix'
then
read -r mode_text links uid gid size _ <<EOF
$(ls -ldn "${destination}")
EOF

uid=$(echo "$ls_line" | awk '{ print $3 }')
gid=$(echo "$ls_line" | awk '{ print $4 }')
owner=$(passwd_lookup /etc/passwd $((uid)) 3 1)
group=$(passwd_lookup /etc/group $((gid)) 3 1)
else
# NOTE: Sortix' ls(1) does not currently support the -n option
read -r mode_text links owner group size _ <<EOF
$(ls -ld "${destination}")
EOF

owner=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/passwd)
group=$(awk -F: -v gid="$gid" '$3 == gid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/group)
uid=$(passwd_lookup /etc/passwd "${owner}" 1 3)
gid=$(passwd_lookup /etc/group "${group}" 1 3)
fi

mode_text=$(echo "$ls_line" | awk '{ print $1 }')
mode=$(echo "$mode_text" | awk '{for(i=8;i>=0;--i){c=substr($1,10-i,1);k+=((c~/[rwxst]/)*2^i);if(!(i%3))k+=(tolower(c)~/[lst]/)*2^(9+i/3)}printf("%04o",k)}')
mode=$(echo "${mode_text}" | awk '{for(i=8;i>=0;--i){c=substr($1,10-i,1);k+=((c~/[rwxst]/)*2^i);if(!(i%3))k+=(tolower(c)~/[lst]/)*2^(9+i/3)}printf("%04o",k)}')

printf 'type: %s\nowner: %d %s\ngroup: %d %s\nmode: %s %s\n' \
"$("$__type_explorer/type")" \
Expand All @@ -50,7 +74,7 @@ command -v stat >/dev/null 2>&1 || {
exit
}

case $("$__explorer/os")
case ${os}
in
freebsd|netbsd|openbsd|macosx)
stat -f 'type: %HT
Expand All @@ -59,6 +83,11 @@ group: %Dg %Sg
mode: %Mp%03Lp %Sp
' "$destination" | awk '/^type/ { print tolower($0); next } { print }'
;;
sortix)
# NOTE: currently, Sortix' stat(1) does not allow specifying a
# format string.
fallback
;;
*)
# NOTE: Do not use --printf here as it is not supported by BusyBox stat.
# NOTE: BusyBox's stat might not support the "-c" option, in which case
Expand Down
48 changes: 37 additions & 11 deletions type/__file/explorer/stat
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,45 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#

os=$("$__explorer/os")

destination="/$__object_id"

passwd_lookup() {
# usage: passwd_lookup file needle match_col print_col
awk -F ':' -v needle="${2:?}" -v mcol=$((${3:?})) -v pcol=$((${4:?})) '
$mcol == needle {
print $pcol
f = 1
}
END {
if (!f)
print "UNKNOWN"
}' "${1:?}"
}

fallback() {
# Fallback: Patch the output together, manually.

ls_line=$(ls -ldn "$destination")
if test "${os}" != 'sortix'
then
read -r mode_text links uid gid size _ <<EOF
$(ls -ldn "${destination}")
EOF

uid=$(echo "$ls_line" | awk '{ print $3 }')
gid=$(echo "$ls_line" | awk '{ print $4 }')
owner=$(passwd_lookup /etc/passwd $((uid)) 3 1)
group=$(passwd_lookup /etc/group $((gid)) 3 1)
else
# NOTE: Sortix' ls(1) does not currently support the -n option
read -r mode_text links owner group size _ <<EOF
$(ls -ld "${destination}")
EOF

owner=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/passwd)
group=$(awk -F: -v gid="$gid" '$3 == gid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/group)
uid=$(passwd_lookup /etc/passwd "${owner}" 1 3)
gid=$(passwd_lookup /etc/group "${group}" 1 3)
fi

mode_text=$(echo "$ls_line" | awk '{ print $1 }')
mode=$(echo "$mode_text" | awk '{for(i=8;i>=0;--i){c=substr($1,10-i,1);k+=((c~/[rwxst]/)*2^i);if(!(i%3))k+=(tolower(c)~/[lst]/)*2^(9+i/3)}printf("%04o",k)}')

size=$(echo "$ls_line" | awk '{ print $5 }')
links=$(echo "$ls_line" | awk '{ print $2 }')
mode=$(echo "${mode_text}" | awk '{for(i=8;i>=0;--i){c=substr($1,10-i,1);k+=((c~/[rwxst]/)*2^i);if(!(i%3))k+=(tolower(c)~/[lst]/)*2^(9+i/3)}printf("%04o",k)}')

printf 'type: %s\nowner: %d %s\ngroup: %d %s\nmode: %s %s\nsize: %d\nlinks: %d\n' \
"$("$__type_explorer/type")" \
Expand All @@ -59,7 +80,7 @@ command -v stat >/dev/null 2>&1 || {
}


case $("$__explorer/os")
case ${os}
in
freebsd|netbsd|openbsd|macosx)
stat -f 'type: %HT
Expand All @@ -70,6 +91,11 @@ size: %Dz
links: %Dl
' "$destination" | awk '/^type/ { print tolower($0); next } { print }'
;;
sortix)
# NOTE: currently, Sortix' stat(1) does not allow specifying a
# format string.
fallback
;;
*)
# NOTE: Do not use --printf here as it is not supported by BusyBox stat.
# NOTE: BusyBox's stat might not support the "-c" option, in which case
Expand Down
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|freebsd|netbsd|openbsd|gentoo|void)
(centos|fedora|redhat|scientific|freebsd|netbsd|openbsd|gentoo|sortix|void)
echo "hostname '${name_should}'"
;;
(openwrt)
Expand Down
2 changes: 1 addition & 1 deletion type/__hostname/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fi

case ${os}
in
(alpine|debian|devuan|ubuntu|void)
(alpine|debian|devuan|sortix|ubuntu|void)
echo "${name_should}" | __file /etc/hostname --source -
;;
(archlinux)
Expand Down
8 changes: 8 additions & 0 deletions type/__sshd_config/explorer/config_file
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ else
echo '/etc/sshd_config'
fi
;;
(sortix)
if test -e '/etc/sshd_config'
then
echo '/etc/sshd_config'
else
echo '/etc/default/sshd_config'
fi
;;
(*)
echo '/etc/ssh/sshd_config'
;;
Expand Down
Loading