Advertisement
Guest User

snapshot+systemupdate.sh

a guest
Dec 8th, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.81 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Snapshot + System Update
  4. # ---------------------------
  5. # Snapshot - Rollback - Btrfs
  6. # ---------------------------
  7.  
  8. BTRFS=/usr/bin/btrfs
  9. CP=/usr/bin/cp
  10. ECHO=/usr/bin/echo
  11. GREP=/usr/bin/grep
  12. MOUNT=/usr/bin/mount
  13. MV=/usr/bin/mv
  14. PIKAUR=/usr/bin/pikaur
  15. PACMAN=/usr/bin/pacman
  16. REFLECTOR=/usr/bin/reflector
  17. SED=/usr/bin/sed
  18. SUDO=/usr/bin/sudo
  19. CHECKUPDATES=/usr/bin/checkupdates
  20.  
  21. # ---------------------------
  22. #      Snapshot System
  23. # ---------------------------
  24. if $CHECKUPDATES ; then
  25. # if true ; then
  26. bootstate=`$MOUNT | $GREP "on / type btrfs" | $GREP "subvol=/@snapshots/TESTING"`
  27. if [ -z "$bootstate" ]
  28.     then
  29.         $ECHO ""
  30.         $ECHO $bootstate
  31.         $ECHO ""
  32.         $ECHO "System ist nicht mit TESTING hochgefahren !"
  33.         $ECHO "ENDE !"
  34.         sleep 2
  35.         exit 1
  36.     else
  37.     # -------- make new OLDSTABLE --------
  38.         $SUDO $BTRFS subvolume delete /.snapshots/OLDSTABLE
  39.         $SUDO $MV /.snapshots/STABLE /.snapshots/OLDSTABLE
  40.         $SUDO $SED -i 's/STABLE/OLDSTABLE/g' /.snapshots/OLDSTABLE/etc/fstab
  41.         $SUDO $CP /boot/vmlinuz-linux-stable /boot/vmlinuz-linux-oldstable
  42.         $SUDO $CP /boot/initramfs-linux-stable.img /boot/initramfs-linux-oldstable.img
  43.         # $SUDO $CP /boot/vmlinuz-linux-lts-stable /boot/vmlinuz-linux-lts-oldstable
  44.         # $SUDO $CP /boot/initramfs-linux-lts-stable.img /boot/initramfs-linux-lts-oldstable.img
  45.        
  46.         # --------- make new STABLE ----------
  47.         $SUDO $BTRFS subvolume snapshot / /.snapshots/STABLE
  48.         $SUDO $SED -i 's/TESTING/STABLE/g' /.snapshots/STABLE/etc/fstab
  49.         $SUDO $CP /boot/vmlinuz-linux /boot/vmlinuz-linux-stable
  50.         $SUDO $CP /boot/initramfs-linux.img /boot/initramfs-linux-stable.img
  51.         # $SUDO $CP /boot/vmlinuz-linux-lts /boot/vmlinuz-linux-lts-stable
  52.         # $SUDO $CP /boot/initramfs-linux-lts.img /boot/initramfs-linux-lts-stable.img
  53.        
  54.         # ---------------------------
  55.         #      Update System
  56.         # ---------------------------
  57.         $SUDO $REFLECTOR -l 10 -p https --sort rate # initiate 2 ChannelFastSpeed of MagentaHybrid-Router
  58.         $SUDO $REFLECTOR --verbose -l 10 -p https --sort rate --save /etc/pacman.d/mirrorlist
  59.         # $SUDO $PACMAN -Syu
  60.         $PIKAUR -Syu # aktualisiert AUR gleich mit :-)
  61.        
  62.         # -------------------------------------------------------------------------------------
  63.         #    disable automatic-search for grub - only 00_header 40_custom 41_custom are needed
  64.         # -------------------------------------------------------------------------------------
  65.         for file in `ls /etc/grub.d/ | grep -v ^4 | grep -v README | grep -v ^00 | grep -v disabled$` ; do
  66.             $SUDO chmod 644 /etc/grub.d/$file
  67.             $SUDO mv /etc/grub.d/$file /etc/grub.d/"$file"_disabled
  68.         done
  69.  
  70.         # --------------------------------------------
  71.         #    Balance Filesystem
  72.         # --------------------------------------------
  73.         $SUDO $BTRFS balance start -dusage=5 /btrfs
  74.  
  75. fi
  76. else
  77.     echo "Keine Updates vorhanden - ENDE !"
  78.     sleep 2
  79. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement