LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-26-2020, 12:34 AM   #1
Lockywolf
Member
 
Registered: Jul 2007
Posts: 683

Rep: Reputation: 253Reputation: 253Reputation: 253
Question slackpkg return value


Hello, everyone.

At the moment I'm trying to bodge some scripts in order to make updating easier.

I just wonder whether it would make sense for `slackpkg upgrade-all` to return some false value (that is non-zero) in the case of cancelling the update (or, thinking further, different return values in cases of different interruption causes).

That is, zero (0) would mean "update succeeded", 1 would, for example, mean "update cancelled by the user", 2 could mean "download failed".

Then it would be easier to use slackpkg within the scripts.

For example, at the moment I'm doing four things at each update:
  1. slackpkg update && slackpkg install-new && slackpkg upgrade-all
  2. sbopkg -i nvidia-legacy390-kernel:KERNEL=$(find /lib/modules/ | head -1)
  3. sbopkg -i wireguard-linux-compat:KERNEL=$(find /lib/modules/ | head -1)
  4. dd if=/dev/root of=/mnt/backup/$(date)

I would like each of those steps to fail in case something is wrong and terminate the whole script. Hitting "cancel" at the update screen counts as a failure, because apparently means that updating is inappropriate at the moment.

What do people thing about this? Is it a good idea? Would anyone find this useful?

Last edited by Lockywolf; 07-26-2020 at 01:32 AM.
 
Old 07-26-2020, 11:23 AM   #2
ardya
Member
 
Registered: Mar 2006
Distribution: Slackware since 1997
Posts: 89

Rep: Reputation: 18
You might find the following useful to modify. It steps through each command, and scripts exits on first failure.

Code:
#!/bin/bash

# RUN_LOG and ERROR_LOG not defined but easily added and refs uncommented.

. /etc/COLORS
KERNEL=$1
OLDKERNEL=${2:-$(uname -r)}

get_exit_status() {
  echo -e "${BYELLOW}Running "$@"...${OFF}" #1>> $RUN_LOG 2>> $ERROR_LOG
  "$@" #1>> $RUN_LOG 2>> $ERROR_LOG
  RETVAL=$?
  if [ "$RETVAL" -eq "0" ]; then 
    echo -e "Exit value = ${BGREEN}${RETVAL}${OFF}" #1>> $RUN_LOG 2>> $ERROR_LOG
  else
    echo -e "Exit value = ${BRED}${RETVAL}${OFF}"
  fi 
  if [ "$RETVAL" -gt "0" ]; then
    echo -e "${BRED}"$@" exited with value ${RETVAL}, exiting.${OFF}" #1>> $RUN_LOG 2>> $ERROR_LOG
    echo #1>> $RUN_LOG 2>> $ERROR_LOG
    #mail_status $RETVAL #function not defined but easily added
    exit $RETVAL
  fi
  return $RETVAL
}

if [[ $KERNEL =~ ^[0-9]\.[0-9]{1,}\.[0-9]{1,3}$ ]] && [[ $OLDKERNEL =~ ^[0-9]\.[0-9]{1,}\.[0-9]{1,3}$ ]]; then
  CMD1="cp -v /boot/config-${OLDKERNEL} /usr/src/linux-${KERNEL}/.config"
  CMD2="cd /usr/src/linux-${KERNEL}"
  CMD3="make oldconfig"
  CMD4="make -j4"
  CMD5="make modules_install"
  CMD6="cp -v arch/x86/boot/bzImage /boot/vmlinuz-${KERNEL}"
  CMD7="cp -v .config /boot/config-${KERNEL}"
  CMD8="cp -v System.map /boot/System.map-${KERNEL}"
  CMD9="mkinitrd -F /etc/mkinitrd.conf -k ${KERNEL}"
  CMD10="/sbin/rcvboxadd quicksetup ${KERNEL}"

  CMDARY=("$CMD1" "$CMD2" "$CMD3" "$CMD4" "$CMD5" "$CMD6" "$CMD7" "$CMD8" "$CMD9" "$CMD10")

  for i in "${CMDARY[@]}"
    do get_exit_status $i
  done
else
  echo "Usage: $0 new_kernel_ver [old_kernel_ver (defaults to current version)]"
fi
 
  


Reply

Tags
bash, kernel, slackpkg, slackware, update



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Slackpkg, Slackpkg Plus, Slackware 14.1 x86_64 install.log delay or slow to write bamunds Slackware 7 04-22-2014 11:12 AM
[SOLVED] typos in latest /etc/slackpkg/mirrors(.new) [slackpkg-2.82.0-noarch-8.tgz] wailingwailer Slackware 4 09-22-2012 04:04 AM
strange value assignments variable = value, value?? ostrow30 Programming 2 07-24-2011 07:59 AM
difference between value *value and value * value PoleStar Linux - Newbie 1 11-26-2010 03:37 PM
Slackpkg: missing something in /usr/libexec/slackpkg/functions.d/dialog-functions.sh michelino Slackware 4 03-20-2007 12:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration