Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.78 KB | None | 0 0
  1. #!/bin/bash
  2. ###############################################################################
  3. #  Script: suse-update.sh
  4. # Purpose: Update openSUSE tumbleweed with the latest packages.
  5. # Version: 1.01
  6. #  Author: Dan Huckson
  7. #    Date: 2017/09/20
  8. ###############################################################################
  9.  
  10. date_time=`date`
  11. start_time=$(date +%s)
  12.  
  13. echo $date_time >> /tmp/suse-update-timestamps.txt
  14. echo -e "\nStart Time: $date_time\n" > /var/log/suse-update.log
  15.  
  16. if [ -z "$1" ]; then VERBOSITY=0; else VERBOSITY=$1; fi
  17.  
  18. if (( $VERBOSITY > 1 )) || (( $VERBOSITY < 0 )); then
  19.     echo "Incorrect value entered."
  20.     exit
  21. fi
  22.  
  23. if (( $VERBOSITY )); then
  24.     zypper refresh > /dev/nil
  25.     echo Refreshed `zypper repos | grep -e '| Yes ' | cut -d'|' -f3 | wc -l` repositories
  26.     zypper -v -n update --auto-agree-with-licenses | grep -P "^Nothing to do|^CommitResult  \(|The following \d{1}" | sed 's/The following //' | tee -a /var/log/suse-update.log
  27. else
  28.     echo -e "\nRefreshing Repositories" | tee -a /var/log/suse-update.log
  29.     echo -e "----------------------------------------" | tee -a /var/log/suse-update.log
  30.     zypper refresh | cut -d"'" -f2 | tee -a /var/log/suse-update.log
  31.     echo -e "----------------------------------------\n" | tee -a /var/log/suse-update.log
  32.     zypper -v -n update --auto-agree-with-licenses | sed "/Unknown media type in type/d;s/^   //;/^Additional rpm output:/d" | sed ':a;N;$!ba;s/\n  / /g' | tee -a /var/log/suse-update.log
  33. fi
  34.  
  35. s=$[$(date +%s) - $start_time]; h=$[$s / 3600]; s=$[$s - $[$h * 3600]]; m=$[$s / 60]; s=$[$s - $[m * 60]]
  36. [ "$h" != '0' ] && hours=" $h hours" || hours=""
  37. [ "$m" != '0' ] && minutes=" $m minutes and" || minutes=""
  38. echo -e "\nTotal run time$hours$minutes $s seconds." | tee -a /var/log/suse-update.log
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement