Skip to content

Commit

Permalink
scripts/bindhosts: expose custom_cron
Browse files Browse the repository at this point in the history
  • Loading branch information
backslashxx committed Dec 16, 2024
1 parent 4b8e64d commit 812522f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion module/bindhosts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ show_help () {
echo "usage:"
printf " --force-update \tforce an update\n"
printf " --force-reset \t\tforce a reset\n"
printf " --custom-cron \t\tcustom schedule, syntax: \"0 2 * * *\" \n"
printf "\t\t\tif you do NOT know this, use --enable-cron\n"
printf " --enable-cron \t\tenables scheduled updates (4AM daily)\n"
printf " --disable-cron \tdisables scheduled updates\n"
printf " --help \t\tdisplays this message\n"
}

run_crond() {
[ ! -d $PERSISTENT_DIR/crontabs ] && {
mkdir $PERSISTENT_DIR/crontabs
Expand All @@ -88,11 +91,30 @@ run_crond() {
}
}

custom_cron() {
shift
# todo: think of a way to sanitize input
# this atleast will catch globbed
if [ -z "$1" ] || [ ! -z "$2" ]; then
# shoutout to native test and holmes
echo "[!] futile cronjob"
echo "[!] syntax: --custom-cron \"0 2 * * *\" "
exit 0
fi
# run crond
run_crond
# add entry
echo "$1 sh $MODDIR/bindhosts.sh --force-update > $rwdir/bindhosts_cron.log 2>&1 &" | busybox crontab -c $PERSISTENT_DIR/crontabs -
echo "[>] $(head -n1 $PERSISTENT_DIR/crontabs/root) "
echo "[!] make sure entry is correct!"
echo "[+] crontab entry added!"
}

enable_cron() {
# run crond
run_crond
# add entry
echo "0 4 * * * sh /data/adb/modules/bindhosts/bindhosts.sh --force-update > $rwdir/bindhosts_cron.log 2>&1 &" | busybox crontab -c $PERSISTENT_DIR/crontabs -
echo "0 4 * * * sh $MODDIR/bindhosts.sh --force-update > $rwdir/bindhosts_cron.log 2>&1 &" | busybox crontab -c $PERSISTENT_DIR/crontabs -
echo "[>] $(head -n1 $PERSISTENT_DIR/crontabs/root) "
echo "[+] crontab entry added!"
}
Expand Down Expand Up @@ -229,6 +251,7 @@ pm path org.adaway > /dev/null 2>&1 && grep -q "generated by AdAway" /system/etc
case "$1" in
--force-update) run; exit ;;
--force-reset) reset; exit ;;
--custom-cron) custom_cron "$@"; exit ;;
--enable-cron) enable_cron; exit ;;
--disable-cron) disable_cron; exit ;;
--toggle-updatejson) toggle_updatejson; exit ;;
Expand Down

0 comments on commit 812522f

Please sign in to comment.