Merge branch 'master' into __download_improvements

This commit is contained in:
ander 2020-06-28 16:57:13 +03:00
commit 99b5dcd8f0
5 changed files with 112 additions and 46 deletions

View file

@ -26,7 +26,7 @@
os=$(cat "$__global/explorer/os") os=$(cat "$__global/explorer/os")
case "$os" in case "$os" in
debian|ubuntu) debian|devuan|ubuntu)
locale_conf="/etc/default/locale" locale_conf="/etc/default/locale"
;; ;;
archlinux) archlinux)

View file

@ -1,7 +1,8 @@
#!/bin/sh #!/bin/sh -e
# #
# 2011 Nico Schottelius (nico-cdist at schottelius.org) # 2011 Nico Schottelius (nico-cdist at schottelius.org)
# 2012 Giel van Schijndel (giel plus cdist at mortis dot eu) # 2012 Giel van Schijndel (giel plus cdist at mortis dot eu)
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -19,21 +20,78 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
# #
# Retrieve the status of a package - parsed opkg output # Retrieve the status of a package - parses opkg output
# #
if [ -f "$__object/parameter/name" ]; then readonly __type_path=${__object%%${__object_id}*}
name="$(cat "$__object/parameter/name")" test -d "${__type_path}" || { echo 'Cannot determine __type_path' >&2; exit 1; }
readonly LOCKFILE="${__type_path:?}/.cdist_opkg.lock"
if command -v flock >/dev/null 2>&1
then
# use flock (if available) on FD 9
_lock() {
exec 9<>"${LOCKFILE:?}"
flock -x 9
echo $$>&9
}
_unlock() {
:>"${LOCKFILE:?}"
flock -u 9
exec 9<&-
}
else else
name="$__object_id" # fallback to mkdir if flock is missing
_lock() {
until mkdir "${LOCKFILE:?}.dir" 2>/dev/null
do
while test -d "${LOCKFILE}.dir"
do
# DEBUG:
# printf 'Locked by PID: %u\n' "$(cat "${LOCKFILE}.dir/pid")"
sleep 1
done
done
echo $$ >"${LOCKFILE:?}.dir/pid"
}
_unlock() {
test -d "${LOCKFILE}.dir" || return 0
if test -s "${LOCKFILE}.dir/pid"
then
test "$(cat "${LOCKFILE}.dir/pid")" = $$ || return 1
rm "${LOCKFILE:?}.dir/pid"
fi
rmdir "${LOCKFILE:?}.dir"
}
fi fi
# Except dpkg failing, if package is not known / installed
if opkg status "$name" 2>/dev/null | grep -q "^Status: install user installed$"; then if test -f "${__object}/parameter/name"
echo "present" then
exit 0 pkg_name=$(cat "${__object}/parameter/name")
elif [ "$(opkg info "$name" 2> /dev/null | wc -l)" -eq 0 ]; then else
echo "absent notpresent" pkg_name=$__object_id
exit 0 fi
# NOTE: We need to lock parallel execution of type explorers and code-remote
# because opkg will try to acquire the OPKG lock (usually /var/lock/opkg.lock)
# using lockf(2) for every operation.
# It will not wait for the lock but terminate with an error.
# This leads to incorrect 'absent notpresent' statuses when parallel execution
# is enabled.
trap _unlock EXIT
_lock
# Except opkg failing, if package is not known / installed
if opkg status "${pkg_name}" 2>/dev/null \
| grep -q -e '^Status: [^ ][^ ]* [^ ][^ ]* installed$'
then
echo 'present'
elif opkg info "${pkg_name}" 2>/dev/null | grep -q .
then
echo 'absent notpresent'
else
echo 'absent'
fi fi
echo "absent"

View file

@ -2,6 +2,7 @@
# #
# 2011,2013 Nico Schottelius (nico-cdist at schottelius.org) # 2011,2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2012 Giel van Schijndel (giel plus cdist at mortis dot eu) # 2012 Giel van Schijndel (giel plus cdist at mortis dot eu)
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -19,41 +20,50 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
# #
# Manage packages on OpenWRT and co. # Manage packages on OpenWrt, optware, and co.
# #
if [ -f "$__object/parameter/name" ]; then if test -f "${__object}/parameter/name"
name="$(cat "$__object/parameter/name")" then
name=$(cat "${__object}/parameter/name")
else else
name="$__object_id" name=$__object_id
fi fi
state_should="$(cat "$__object/parameter/state")" state_should=$(cat "${__object}/parameter/state")
state_is=$(cat "${__object}/explorer/pkg_status")
state_is="$(cat "$__object/explorer/pkg_status")" case $state_is
case "$state_is" in in
absent*) (absent*)
present="$(echo "$state_is" | cut -d ' ' -f 2)" presence=$(echo "${state_is}" | cut -d ' ' -f 2)
state_is="absent" state_is='absent'
;; ;;
esac esac
[ "$state_is" = "$state_should" ] && exit 0 if test "${state_is}" = "${state_should}"
then
case "$state_should" in exit 0
present)
if [ "$present" = "notpresent" ]; then
echo "opkg --verbosity=0 update"
fi fi
echo "opkg --verbosity=0 install '$name'"
echo "installed" >> "$__messages_out"
case $state_should
in
(present)
if test "${presence}" = 'notpresent'
then
echo 'opkg --verbosity=0 update'
fi
printf "opkg --verbosity=0 install '%s'\n" "${name}"
echo 'installed' >>"${__messages_out}"
;; ;;
absent) (absent)
echo "opkg --verbosity=0 remove '$name'" printf "opkg --verbosity=0 remove '%s'" "${name}"
echo "removed" >> "$__messages_out" echo 'removed' >>"${__messages_out}"
;; ;;
*) (*)
echo "Unknown state: ${state_should}" >&2 printf 'Unknown state: %s\n' "${state_should}" >&2
exit 1 exit 1
;; ;;
esac esac

View file

@ -45,8 +45,6 @@ def resolve_target_host_name(host, family=0):
log.debug("derived host_name for host \"{}\": {}".format( log.debug("derived host_name for host \"{}\": {}".format(
host, host_name)) host, host_name))
except (socket.gaierror, socket.herror) as e: except (socket.gaierror, socket.herror) as e:
log.warning("Could not derive host_name for {}"
", $host_name will be empty. Error is: {}".format(host, e))
# in case of error provide empty value # in case of error provide empty value
host_name = '' host_name = ''
return host_name return host_name
@ -59,8 +57,6 @@ def resolve_target_fqdn(host):
log.debug("derived host_fqdn for host \"{}\": {}".format( log.debug("derived host_fqdn for host \"{}\": {}".format(
host, host_fqdn)) host, host_fqdn))
except socket.herror as e: except socket.herror as e:
log.warning("Could not derive host_fqdn for {}"
", $host_fqdn will be empty. Error is: {}".format(host, e))
# in case of error provide empty value # in case of error provide empty value
host_fqdn = '' host_fqdn = ''
return host_fqdn return host_fqdn

View file

@ -3,6 +3,8 @@ Changelog
next: next:
* New type: __download (Ander Punnar) * New type: __download (Ander Punnar)
* Type __locale_system: Add devuan support (Dennis Camera)
* Type __package_opkg: Add locking (Dennis Camera)
6.6.0: 2020-06-17 6.6.0: 2020-06-17
* Type __ssh_authorized_keys: Add option for removing undefined keys (Ander Punnar) * Type __ssh_authorized_keys: Add option for removing undefined keys (Ander Punnar)