summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorAryan Ghasemi2024-01-02 22:22:42 +0330
committerAryan Ghasemi2024-01-02 22:22:42 +0330
commite7d974e83cd0eea83336a16e315692674e1a9efa (patch)
tree5c2be57ba003e485bbb7c44da1ff17fe775244e6
parentd4db66b89614ac8669b155997603bef2533cfaf7 (diff)
downloadaur-e7d974e83cd0eea83336a16e315692674e1a9efa.tar.gz
whoops! forgot .install file
-rw-r--r--midnight-dler.install23
-rw-r--r--midnight-dler.service11
-rwxr-xr-xmidnight-dler.sh45
3 files changed, 79 insertions, 0 deletions
diff --git a/midnight-dler.install b/midnight-dler.install
new file mode 100644
index 000000000000..f32be2e1fecf
--- /dev/null
+++ b/midnight-dler.install
@@ -0,0 +1,23 @@
+# This is a default template for a post-install scriptlet.
+# Uncomment only required functions and remove any functions
+# you don't need (and this header).
+
+
+post_install() {
+ cat <<eof
+package is installed now, but you need to set bios wake on clock settings to
+make your pc wakeup at night. else, you need to manually power on your system
+during the night.
+
+use "systemctl enable --now midnight-dler.service" to enable the service.
+eof
+}
+
+post_upgrade() {
+ post_install
+}
+
+## arg 1: the old package version
+#post_remove() {
+ # do something here
+#}
diff --git a/midnight-dler.service b/midnight-dler.service
new file mode 100644
index 000000000000..3acf1b54be10
--- /dev/null
+++ b/midnight-dler.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Update and Shutdown Service
+After=network-online.target
+#SuccessAction=none
+#OnSuccess=systemd-suspend.service
+[Service]
+RemainAfterExit=no
+Type=oneshot
+ExecStart=/usr/local/bin/midnight-dler.sh
+[Install]
+WantedBy=default.target
diff --git a/midnight-dler.sh b/midnight-dler.sh
new file mode 100755
index 000000000000..17e2520c0b01
--- /dev/null
+++ b/midnight-dler.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/bash -xu
+#
+# Script job is to check if the sytem's time is as specified time and if it is, then do some downloading and updating.
+# At the end, machine will be powered off by systemd.
+#
+# Links should be downloaded by download()
+
+LOG='/var/log/midnight-dler.log'
+function clock-check() {
+ TIME_NOW="$(date +%H%M)"
+ if [[ $TIME_NOW > 0200 && $TIME_NOW < 0700 ]]; then #Checks if time is between 2:00 - 4:00. Cause this script should get run only at this time.
+ echo 'clock-check success!'
+ return 0
+ else
+ return 1
+ fi
+}
+# Well, script doesn't know the $LINKS and $LINKS_ have been downloaded or not. therefore it rerun the `aria2c` and `yt-dlp` commands.
+# Although `aria2c` and `yt-dlp` are smart enough to skip the download if files downloaded correctly.
+if [[ $0 -nt $LOG ]]; then # if chores.sh is newer than chores.log, new stuff was added to LINKS or LINKS_.
+ SCRIPT_NT_LOG=true
+else
+ SCRIPT_NT_LOG=false
+ echo "Not any new links here for download.\n skipping..." &>>$LOG
+fi
+function update() {
+ /usr/bin/pacman -Syu --noconfirm &>$LOG #will be replaced with `pacman -Syu --no-confirm`. it's just for the examining.
+}
+
+function download() {
+LINKS=""
+LINKS_=""
+
+ DL_DIR="/media/info/Junk" #Directory of downloaded files
+ DL_DIR_="/media/info/Junk/DL_DIR_" #Directory of downloaded files
+
+ [[ "$LINKS" ]] && /usr/bin/aria2c -d $DL_DIR -i - -c true &>>$LOG<<<"$LINKS" # || systemctl suspend
+ [[ "$LINKS_" ]] && yt-dlp --hls-prefer-native -f best --proxy socks5://127.0.0.1:1080/ -o "${DL_DIR_}/%(title)s.%(ext)s" --no-progress -a - &>>$LOG<<<"$LINKS_"
+}
+#clock-check
+if clock-check; then
+ update
+ $SCRIPT_NT_LOG && download
+ systemctl poweroff
+fi