Skip to content

Instantly share code, notes, and snippets.

@mozlima
Created November 23, 2020 04:36
Show Gist options
  • Save mozlima/76ae1aa5b0cfcf217ab4b4258e08dfd2 to your computer and use it in GitHub Desktop.
Save mozlima/76ae1aa5b0cfcf217ab4b4258e08dfd2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#Bypass any and all “Are you sure?” messages from pacman.
NOCONFIRM=1
#Install reflector (https://www.archlinux.org/packages/?name=reflector) ,
#To update mirrorlist and set REFLECTOR_ENABLE=1
REFLECTOR_ENABLE=0
REFLECTOR_COUNTRY="United States"
#Install https://aur.archlinux.org/packages/systemd-system-update-pacman/ ,
#To apply the updates in the next reboot and set UPDATE_NEXT_REBOOT=1
UPDATE_NEXT_REBOOT=0
if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi
if [[ "$REFLECTOR_ENABLE" == "1" ]] ; then
echo "UPDATING: mirrorlist"
reflector --verbose --country "$REFLECTOR_COUNTRY" -l 5 -p https --sort rate --save /tmp/bkp.mirrorlist
cp -f /tmp/bkp.mirrorlist /etc/pacman.d/mirrorlist
else
cp -f /etc/pacman.d/mirrorlist /tmp/bkp.mirrorlist
fi
RXP_URL='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
LOCALIP=$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p')
pacman -Sy
arp -ne | grep ':' | grep -v "$LOCALIP" | awk '{print "http://"$1":8080"}' | while read url; do
if [[ "$url" =~ $RXP_URL ]] && [[ $(wget -t 1 -T 2 -q "${url}" -O- | grep core.db) ]]; then
echo "LINK ADDED: $url"
if ! grep -qxF "Server = ${url}" /etc/pacman.d/mirrorlist; then
echo -e "Server = $url\n$(cat /etc/pacman.d/mirrorlist)" | tee /etc/pacman.d/mirrorlist > /dev/null
fi
break
else
echo "LINK NOT ADDED: $url"
fi
done;
if [[ "$UPDATE_NEXT_REBOOT" == "1" ]] ; then
pacman -Suw --noconfirm
#FIXME: Check if need schedule-system-update if not package was installed
schedule-system-update
echo "Reboot to finish the update!"
else
[[ "$NOCONFIRM" == "1" ]] && pacman -Su --noconfirm || pacman -Su
echo "Finish"
fi
cp -f /tmp/bkp.mirrorlist /etc/pacman.d/mirrorlist
#!/usr/bin/env bash
if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi
sudo ln /var/lib/pacman/sync/*.db /var/cache/pacman/pkg
sudo -u http darkhttpd /var/cache/pacman/pkg --no-server-id --maxconn 8
#Sync and download the updated packages in advance
pacman -Suw --noconfirm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment