From c95d67a449f17f79859bc32d8903a31139cb3c80 Mon Sep 17 00:00:00 2001 From: VR-25 <28943176+VR-25@users.noreply.github.com> Date: Mon, 23 Aug 2021 19:29:06 +0100 Subject: [PATCH] **v2021.8.23 (202108230)** - -L|--log [cmd] (default cmd: tail -F), djsd generates verbose (/dev/.vr25/djs/djsd.log). - General fixes - Major optimizations - Updated documentation: now with a table of contents and available in HTML format. --- META-INF/com/google/android/update-binary | 4 +- README.html | 218 ++++++++++++++++++++++ README.md | 51 +++-- customize.sh | 4 +- djs/djs-config.sh | 21 ++- djs/djs.sh | 44 +++-- install.sh | 4 +- module.prop | 4 +- 8 files changed, 309 insertions(+), 41 deletions(-) create mode 100644 README.html diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index 587516b..7988674 100644 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -263,7 +263,9 @@ echo " case $installDir in - /data/adb/*) echo " + /data/adb/modules*) + ;; + *) echo " (i) Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it." ;; esac diff --git a/README.html b/README.html new file mode 100644 index 0000000..6774b1c --- /dev/null +++ b/README.html @@ -0,0 +1,218 @@ + + + + + Daily Job Scheduler (DJS) + + + + + + + + + + + +

Daily Job Scheduler (DJS)

+ +
+

DESCRIPTION

+

DJS runs scripts and/or commands on boot or at set HH:MM (e.g, 23:59). +Any root solution is supported. +The installation is always "systemless", whether or not the system is rooted with Magisk.

+
+ +

Copyright (C) 2019-2021, VR25

+

This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version.

+

This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details.

+

You should have received a copy of the GNU General Public License +along with this program. If not, see https://www.gnu.org/licenses/.

+
+

DISCLAIMER

+

Always read/reread this reference prior to installing/upgrading this software.

+

While no cats have been harmed, the author assumes no responsibility for anything that might break due to the use/misuse of it.

+

To prevent fraud, do NOT mirror any link associated with this project; do NOT share builds (tarballs/zips)! Share official links instead.

+
+

WARNING

+

The author assumes no responsibility under anything that might break due to the use/misuse of this software. +By choosing to use/misuse it, you agree to do so at your own risk!

+
+

DONATIONS

+

Please, support the project with donations (links at the bottom). +As the project gets bigger and more popular, the need for coffee goes up as well.

+
+

PREREQUISITES

+ +

* A busybox binary can simply be placed in /data/adb/vr25/bin/. +Permissions (0700) are set automatically, as needed. +Precedence: /data/adb/vr25/bin/busybox > Magisk's busybox > system's busybox

+

Other executables or static binaries can also be placed in /data/adb/vr25/bin/ (with proper permissions) instead of being installed system-wide.

+
+

CONFIGURATION (/data/adb/vr25/djs-data/config.txt)

+
// This is a comment line + +// This is used to determine whether config should be patched. Do NOT modify! +versionCode=201908180 + +// Schedule Examples + +// Run on boot +// boot touch /data/I-was-born-on-boot; : --delete +// ": --delete" is optional; it means "delete the schedule after execution" - effectively turning it into a one-time boot schedule. + +// Apply Advanced Charging Controller night settings at 22:00 +//2200 acc 45 44 && acc --set applyOnPlug usb/current_max:500000 + +// Restore regular ACC settings at 6:00 (morning) +//0600 acc 80 70 && acc -s applyOnPlug 2000000; : --boot +// ": --boot" is optional; it lets this schedule run on boot as well (fail-safe). +
+
+

USAGE

+

If you feel uncomfortable with the command line, use a text editor to modify /data/adb/vr25/djs-data/config.txt. +Changes to this file take effect almost instantly, and without a daemon restart.

+

Terminal Commands

+
Config Management + +Usage: djsc|djs-config OPTION ARGS + +-a|--append 'LINE' + e.g., djsc -a 2200 reboot -p + +-d|--delete ['regex'] (deletes all matching lines) + e.g., djsc --delete 2200 + +-e|--edit [cmd] (fallback cmd: nano -l|vim|vi) + e.g., djs-config --edit vim + +-l|--list ['regex'] (fallback regex: ".", matches all lines) + e.g., djsc -l '^boot' + +-L|--log [cmd] (fallback cmd: tail -F) + e.g., djsc -L cat > /sdcard/djsd.log + + +Daemon Management + +Start/restart: djsd|djs-daemon +Stop: djs.|djs-stop +Status: djs,|djs-status + + +Print Version Code (integer) + +djsv +djs-version + + +Notes +- All commands return either 0 (success/running) or 1 (failure/stopped). +- djs-status prints the daemon's process ID (PID). +- Special shell characters (e.g., "|", ";", "&") must be quoted or escaped. For the sake of simplicity and consistency, single-quote all arguments as a whole (e.g., djsc -a '2200 reboot -p'). +- PATH starts with /data/adb/vr25/bin:/dev/.vr25/busybox. +This means schedules don't require additional busybox setup. +The first directory holds user executables. +
+
+

NOTES/TIPS FOR FRONT-END DEVELOPERS

+

Use /dev/.vr25/djs/* over regular commands. +These are guaranteed to be readily available after installation/initialization.

+

It may be best to use long options over short equivalents - e.g., /dev/.vr25/djs/djs-config --list, instead of /dev/.vr25/djs/djsc -l. +This makes code more readable (less cryptic).

+

Include provided descriptions of DJS features/settings in your app(s). +Provide additional information (trusted) where appropriate. +Explain settings/concepts as clearly and with as few words as possible.

+
+

FREQUENTLY ASKED QUESTIONS (FAQ)

+
+

How do I report issues?

+
+

Open issues on GitHub or contact the developer on Telegram/XDA (linked below). Always provide as much information as possible.

+
+

Where do I find daemon logs?

+
+

/dev/.vr25/djs/djsd.log

+
+ + +
+

LATEST CHANGES

+

v2021.8.2 (202108020)

+ +

v2021.8.9.1 (202108091)

+ +

v2021.8.23 (202108230)

+ + + + \ No newline at end of file diff --git a/README.md b/README.md index e61689a..a999fe0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,22 @@ # Daily Job Scheduler (DJS) + +- [DESCRIPTION](#description) +- [LEGAL](#legal) +- [DISCLAIMER](#disclaimer) +- [WARNING](#warning) +- [DONATIONS](#donations) +- [PREREQUISITES](#prerequisites) +- [CONFIGURATION (/data/adb/vr25/djs-data/config.txt)](#configuration-dataadbvr25djs-dataconfigtxt) +- [USAGE](#usage) + - [Terminal Commands](#terminal-commands) +- [NOTES/TIPS FOR FRONT-END DEVELOPERS](#notestips-for-front-end-developers) +- [FREQUENTLY ASKED QUESTIONS (FAQ)](#frequently-asked-questions-faq) +- [LINKS](#links) +- [LATEST CHANGES](#latest-changes) + + --- ## DESCRIPTION @@ -48,7 +64,7 @@ By choosing to use/misuse it, you agree to do so at your own risk! --- ## DONATIONS -Please, support the project with donations (`## LINKS` at the bottom). +Please, support the project with donations ([links](#links) at the bottom). As the project gets bigger and more popular, the need for coffee goes up as well. @@ -70,7 +86,7 @@ Other executables or static binaries can also be placed in /data/adb/vr25/bin/ ( --- -## CONFIGURATION (/data/adb/djs-data/config.txt) +## CONFIGURATION (/data/adb/vr25/djs-data/config.txt) ``` // This is a comment line @@ -96,7 +112,7 @@ versionCode=201908180 ## USAGE -If you feel uncomfortable with the command line, use a `text editor` to modify `/data/adb/djs-data/config.txt`. +If you feel uncomfortable with the command line, use a `text editor` to modify `/data/adb/vr25/djs-data/config.txt`. Changes to this file take effect almost instantly, and without a [daemon](https://en.wikipedia.org/wiki/Daemon_(computing)) restart. @@ -110,15 +126,18 @@ Usage: djsc|djs-config OPTION ARGS -a|--append 'LINE' e.g., djsc -a 2200 reboot -p --d|--delete 'PATTERN' (all matching lines) +-d|--delete ['regex'] (deletes all matching lines) e.g., djsc --delete 2200 --e|--edit EDITOR OPTS (fallback: nano -l|vim|vi) +-e|--edit [cmd] (fallback cmd: nano -l|vim|vi) e.g., djs-config --edit vim --l|--list 'PATTERN' (default ".", meaning "all lines") +-l|--list ['regex'] (fallback regex: ".", matches all lines) e.g., djsc -l '^boot' +-L|--log [cmd] (fallback cmd: tail -F) + e.g., djsc -L cat > /sdcard/djsd.log + Daemon Management @@ -165,6 +184,11 @@ Explain settings/concepts as clearly and with as few words as possible. Open issues on GitHub or contact the developer on Telegram/XDA (linked below). Always provide as much information as possible. +> Where do I find daemon logs? + +`/dev/.vr25/djs/djsd.log` + + --- ## LINKS @@ -181,13 +205,6 @@ Open issues on GitHub or contact the developer on Telegram/XDA (linked below). A ## LATEST CHANGES -**v2021.7.28 (202107280)** - -- Fixed issues. -- Major refactoring -- Updated framework and documentation. - - **v2021.8.2 (202108020)** - Fixed AccA related issues. @@ -197,3 +214,11 @@ Open issues on GitHub or contact the developer on Telegram/XDA (linked below). A - Rewritten daemon logic for better efficiency and reliability. - Updated documentation + + +**v2021.8.23 (202108230)** + +- -L|--log [cmd] (default cmd: tail -F), djsd generates verbose (/dev/.vr25/djs/djsd.log). +- General fixes +- Major optimizations +- Updated documentation: now with a table of contents and available in HTML format. diff --git a/customize.sh b/customize.sh index 587516b..7988674 100644 --- a/customize.sh +++ b/customize.sh @@ -263,7 +263,9 @@ echo " case $installDir in - /data/adb/*) echo " + /data/adb/modules*) + ;; + *) echo " (i) Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it." ;; esac diff --git a/djs/djs-config.sh b/djs/djs-config.sh index e54914b..cedf0cf 100644 --- a/djs/djs-config.sh +++ b/djs/djs-config.sh @@ -40,6 +40,18 @@ if [ -f $config ]; then echo grep -E "${*:-.}" $config | grep -v '^$' ;; + + -L|--log) + shift + echo + log=/dev/.vr25/djs/djsd.log + if [ -z "${1-}" ]; then + tail -F $log + else + eval "$@ $log" + fi + echo + ;; *) cat << CAT @@ -50,15 +62,18 @@ Usage: djsc|djs-config OPTION ARGS -a|--append 'LINE' e.g., djsc -a 2200 reboot -p --d|--delete 'PATTERN' (all matching lines) +-d|--delete ['regex'] (deletes all matching lines) e.g., djsc --delete 2200 --e|--edit EDITOR OPTS (fallback: nano -l|vim|vi) +-e|--edit [cmd] (fallback cmd: nano -l|vim|vi) e.g., djs-config --edit vim --l|--list 'PATTERN' (default ".", meaning "all lines") +-l|--list ['regex'] (fallback regex: ".", matches "all lines") e.g., djsc -l '^boot' +-L|--log [cmd] (fallback cmd: tail -F) + e.g., djsc -L cat > /sdcard/djsd.log + Note: PATH starts with /data/adb/vr25/bin:/dev/.vr25/busybox. This means schedules don't require additional busybox setup. The first directory holds user executables. diff --git a/djs/djs.sh b/djs/djs.sh index 7de2de1..4cf54c5 100644 --- a/djs/djs.sh +++ b/djs/djs.sh @@ -3,15 +3,19 @@ # Copyright (C) 2019-2021, VR25 # License: GPLv3+ - -exec > /dev/null 2>&1 - -set -u tmpDir=/dev/.vr25/djs +log=$tmpDir/djsd.log execDir=/data/adb/vr25/djs config=${execDir}-data/config.txt getv() { grep -E "$1" $config 2>/dev/null; } +# verbose +[ -z "$LINENO" ] || export PS4='$LINENO: ' +echo "###$(date)###" >> $log +echo "versionCode=$(sed -n s/versionCode=//p $execDir/module.prop 2>/dev/null)" >> $log +exec >> $log 2>&1 +set -x + [ -f $execDir/disable ] && exit 0 . $execDir/setup-busybox.sh pgrep -f /djs.sh | sed s/$$// | xargs kill -9 2>/dev/null @@ -19,7 +23,7 @@ mkdir -p $tmpDir if [ ! -f $config ]; then mkdir -p ${config%/*} - cp $execDir/default-config.txt $config + cat $execDir/default-config.txt > $config fi @@ -71,30 +75,30 @@ ln -sf $execDir/djs-version.sh /dev/djs-version # boot schedules -if [ ! -f $tmpDir/boot.sh ]; then - echo "#!/system/bin/sh" > $tmpDir/boot.sh - grep '^boot | : --boot' $config | sed 's/^.... //' >> $tmpDir/boot.sh - echo 'exit $?' >> $tmpDir/boot.sh - chmod u+x $tmpDir/boot.sh - start-stop-daemon -bx $tmpDir/boot.sh -S -- +if [ ! -f $tmpDir/djsd-boot.sh ]; then + echo "#!/system/bin/sh" > $tmpDir/djsd-boot.sh + grep '^boot | : --boot' $config | sed 's/^.... //' >> $tmpDir/djsd-boot.sh + echo 'exit $?' >> $tmpDir/djsd-boot.sh + chmod u+x $tmpDir/djsd-boot.sh + start-stop-daemon -bx $tmpDir/djsd-boot.sh -S -- grep -q '^boot .* : --delete' $config && sed -i '/^boot .* : --delete/d' $config fi # HH:MM schedules while :; do time=$(date +%H%M) - echo "#!/system/bin/sh" > $tmpDir/${time}.sh - if grep "^$time " $config | sed 's/^.... //' >> $tmpDir/${time}.sh; then - echo 'rm $0' >> $tmpDir/${time}.sh - echo 'exit $?' >> $tmpDir/${time}.sh - chmod u+x $tmpDir/${time}.sh - grep -q ' : --delete' $tmpDir/${time}.sh && sed -i "/^$time .* : --delete/d" $config - start-stop-daemon -bx $tmpDir/${time}.sh -S -- + script=$tmpDir/djsd-${time}.sh + if [ ! -f $script ] && grep -q "^$time " $config; then + sed -n "s|^$time |#!/system/bin/sh\n|p" $config > $script + echo 'rm $0; exit $?' >> $script + chmod u+x $script + grep -q ' : --delete' $script && sed -i "/^$time .* : --delete/d" $config + start-stop-daemon -bx $script -S -- fi - sleep 40 while [ $(date +%H%M) -eq $time ]; do - sleep 10 + sleep 20 done + [ $(du -k $log | cut -f1) -ge 8 ] && : > $log done exit $? diff --git a/install.sh b/install.sh index 587516b..7988674 100644 --- a/install.sh +++ b/install.sh @@ -263,7 +263,9 @@ echo " case $installDir in - /data/adb/*) echo " + /data/adb/modules*) + ;; + *) echo " (i) Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it." ;; esac diff --git a/module.prop b/module.prop index 3032c3f..00c89d5 100644 --- a/module.prop +++ b/module.prop @@ -1,6 +1,6 @@ id=djs name=Daily Job Scheduler (DJS) -version=v2021.8.9.1 -versionCode=202108091 +version=v2021.8.23 +versionCode=202108230 author=VR25 description=Runs commands and scripts on boot and at HH:MM. Any root solution is supported. The installation is always "system-less", whether or not the system is rooted with Magisk.