Advertisement
TWeiss

Untitled

Nov 12th, 2024
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.65 KB | None | 0 0
  1. #!/bin/bash
  2. # shellcheck disable=SC2015
  3. set -e
  4.  
  5. minimal_pacman_conf() {
  6.     local TEMP_CONF
  7.     TEMP_CONF=$(mktemp)
  8.     echo -e "[chaotic-aur]\nServer = https://garudalinux.org/os/garuda-update/backuprepo/x86_64" >"$TEMP_CONF"
  9.     echo "$TEMP_CONF"
  10. }
  11.  
  12. self_update() {
  13.     # Let the update script self update
  14.     local EXTRA_PARAMS=()
  15.     if [ "$DATABASE_UPDATED" == "force" ]; then
  16.         $PACMAN -Syy && DATABASE_UPDATED=true || true
  17.     elif [ "$DATABASE_UPDATED" != "true" ]; then
  18.         $PACMAN -Sy && DATABASE_UPDATED=true || true
  19.     fi
  20.     [ "$DATABASE_UPDATED" != "true" ] && local MIN_PACMAN_CONF && MIN_PACMAN_CONF="$(minimal_pacman_conf)" && $PACMAN --config "$MIN_PACMAN_CONF" -Syy && EXTRA_PARAMS=("--config" "$MIN_PACMAN_CONF") || true
  21.     $INT
  22.     if $PACMAN "${EXTRA_PARAMS[@]}" -Qu garuda-update &>/dev/null; then
  23.         local success=true
  24.         if ! SNAP_PAC_SKIP=y SKIP_AUTOSNAP='' $PACMAN "${EXTRA_PARAMS[@]}" -Sdd garuda-update --needed --noconfirm; then
  25.             $INT
  26.             # Create unshare'd mount namespace and mount an empty tmpfs on /usr/share/libalpm/hooks and /var/cache/pacman/pkg if it exists
  27.             unshare -m bash -c 'mount -t tmpfs tmpfs /usr/share/libalpm/hooks && { [ ! -d /var/cache/pacman/pkg ] || mount -t tmpfs tmpfs /var/cache/pacman/pkg; } && eval "$@"' -- SNAP_PAC_SKIP=y SKIP_AUTOSNAP='' "$PACMAN" "${EXTRA_PARAMS[@]}" --hookdir "/usr/share/libalpm/hooks" -Sdd garuda-update --needed --noconfirm || success=false
  28.         fi
  29.         $INT
  30.         if [ "$success" == "true" ]; then
  31.             GARUDA_UPDATE_SELFUPDATE=2 exec /usr/bin/garuda-update "$@"
  32.         fi
  33.     fi
  34.     # Check if we have received sigint and should exit
  35.     $INT
  36. }
  37.  
  38. # Some funny stuff with reflector makes it not exit on sigint, we set up our own sigint handler for that
  39. INT=true
  40. trap "INT=false" INT
  41.  
  42. # Show a help text in case it was requested
  43. if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "help" ]; then
  44.     # shellcheck source=./help
  45.     source /usr/lib/garuda/garuda-update/help
  46. fi
  47.  
  48. # Elevate once and stop asking for the password constantly
  49. if [[ $EUID -ne 0 ]]; then
  50.     exec sudo --preserve-env="SKIP_MIRRORLIST,UPDATE_AUR,PACMAN_EXE,GARUDA_SNAPSHOT_PACMAN,PACMAN_EXTRA_OPTS" /usr/bin/garuda-update "$@"
  51.     exit 1
  52. fi
  53.  
  54. # Run the "I'm too lazy to fix it myself all in one" script
  55. if [ "$1" == "remote" ]; then
  56.     exec bash -c "VERSION=6 . <(wget -qO- https://garudalinux.org/os/garuda-update/remote-update) \"\$@\"" remote-update "${@:2}"
  57. fi
  58.  
  59. if [ -n "$PACMAN_EXE" ]; then
  60.     PACMAN="$PACMAN_EXE"
  61. else
  62.     PACMAN="pacman"
  63. fi
  64.  
  65. export PACMAN
  66.  
  67. DATABASE_UPDATED=false
  68. if [ -n "$GARUDA_UPDATE_SELFUPDATE" ]; then
  69.     DATABASE_UPDATED=true
  70. fi
  71.  
  72. self_update "$@"
  73.  
  74. # shellcheck source=./main-update
  75. source /usr/lib/garuda/garuda-update/main-update
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement