admin-scripts/.archived/seed-armbian-tx.nu

56 lines
1.2 KiB
Plaintext
Raw Normal View History

2024-03-26 05:05:38 +01:00
#!/usr/bin/env nu
use std log
# Create temporary directory to store torrents
let temp_dir = (mktemp -d)
chmod 700 $temp_dir
# Download the torrents archive and save to temporary directory
let torrent_zip = ($temp_dir | path join "armbian-torrents.zip")
(
2024-04-02 19:32:26 +02:00
http get -r "https://dl.armbian.com/torrent/all-torrents.zip"
| save -r $torrent_zip
2024-03-26 05:05:38 +01:00
)
# Test torrent_zip for corruption
if (unzip -t $torrent_zip | complete | get exit_code) != 0 {
log error "Error in zip";
exit
}
# Extract torrent_zip
unzip -o $torrent_zip -d ($temp_dir | path join "torrent-tmp") | ignore
# Create list of current active Armbian torrent ids
let armbian_torrent_ids = (
2024-04-02 19:32:26 +02:00
transmission-remote -n 'debian-transmission:debian-transmission' -l
| from ssv
| drop nth 0
| drop
| find "Armbian"
| get ID
2024-03-26 05:05:38 +01:00
)
# Remove torrents from armbian_torrent_ids
$armbian_torrent_ids | each {
|id|
(
transmission-remote -n 'debian-transmission:debian-transmission'
-t $"($id)"
--remove-and-delete
)
} | ignore
# Add new/updated Armbian torrents
(
2024-04-02 19:32:26 +02:00
ls ($temp_dir | path join "torrent-tmp")
| get name
| each {
2024-03-26 05:05:38 +01:00
|torrent|
transmission-remote -n 'debian-transmission:debian-transmission' -a $"($torrent)"
} | ignore
)
# Clean up temporary directory
rm -rf $temp_dir