summaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
Diffstat (limited to 'sh')
-rwxr-xr-xsh/upd55
1 files changed, 50 insertions, 5 deletions
diff --git a/sh/upd b/sh/upd
index 4c21182..5cfe8f3 100755
--- a/sh/upd
+++ b/sh/upd
@@ -1,6 +1,15 @@
#!/bin/sh
+die () {
+ echo "error: $*" >&2
+ exit 1
+}
+
all () {
+ # monthly_misc() needs to use qbittorrent-nox APIs, so I need to restart qbt before that, so I put qb() at top here, not perfect but good enough
+ if [ "$hostname" = xyzia ]; then
+ qb
+ fi
fast
clean
# don't run reflector if it is pp or aa or {it is studio and insp is in the same network}
@@ -8,14 +17,11 @@ all () {
if ! { [ "$hostname" = xyzpp ] || [ "$hostname" = xyzaa ] || { [ "$hostname" = xyzstudio ] && ping -4qc1 xyzinsp > /dev/null;};}; then
refl
fi
- if [ "$hostname" = xyzia ]; then
- qb
- fi
- [ "$hostname" = xyzinsp ] && music
+ monthly_misc
if [ "$hostname" = xyzinsp ] || [ "$hostname" = xyzpp ]; then
userjs
fi
- monthly_misc
+ [ "$hostname" = xyzinsp ] && music
}
backup () {
@@ -249,6 +255,45 @@ monthly_misc () {
echo 'Wait for studio sudo prompt and enter password:'
ssh -t studio 'sudo mv /tmp/mirrorlist /etc/pacman.d/mirrorlist && sudo chown root:root /etc/pacman.d/mirrorlist'
fi
+
+ # https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)
+ curl -s -X POST '10.0.0.4:57151/api/v2/search/updatePlugins' &
+ for qbt_wireguard_ip in 10.0.0.3 10.0.0.4; do
+ curl -s https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt | awk '$0{printf("%s\\n",$0)}' | xargs -0 -I {} curl -s -d json='{"add_trackers":"{}"}' "$qbt_wireguard_ip:57151/api/v2/app/setPreferences" &
+ # another way: `jq -r '.[]|"\(.added_on)\t\(.hash)\t\(.name)"'`
+ curl -s "$qbt_wireguard_ip:57151/api/v2/torrents/info?category=useful" | jq -r '.[]|[.added_on,.hash,.name]|@tsv' | grep 'archlinux.*\.iso' | sort -n | head -n-1 | awk '{print $2}' | while read -r hash; do
+ # need POST to delete torrents. -d default POST, so no need `-X POST`
+ curl -s -d "hashes=$hash" -d deleteFiles=true "$qbt_wireguard_ip:57151/api/v2/torrents/delete"
+ done &
+ done
+ wait
+
+ while ! [ -d /run/media/xyz/Ventoy ]; do
+ alarm 0 'Plug in usb flash drive'
+ echo 'Plug in usb flash drive'
+ sleep 10
+ done
+ #[ -d /run/media/xyz/Ventoy ] || die "No usb flash drive"
+
+ rsync -vPu studio:~/downloads/torrents/useful/archlinux*.iso /run/media/xyz/Ventoy/archlinux-x86_64.iso
+ # only check checksum and gpg signature on insp is sufficient for me, else too much work
+ if curl -s -o /run/media/xyz/Ventoy/archlinux-x86_64.iso.sig https://mirror.fcix.net/archlinux/iso/latest/archlinux-x86_64.iso.sig; then
+ gpg --verify /run/media/xyz/Ventoy/archlinux-x86_64.iso.sig || die 'Arch iso gpg signature check failed'
+ else
+ die 'Arch iso gpg signature download failed'
+ fi
+ # need to cd to iso file dir to checksum
+ cd /run/media/xyz/Ventoy || exit
+ curl -s https://mirror.fcix.net/archlinux/iso/latest/sha256sums.txt | grep archlinux-x86_64\.iso | tee /run/media/xyz/Ventoy/archlinux-x86_64.iso.sha256 | sha256sum -c || die 'Arch iso checksum does not match'
+ # if stay at /run/media/xyz/Ventoy, will cause it be busy and can't be umount, which will cause `ventoy -u` fail
+ # need to be after `wait`, because checksum need to be at ventoy dir
+ cd || exit
+
+ disk="$(df /run/media/xyz/Ventoy/ | awk 'END{sub(/[[:digit:]]+$/,"",$1);printf("%s",$1)}')"
+ sudo ventoy -l "$disk" | awk '/Ventoy:/{a=$2} /Ventoy Version in Disk:/{b=$NF;exit} END{exit((a==b)?1:0)}' && sudo ventoy -u "$disk"
+ umount /run/media/xyz/Ventoy /run/media/xyz/FAT32DIR
+
+ alarm 0 'Unplug usb flash drive'
fi
}