git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authormail_redacted_for_web 2019-01-07 10:55:12 +0100
committermail_redacted_for_web 2019-01-07 10:55:12 +0100
commit7ab0688c6c29bb537f024934280ec4ff64a13ea3 (patch)
treedec0bab32a5ccf680d86572dd668280f7463ada4 /sbin
parent36ed33e88f4ba560649fc16fc1aa895e4e6ee34d (diff)
downloaddebian-scripts-7ab0688c6c29bb537f024934280ec4ff64a13ea3.tar.bz2
version update: needrestart treatment, help
Diffstat (limited to 'sbin')
-rwxr-xr-xsbin/ln-update90
1 files changed, 56 insertions, 34 deletions
diff --git a/sbin/ln-update b/sbin/ln-update
index 6b025a3..ba8ce00 100755
--- a/sbin/ln-update
+++ b/sbin/ln-update
@@ -28,7 +28,9 @@ GTLUNT="gitlab-runsvdir.service"
NDRBIN="$(which needrestart||echo "/usr/sbin/needrestart")"
# -e: see RKHBIN
[ ! -e "$NDRBIN" ]&&unset NDRBIN
-NDRCLP=( "-ra" "-blqp" )
+NDRLLP=( "-rl" "-blqp" )
+NDRLKP=( "-rl" "-bkqp" )
+NDRCLP=( "-ra" )
NDRCKP=( "-ra" "-bkqp" )
RETSAV="\\033[s"
RETCLR="\\033[K"
@@ -40,12 +42,24 @@ SHUTUP=0
LOGDMP=0;LOGTARG="ln-update"
GTLUPD=0
RETVAL=0
+NOAPT=0
+hayulp() {
+ echo "USAGE: $(basename "$0") [ -h ] [ -l ] [ -q ]"
+ echo
+ echo -e "-h:\tThis help"
+ echo -e "-l:\tLog progress in syslog"
+ echo -e "-q:\tNo output, e.g. for scripted calls"
+}
retinit() {
echo -ne "[....] $1$RETSAV""..."
}
retinf() {
# Delivers the initial log output to be adjusted by return values
- echo -e "$(tput cub 666)[$(tput setaf 7)INFO$(tput sgr0)]$RETRES$RETCLR"" ($(tput setaf 7)$1$(tput sgr0))."
+ if [ -z "$1" ];then
+ echo -e "$(tput cub 666)[$(tput setaf 6)INFO$(tput sgr0)]$RETRES$RETCLR""."
+ else
+ echo -e "$(tput cub 666)[$(tput setaf 6)INFO$(tput sgr0)]$RETRES$RETCLR"" ($(tput sgr0)$1""."
+ fi
}
gitlab-start() {
# Starts a stopped gitlab instance: unmasks gitlab-runsvdir, starts that service and executes
@@ -186,23 +200,27 @@ needrestart-ck() {
# RC:
# 255: Outdated services still active or running kernel outdated
LOCRETVAL=0
- [ "$SHUTUP" -ne 1 ]&&retinit "Checking for services in need of restart"
[ "$LOGDMP" -eq 1 ]&&logger -p"info" -t"$LOGTARG" "Checking for services in need of restart..."
- LLIBRES="$("$NDRBIN" "${NDRCLP[@]}")"
+ LLIBCNT="$("$NDRBIN" "${NDRLLP[@]}" 2>&1|grep -P '^(WARN|OK|ERR)'|sed 's/.*Services=\([0-9]\{1,\}\).*/\1/g')"
+ [ "$SHUTUP" -ne 1 ]&&echo -e "[$(tput setaf 6)INFO$(tput sgr0)] $LLIBCNT services affected by previous update."
+ [ "$SHUTUP" -ne 1 ]&&retinit "Checking for services in need of restart"
+ LLIBRES="$("$NDRBIN" "${NDRCLP[@]}" 2>&1)"
NAGRETVAL="$?"
- case "$NAGRETVAL" in
+ LLIBCNT="$("$NDRBIN" "${NDRLLP[@]}" 2>&1|grep -P '^(WARN|OK|ERR)'|sed 's/.*Services=\([0-9]\{1,\}\).*/\1/g')"
+ case "$LLIBCNT" in
0)
[ "$SHUTUP" -ne 1 ]&&echo -e "$RETOGE"
[ "$LOGDMP" -eq 1 ]&&logger -p"info" -t"$LOGTARG" "No remaining services running with outdated libs."
;;
*)
[ "$SHUTUP" -ne 1 ]&&echo -e "$RETWRN"&&echo "$LLIBRES"|sed 's/^[^-]\+-\ \([^|]\+\)|.*/\1/g'
- [ "$LOGDMP" -eq 1 ]&&logger -p"warning" -t"$LOGTARG" "Some services could not be restarted: $LLIBRES"
+ LLIBCNR="$("$NDRBIN" "${NDRLLP[@]}" 2>&1|grep -P '^(WARN|OK|ERR)'|sed 's/.*Services[:=][\ ]\?\([0-9]\{1,\}\).*/\1/g')"
+ [ "$LOGDMP" -eq 1 ]&&logger -p"warning" -t"$LOGTARG" "Some services could not be restarted ($LLIBCNR/$LLIBCNT): $LLIBRES"
LOCRETVAL=255
;;
esac
- unset LLIBRES
- [ "$SHUTUP" -ne 1 ]&&retinit "Checking for outdated kernel..."
+ unset LLIBRES LLIBCNT
+ [ "$SHUTUP" -ne 1 ]&&retinit "Checking for outdated kernel"
[ "$LOGDMP" -eq 1 ]&&logger -p"info" -t"$LOGTARG" "Checking for outdated kernel..."
LKRNRES="$("$NDRBIN" "${NDRCKP[@]}")"
NAGRETVAL="$?"
@@ -221,10 +239,11 @@ needrestart-ck() {
return "$LOCRETVAL"
}
-while getopts :lq SHOPT;do
+while getopts :lqh SHOPT;do
case "$SHOPT" in
q)SHUTUP=1;;
l)LOGDMP=1;;
+ h)hayulp;exit 0;;
esac
done
@@ -261,7 +280,7 @@ unset UPDARR
case "$UPDCNT" in
0)
[ "$SHUTUP" -ne 1 ]&&retinf "No updates available :)"
- exit 0
+ NOAPT=1
;;
*)
[ "$SHUTUP" -ne 1 ]&&echo -e "$RETOGE ($UPDCNT updates)."
@@ -269,34 +288,38 @@ case "$UPDCNT" in
;;
esac
-"$APTBIN" list --upgradable 2>/dev/null|grep gitlab-ce >/dev/null
-if [ "$?" -eq 0 ];then
- [ "$SHUTUP" -ne 1 ]&&echo "Encountered Gitlab update."
- GTLUPD=1
-fi
+case "$NOAPT" in
+ 0)
+ "$APTBIN" list --upgradable 2>/dev/null|grep gitlab-ce >/dev/null
+ if [ "$?" -eq 0 ];then
+ [ "$SHUTUP" -ne 1 ]&&retinit "Encountered Gitlab update"&&retinf
+ GTLUPD=1
+ fi
-if [ ! -z "$RKHBIN" ];then rkhunter-ck||exit "$?";fi
+ if [ ! -z "$RKHBIN" ];then rkhunter-ck||exit "$?";fi
-if [ "$GTLUPD" -eq 1 ];then gitlab-start||exit "$?";fi
+ if [ "$GTLUPD" -eq 1 ];then gitlab-start||exit "$?";fi
-[ "$SHUTUP" -ne 1 ]&&retinit "Upgrading packages"
-#"$SUDBIN" "$APTBIN" -qqq -y dist-upgrade >/dev/null 2>&1
-"$APTBIN" -qqq -y dist-upgrade >/dev/null 2>&1
-case "$?" in
- 0)
- [ "$SHUTUP" -ne 1 ]&&echo -e "$RETOGE"
- [ "$LOGDMP" -eq 1 ]&&logger -p"info" -t"$LOGTARG" "Apt dist-upgrade successful."
- ;;
- *)
- [ "$SHUTUP" -ne 1 ]&&echo -e "$RETERR"
- [ "$LOGDMP" -eq 1 ]&&logger -p"error" -t"$LOGTARG" "Apt dist-upgrade failed."
- exit 5
- ;;
-esac
+ [ "$SHUTUP" -ne 1 ]&&retinit "Upgrading packages"
+ #"$SUDBIN" "$APTBIN" -qqq -y dist-upgrade >/dev/null 2>&1
+ "$APTBIN" -qqq -y dist-upgrade >/dev/null 2>&1
+ case "$?" in
+ 0)
+ [ "$SHUTUP" -ne 1 ]&&echo -e "$RETOGE"
+ [ "$LOGDMP" -eq 1 ]&&logger -p"info" -t"$LOGTARG" "Apt dist-upgrade successful."
+ ;;
+ *)
+ [ "$SHUTUP" -ne 1 ]&&echo -e "$RETERR"
+ [ "$LOGDMP" -eq 1 ]&&logger -p"error" -t"$LOGTARG" "Apt dist-upgrade failed."
+ exit 5
+ ;;
+ esac
-if [ "$GTLUPD" -eq 1 ];then gitlab-stop||exit "$?";fi
+ if [ "$GTLUPD" -eq 1 ];then gitlab-stop||exit "$?";fi
-if [ ! -z "$RKHBIN" ];then rkhunter-upd||exit "$?";fi
+ if [ ! -z "$RKHBIN" ];then rkhunter-upd||exit "$?";fi
+ ;;
+esac
if [ ! -z "$NDRBIN" ];then
needrestart-ck;NDRRETVAL="$?"
@@ -305,5 +328,4 @@ if [ ! -z "$NDRBIN" ];then
if [ "$RETVAL" -eq 0 ];then RETVAL="$NDRRETVAL";fi
unset NDRRETVAL
fi
-RETVAL="$?"
exit "$RETVAL"