Last active
June 30, 2018 17:24
-
-
Save u1735067/b0f276e9c50bb1f5421a to your computer and use it in GitHub Desktop.
Aria automatic downloader script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# root@omv:/export/Medias/!Dépot/Aria# ls -la | |
# total 16 | |
# drwxrwsr-x 2 nobody users 4096 Aug 21 22:26 . | |
# -rw-r----- 1 root users 3258 Aug 21 22:25 !Archives.txt | |
# -rwxr-xr-- 1 root users 1.1K May 29 18:38 !IDN-Convert.py | |
# -rw-rw-r-- 1 alex users 0 Aug 21 22:25 !ToDL.txt | |
# -rwxr-xr-- 1 root users 1223 Aug 21 22:22 !ZeScript.sh | |
# SU owned, rw, r | |
archives='!Archives.txt' | |
lock='!Aria.lock' | |
# User owned, rw, rw, r | |
todl='!ToDL.txt' | |
idn_convert='python3 !IDN-Convert.py' | |
sepline=-------------------------------------------------------------------------------- | |
wecho() { | |
echo $*$'\r' | |
} | |
# Entering working directory | |
pushd `dirname "$0"` >/dev/null | |
wecho >> "$todl" | |
sed -i '/^\s*$/d' "$todl" | |
# Do we have something to download ? | |
if [ -e "$lock" ]; then | |
echo 'Lock present, skipping.' | |
elif [ -s "$todl" ]; then | |
# Create lock file | |
touch "$lock" | |
# Add new list to download list & empty new list | |
wecho "# New content at $(date +'%F %T %z')" >> "$archives" | |
wecho "# $sepline" >> "$archives" | |
# UTF-8 ou pas ? | |
if iconv -f utf8 $todl >/dev/null 2>&1; then | |
cat "$todl" | $idn_convert >> "$archives" | |
else | |
iconv -f cp1252 -t utf8 "$todl" | $idn_convert >> "$archives" | |
fi | |
wecho "# $sepline" >> "$archives" | |
# Sanity check | |
chmod 640 "$archives" | |
chmod 664 "$todl" | |
# Empty ToDL file | |
:>"$todl" | |
# Download (extract download result) | |
#umask 0002 | |
wecho "# Results" >> "$archives" | |
wecho "# $sepline" >> "$archives" | |
sudo -u 'nobody' -g 'users' -- sh -c "umask 0002; aria2c -j3 -U 'aria2/$VERSION - Alex' --summary-interval=0 --auto-file-renaming=false --seed-time=0 --input-file=$archives" | \ | |
sed -n '/Results/,/Legend/p' | head -n -2 | tail -n +2 | sed 's/^/# /;s/$/\r/' | tee -a "$archives" | |
wecho "# $sepline" >> "$archives" | |
wecho "#" >> "$archives" | |
wecho "#" >> "$archives" | |
# Comment out downloaded content | |
sed -i '/^[^#]/ s/^/#/' "$archives" | |
# Remove lock | |
rm -f "$lock" | |
else | |
echo 'Nothing to do.' | |
fi | |
# Leaving directory | |
popd >/dev/null | |
# Done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment