From fe5213e5423d9ef57746205aaa2ae1aa2162c1cc Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Sat, 3 Jan 2026 23:46:09 -0800 Subject: [PATCH 01/12] Improvements and Fine-Tuning - Added 3-hour and 4-hour intervals for the logrotate cron job options. - Increased the log FIFO queue for number of messages to 1024. - Miscellaneous code improvements. --- README.md | 4 +- init.d/rc.func.syslog-ng | 38 ++++--- scribe.sh | 155 ++++++++++++++++++-------- syslog-ng.share/syslog-ng.conf-scribe | 4 +- 4 files changed, 134 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 74c5563..64ccf4e 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ **scribe** is a **syslog-ng** and **logrotate** installer for ASUS routers running **Asuswrt-Merlin** -## v3.2.6 -### Updated on 2025-Dec-22 +## v3.2.7 +### Updated on 2026-Jan-03 ## Getting Started diff --git a/init.d/rc.func.syslog-ng b/init.d/rc.func.syslog-ng index 53ebbcb..966b62a 100644 --- a/init.d/rc.func.syslog-ng +++ b/init.d/rc.func.syslog-ng @@ -1,8 +1,8 @@ #!/bin/sh - # # NB: rc.func only runs PRECMD on "start" -# Last Modified: 2025-Nov-23 -# VERSION="3.1.2" +# Last Modified: 2026-Jan-02 +# VERSION="3.1.3" #------------------------------------------- ## Run the F/W built-in native commands ## @@ -14,9 +14,10 @@ pidofCmd="$(which -a pidof | grep -v '^/opt/')" loggerCmd="$(which -a logger | grep -v '^/opt/')" logTagStr="Scribe:kill_logger[$$]" logPrioNum="-p 4" +prevSysLog_Loc="" ##----------------------------------------## -## Modified by Martinski W. [2025-Nov-21] ## +## Modified by Martinski W. [2026-Jan-02] ## ##----------------------------------------## kill_logger() { @@ -31,9 +32,10 @@ kill_logger() then postLogMsgs=true else postLogMsgs=false fi + prevSysLog_Loc="$syslog_loc" # figure out where syslogd expects log file to live # - if [ -z "$syslog_loc" ] # don't look for config file if $syslog_loc is defined # + if [ -z "$syslog_loc" ] # do NOT look for config file if $syslog_loc is defined # then if [ -s "$script_conf" ] && $grepCmd -q "^SYSLOG_LOC=" "$script_conf" then @@ -63,6 +65,22 @@ kill_logger() [ "$syslog_loc" = "$jffslog" ] && isjffs=true + # touch 'logrotate.status' if it doesn't exist so syslog-ng doesn't whine # + [ ! -f /var/lib/logrotate.status ] && touch /var/lib/logrotate.status + + ##----------------------------------------## + ## Modified by Martinski W. [2025-Jun-16] ## + ##----------------------------------------## + # Set correct permissions to avoid "world-readable" status # + chmod 600 /var/lib/logrotate.status + + # export timezone if not already set # + [ -z "${TZ:+xSETx}" ] && export TZ="$(/bin/cat /etc/TZ)" + + if [ "$prevSysLog_Loc" = "$syslog_loc" ] && ! "$postLogMsgs" + then return 0 + fi + # kill any/all running klogd and/or syslogd # count=30 klgk=false @@ -116,18 +134,6 @@ kill_logger() # create /opt/var/run/syslog-ng/ directory if it doesn't exist # # not needed for older versions of syslog-ng, but doesn't hurt anything # [ ! -d "/opt/var/run/syslog-ng" ] && mkdir "/opt/var/run/syslog-ng" - - # touch 'logrotate.status' if it doesn't exist so syslog-ng doesn't whine # - [ ! -f /var/lib/logrotate.status ] && touch /var/lib/logrotate.status - - ##----------------------------------------## - ## Modified by Martinski W. [2025-Jun-16] ## - ##----------------------------------------## - # Set correct permissions to avoid "world-readable" status # - chmod 600 /var/lib/logrotate.status - - # export timezone if not already set # - [ -z "${TZ:+xSETx}" ] && export TZ="$(/bin/cat /etc/TZ)" } PRECMD="kill_logger" diff --git a/scribe.sh b/scribe.sh index 026ae5e..31bbbc5 100644 --- a/scribe.sh +++ b/scribe.sh @@ -18,7 +18,7 @@ # curl --retry 3 "https://raw.githubusercontent.com/AMTM-OSR/scribe/master/scribe.h" -o "/jffs/scripts/scribe" && chmod 0755 /jffs/scripts/scribe && /jffs/scripts/scribe install # ################################################################## -# Last Modified: 2025-Dec-21 +# Last Modified: 2026-Jan-03 #----------------------------------------------------------------- ################ Shellcheck directives ################ @@ -33,6 +33,12 @@ # shellcheck disable=SC3045 ################################################################# +readonly script_name="scribe" +readonly scribe_ver="v3.2.7" +readonly scriptVer_TAG="26010323" +scribe_branch="develop" +script_branch="$scribe_branch" + # Ensure firmware binaries are used, not Entware # export PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH" @@ -70,15 +76,9 @@ done [ "$action" = "X" ] && action="menu" # scribe constants # -readonly script_name="scribe" -scribe_branch="develop" -script_branch="$scribe_branch" -# Version number for amtm compatibility # -readonly scribe_ver="v3.2.6" # Version 'vX.Y_Z' format because I'm stubborn # script_ver="$( echo "$scribe_ver" | sed 's/\./_/2' )" readonly script_ver -readonly scriptVer_TAG="25122122" readonly scriptVer_long="$scribe_ver ($scribe_branch)" readonly script_author="AMTM-OSR" readonly raw_git="https://raw.githubusercontent.com" @@ -186,6 +186,20 @@ readonly LR_FLock_FName="/tmp/scribeLogRotate.flock" readonly logFilesRegExp="${optVarLogDir}/.*([.]log)?" readonly filteredLogList="${config_d}/.filteredlogs" readonly noConfigLogList="${config_d}/.noconfiglogs" +readonly sysLogMsgSizeMAX=10240 +readonly sysLogFiFoSizeMIN=1024 + +# color constants # +readonly red="\033[1;31m" +readonly green="\033[1;32m" +readonly yellow="\033[1;33m" +readonly blue="\033[1;34m" +readonly magenta="\033[1;35m" +readonly cyan="\033[1;36m" +readonly white="\033[1;37m" +readonly std="\e[0m" +readonly CLRD="\e[0m" +readonly BOLD="\e[1m" ##-------------------------------------## ## Added by Martinski W. [2025-Nov-29] ## @@ -195,8 +209,8 @@ readonly twoMByte=2097152 readonly LR_CronJobMins=5 readonly LR_CronJobHour=0 readonly LR_CronTagStr="scribeLogRotate" -readonly validHourRegExp="(6|8|12|24)" -readonly validHourLstStr="6, 8, 12, or 24." +readonly validHourRegExp="(3|4|6|8|12|24)" +readonly validHourLstStr="3, 4, 6, 8, 12, 24." ##----------------------------------------## ## Modified by Martinski W. [2025-Jul-07] ## @@ -209,18 +223,6 @@ readonly uiscribeRepo="$raw_git/$uiscribeAuthor/$uiscribeName/$uiscribeBranch/${ readonly uiscribePath="$script_d/$uiscribeName" readonly uiscribeVerRegExp="v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})" -# color constants # -readonly red="\033[1;31m" -readonly green="\033[1;32m" -readonly yellow="\033[1;33m" -readonly blue="\033[1;34m" -readonly magenta="\033[1;35m" -readonly cyan="\033[1;36m" -readonly white="\033[1;37m" -readonly std="\e[0m" -readonly CLRD="\e[0m" -readonly BOLD="\e[1m" - readonly header="=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=${std}\n\n" # check if Scribe is already installed by looking for link in /opt/bin # @@ -258,7 +260,7 @@ finished(){ printf "$green done. $std\n"; } not_installed(){ printf "\n$blue %s$red NOT$white installed! $std\n" "$1"; } PressEnterTo() -{ printf "$white Press key to %s: $std" "$1"; read -rs inputKey; echo; } +{ printf "$white Press key to %s $std" "$1"; read -rs inputKey; echo; } VersionStrToNum() { echo "$1" | sed 's/v//; s/_/./' | awk -F. '{ printf("%d%03d%02d\n", $1, $2, $3); }'; } @@ -506,7 +508,7 @@ update_file() if [ $# -gt 2 ] && [ "$3" = "backup" ] then date_stamp "$2" fi - cp -pf "$1" "$2" + cp -fp "$1" "$2" } # Check Yes or No # @@ -567,7 +569,7 @@ ScriptLogo() printf " (____/\`\\____)(_) (_)(_,__/'\`\\____) \n" printf " %s and %s installation $std\n" "$sng" "$lr" printf "%*s${green}%s${std} ${colorCT}%s${std}\n" "$spaceLenX" '' "$scribe_ver" "$branchxStr_TAG" - printf " ${blue}https://github.com/AMTM-OSR/scribe${std}\n" + printf " ${blue}https://github.com/AMTM-OSR/scribe${std}\n" printf " ${blue}Original author: cmkelley${std}\n\n" } @@ -850,6 +852,9 @@ _Get_LogRotate_CronHour_() menu_LogRotate_CronJob_Time() { local cronHourNum cronHourStr hourInput validInput + local GRNct="\\\e[1;32m" CLRct="\\\e[0m" validHoursStr + + validHoursStr="$(echo "$validHourLstStr" | sed -E "s/([1-9]+)/${GRNct}\1${CLRct}/g")" validInput=false while true @@ -860,7 +865,7 @@ menu_LogRotate_CronJob_Time() printf " ${BOLD}Current $lr cron job interval: " printf "${green}Every ${cronHourNum} hours${CLRD}\n" printf "\n ${BOLD}Please enter how often in HOURS to run the cron job." - printf "\n Every N hours, where N is ${green}${validHourLstStr}${CLRD} " + printf "\n Valid values are $validHoursStr " printf "(${green}e${CLRD}=Exit): " read -r hourInput @@ -870,9 +875,8 @@ menu_LogRotate_CronJob_Time() elif [ -z "$hourInput" ] || \ ! echo "$hourInput" | grep -qE "^${validHourRegExp}$" then - printf "\n ${red}Please enter a valid number:${CLRD} " - printf "${green}${validHourLstStr}${CLRD}\n\n" - PressEnterTo "continue" + printf "\n ${red}Please enter a valid number:${CLRD} ${validHoursStr}\n\n" + PressEnterTo "continue..." elif [ "$hourInput" -eq 24 ] then validInput=true @@ -934,18 +938,73 @@ dir_links() fi } +##-------------------------------------## +## Added by Martinski W. [2026-Jan-03] ## +##-------------------------------------## +_SysLogMsgSizeFromConfig_() +{ + if [ $# -eq 0 ] || [ -z "$1" ] + then return 1 + fi + local msgSizeNum msgSizeOK=true + + msgSizeNum="$(grep -m1 'log_msg_size(' "$sng_conf" | cut -d ';' -f1 | grep -oE '[0-9]+')" + if [ -n "$msgSizeNum" ] && [ "$msgSizeNum" -gt "$sysLogMsgSizeMAX" ] + then msgSizeOK=false + fi + "$msgSizeOK" && return 0 + + if [ "$1" = "check" ] + then return 1 + elif [ "$1" = "update" ] + then + sed -i "s/log_msg_size($msgSizeNum)/log_msg_size($sysLogMsgSizeMAX)/g" "$sng_conf" + return 0 + fi +} + +##-------------------------------------## +## Added by Martinski W. [2026-Jan-03] ## +##-------------------------------------## +_SysLogFiFoSizeFromConfig_() +{ + if [ $# -eq 0 ] || [ -z "$1" ] + then return 1 + fi + local fifoSizeNum fifoSizeOK=true + + fifoSizeNum="$(grep -m1 'log_fifo_size(' "$sng_conf" | cut -d ';' -f1 | grep -oE '[0-9]+')" + if [ -n "$fifoSizeNum" ] && [ "$fifoSizeNum" -lt "$sysLogFiFoSizeMIN" ] + then fifoSizeOK=false + fi + "$fifoSizeOK" && return 0 + + if [ "$1" = "check" ] + then return 1 + elif [ "$1" = "update" ] + then + sed -i "s/log_fifo_size($fifoSizeNum)/log_fifo_size($sysLogFiFoSizeMIN)/g" "$sng_conf" + return 0 + fi +} + ##----------------------------------------## -## Modified by Martinski W. [2024-Aug-25] ## +## Modified by Martinski W. [2026-Jan-03] ## ##----------------------------------------## sync_conf() { + local sng_conf_vtag1 sng_conf_vtag2 sng_version_str sng_conf_verstr + printf "$white %34s" "$( strip_path "$sng_conf" ) version check ..." sng_conf_vtag1="@version:" sng_conf_vtag2="${sng_conf_vtag1}[[:blank:]]*" sng_version_str="$( $sng --version | grep -m1 "$sng" | grep -oE '[0-9]{1,2}([_.][0-9]{1,2})' )" - sng_conf_verstr="$( grep -Em1 "$sng_conf_vtag2" "$sng_conf" | grep -oE '[0-9]{1,2}([_.][0-9]{1,2})' )" + sng_conf_verstr="$( grep -Em1 "^$sng_conf_vtag2" "$sng_conf" | grep -oE '[0-9]{1,2}([_.][0-9]{1,2})' )" - if [ "$sng_version_str" != "$sng_conf_verstr" ] || grep -q 'stats_freq(' "$sng_conf" + if grep -q 'stats_freq(' "$sng_conf" || \ + ! _SysLogMsgSizeFromConfig_ check || \ + ! _SysLogFiFoSizeFromConfig_ check || \ + [ "$sng_version_str" != "$sng_conf_verstr" ] then printf "$red out of sync! (%s) $std\n" "$sng_conf_verstr" printf "$cyan *** Updating %s and restarting %s *** $std\n" "$( strip_path "$sng_conf" )" "$sng" @@ -953,12 +1012,14 @@ sync_conf() old_doc="doc\/syslog-ng-open" new_doc="list\/syslog-ng-open-source-edition" sed -i "s/$old_doc.*/$new_doc/" "$sng_conf" - stats_freq="$( grep -m1 'stats_freq(' $sng_conf | cut -d ';' -f 1 | grep -oE '[0-9]*' )" + stats_freq="$( grep -m1 'stats_freq(' "$sng_conf" | cut -d ';' -f 1 | grep -oE '[0-9]*' )" [ -n "$stats_freq" ] && sed -i "s/stats_freq($stats_freq)/stats(freq($stats_freq))/g" "$sng_conf" if [ -n "$sng_version_str" ] && [ -n "$sng_conf_verstr" ] then sed -i "s/^${sng_conf_vtag2}${sng_conf_verstr}.*/$sng_conf_vtag1 $sng_version_str/" "$sng_conf" fi + _SysLogMsgSizeFromConfig_ update + _SysLogFiFoSizeFromConfig_ update $S01sng_init start Hup_uiScribe printf "$white %34s" "$( strip_path "$sng_conf" ) version ..." @@ -1068,7 +1129,7 @@ setup_exmpls() dlt "$conf_opkg" elif [ ! -e "$share/examples/$opkg" ] then - cp -pf "$conf" "$share/examples/$opkg" + cp -fp "$conf" "$share/examples/$opkg" if [ "$1" = "$sng" ] then printf "\n$white NOTE: The %s file provided by the Entware %s package sources a very\n" "$( strip_path "$conf" )" "$sng" @@ -1343,25 +1404,25 @@ sng_ver_chk() fi } -setup_sng() +Setup_SysLogNG() { printf "\n$magenta setting up %s ...\n$std" "$sng" copy_rcfunc sed_sng sed_srvcEvent sed_unMount - if [ "$( md5_file "$sng_share/examples/$sng.conf-scribe" )" != "$( md5_file "$sng_conf" )" ] + if [ "$( md5_file "$sng_share/examples/${sng}.conf-scribe" )" != "$( md5_file "$sng_conf" )" ] then - printf "$white %34s" "updating $( strip_path $sng_conf ) ..." - update_file $sng_share/examples/$sng.conf-scribe $sng_conf "backup" + printf "$white %34s" "updating $( strip_path "$sng_conf" ) ..." + update_file "$sng_share/examples/${sng}.conf-scribe" "$sng_conf" "backup" finished fi sync_conf } -setup_lr() +Setup_LogRotate() { - # assumes since entware is required / installed, post-mount exists and is properly executable + # Assumes since Entware is required/installed, post-mount exists and is properly executable # printf "\n$magenta setting up %s ...\n" "$lr" LogRotate_CronJob_PostMount_Check LogRotate_CronJob_Check @@ -1381,8 +1442,8 @@ doInstall() [ "$1" = "$sng" ] && sng_ver_chk setup_ddir "$1" "ALL" setup_exmpls "$1" "ALL" - [ "$1" = "$sng" ] && setup_sng - [ "$1" = "$lr" ] && setup_lr + [ "$1" = "$sng" ] && Setup_SysLogNG + [ "$1" = "$lr" ] && Setup_LogRotate } ##----------------------------------------## @@ -1566,7 +1627,7 @@ menu_install() rld_sngconf printf "\n$white %s setup complete!\n\n" "$script_name" - PressEnterTo "continue" + PressEnterTo "continue..." if ! "$uiScribeInstalled" then Install_uiScribe fi @@ -1684,7 +1745,7 @@ doUninstall() printf "\n$white %s, %s, and %s have been removed from the system.\n" "$sng" "$lr" "$script_name" printf " It is recommended to reboot the router at this time. If you do not\n" printf " wish to reboot the router, press ${blue}${std} now to exit.\n\n" - PressEnterTo "reboot" + PressEnterTo "reboot:" service reboot; exit 0 fi } @@ -1855,7 +1916,7 @@ menu_forgrnd() printf "\n$yellow NOTE: If there are no errors, debugging mode will\n" printf " continue indefinitely. If this happens, type\n" printf " to halt debugging mode output.\n\n" - PressEnterTo "start" + PressEnterTo "start:" if "$restrt" then $S01sng_init stop; echo fi @@ -2325,7 +2386,7 @@ scribe_menu() printf "\n${red} Please choose a valid option.${std}\n\n" fi if "$pause" - then PressEnterTo "continue" + then PressEnterTo "continue..." fi if "$run_scribe" then sh "$script_loc" ; exit 0 @@ -2501,8 +2562,8 @@ case "$action" in lastTimeSecs="$(_ServiceEventTime_ check)" thisTimeDiff="$(echo "$currTimeSecs $lastTimeSecs" | awk -F ' ' '{printf("%s", $1 - $2);}')" - #Only once every 10 minutes at most# - if [ "$thisTimeDiff" -ge 600 ] + #Only once every 15 minutes at most# + if [ "$thisTimeDiff" -ge 900 ] then _ServiceEventTime_ update "$currTimeSecs" . "$rcfunc_loc" diff --git a/syslog-ng.share/syslog-ng.conf-scribe b/syslog-ng.share/syslog-ng.conf-scribe index bd5fc94..f3c2fa9 100644 --- a/syslog-ng.share/syslog-ng.conf-scribe +++ b/syslog-ng.share/syslog-ng.conf-scribe @@ -14,8 +14,8 @@ options { chain_hostnames(no); # Enable or disable the chained hostname format. create_dirs(yes); keep_hostname(yes); # Enable or disable hostname rewriting. - log_fifo_size(256); # The number of messages that the output queue can store. - log_msg_size(16384); # Maximum length of a message in bytes. + log_fifo_size(1024); # The number of messages that the output queue can store. + log_msg_size(10240); # Maximum length of a message in bytes. stats(freq(21600)); # The period between two STATS messages sent by syslog-ng, containing statistics about dropped logs in seconds; 0 disables. (21,600 seconds = 6 hours) flush_lines(0); # How many lines are flushed to a destination at a time. use_fqdn(no); # Add Fully Qualified Domain Name instead of short hostname. From 8c1306b7e527c1a091d7cc01d2823e28fa21d47d Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Sun, 4 Jan 2026 01:02:20 -0800 Subject: [PATCH 02/12] Improvements and Fine-Tuning - Increased the log FIFO queue for number of messages based on total RAM size. --- README.md | 2 +- scribe.sh | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 64ccf4e..4b79d32 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **scribe** is a **syslog-ng** and **logrotate** installer for ASUS routers running **Asuswrt-Merlin** ## v3.2.7 -### Updated on 2026-Jan-03 +### Updated on 2026-Jan-04 ## Getting Started diff --git a/scribe.sh b/scribe.sh index 31bbbc5..1b2c869 100644 --- a/scribe.sh +++ b/scribe.sh @@ -18,7 +18,7 @@ # curl --retry 3 "https://raw.githubusercontent.com/AMTM-OSR/scribe/master/scribe.h" -o "/jffs/scripts/scribe" && chmod 0755 /jffs/scripts/scribe && /jffs/scripts/scribe install # ################################################################## -# Last Modified: 2026-Jan-03 +# Last Modified: 2026-Jan-04 #----------------------------------------------------------------- ################ Shellcheck directives ################ @@ -35,7 +35,7 @@ readonly script_name="scribe" readonly scribe_ver="v3.2.7" -readonly scriptVer_TAG="26010323" +readonly scriptVer_TAG="26010400" scribe_branch="develop" script_branch="$scribe_branch" @@ -186,8 +186,8 @@ readonly LR_FLock_FName="/tmp/scribeLogRotate.flock" readonly logFilesRegExp="${optVarLogDir}/.*([.]log)?" readonly filteredLogList="${config_d}/.filteredlogs" readonly noConfigLogList="${config_d}/.noconfiglogs" -readonly sysLogMsgSizeMAX=10240 -readonly sysLogFiFoSizeMIN=1024 +sysLogMsgSizeMAX=10240 +sysLogFiFoSizeMIN=1024 # color constants # readonly red="\033[1;31m" @@ -1195,6 +1195,19 @@ _AcquireFLock_() _ReleaseFLock_() { flock -u "$LR_FLock_FD" ; } +##-------------------------------------## +## Added by Martinski W. [2026-Jan-04] ## +##-------------------------------------## +_HasRouterMoreThan512MBtotalRAM_() +{ + local totalRAM_KB + totalRAM_KB="$(awk -F ' ' '/^MemTotal:/{print $2}' /proc/meminfo)" + if [ -n "$totalRAM_KB" ] && [ "$totalRAM_KB" -gt 524288 ] + then return 0 + else return 1 + fi +} + ##-------------------------------------## ## Added by Martinski W. [2025-Dec-05] ## ##-------------------------------------## @@ -2400,6 +2413,12 @@ scribe_menu() SetUpRepoBranchVars +## Increase FIFO queue size if 1GB RAM or more ## +if _HasRouterMoreThan512MBtotalRAM_ +then sysLogFiFoSizeMIN=2048 +else sysLogFiFoSizeMIN=1024 +fi + if ! SyslogDm_Running && ! SyslogNg_Running then printf "\n\n${red} *WARNING*: $white No system logger was running!!\n" From 7ddf468860bb6857af00aa299c5a157f4e3366ff Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Sun, 4 Jan 2026 02:09:17 -0800 Subject: [PATCH 03/12] Improvements and Fine-Tuning Show the full log file when running logrotate in debug mode. --- scribe.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scribe.sh b/scribe.sh index 1b2c869..86c4c23 100644 --- a/scribe.sh +++ b/scribe.sh @@ -35,7 +35,7 @@ readonly script_name="scribe" readonly scribe_ver="v3.2.7" -readonly scriptVer_TAG="26010400" +readonly scriptVer_TAG="26010401" scribe_branch="develop" script_branch="$scribe_branch" @@ -2337,9 +2337,9 @@ scribe_menu() then _DoRotateLogFiles_ DEBUG TEMP _ReleaseFLock_ - less "$lr_temp" - dlt "$lr_temp" + more "$lr_temp" ; echo pause=false + PressEnterTo "continue..." else printf "\n${red} Unable to acquire lock to run logrotate.${std}\n" printf "\n${red} The program may be currently running.${std}\n\n" From abe71a2818da3e202c32b2d395fa1e7abe01ceca Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Sun, 4 Jan 2026 22:58:18 -0800 Subject: [PATCH 04/12] More Improvements and Fine-Tuning - Decreased the log message size to 2048 (from original 16384). - Increased the log FIFO queue for number of messages to 1024 (2048 if total RAM > 512MB). - Changes in the CLI menu display. - Miscellaneous code improvements. --- init.d/rc.func.syslog-ng | 7 - scribe.sh | 179 ++++++++++++++------------ syslog-ng.share/syslog-ng.conf-scribe | 2 +- 3 files changed, 97 insertions(+), 91 deletions(-) diff --git a/init.d/rc.func.syslog-ng b/init.d/rc.func.syslog-ng index 966b62a..894268f 100644 --- a/init.d/rc.func.syslog-ng +++ b/init.d/rc.func.syslog-ng @@ -124,13 +124,6 @@ kill_logger() [ ! -L "$tmplog-1" ] && /bin/ln -s "${syslog_loc}-1" "${tmplog}-1" fi - if "$postLogMsgs" - then - $loggerCmd -t "$logTagStr" $logPrioNum "optmsg=[$(ls -ld "$optmsg")]" - $loggerCmd -t "$logTagStr" $logPrioNum "syslog_loc=[$(ls -ld "$syslog_loc")]" - $loggerCmd -t "$logTagStr" $logPrioNum "script_conf=[$(ls -ld "$script_conf")]" - fi - # create /opt/var/run/syslog-ng/ directory if it doesn't exist # # not needed for older versions of syslog-ng, but doesn't hurt anything # [ ! -d "/opt/var/run/syslog-ng" ] && mkdir "/opt/var/run/syslog-ng" diff --git a/scribe.sh b/scribe.sh index 86c4c23..2a95d0f 100644 --- a/scribe.sh +++ b/scribe.sh @@ -35,7 +35,7 @@ readonly script_name="scribe" readonly scribe_ver="v3.2.7" -readonly scriptVer_TAG="26010401" +readonly scriptVer_TAG="26010422" scribe_branch="develop" script_branch="$scribe_branch" @@ -45,7 +45,7 @@ export PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH" # set TMP if not set # [ -z "${TMP:+xSETx}" ] && export TMP=/opt/tmp -# parse parameters +# parse parameters # action="X" got_zip=false banner=true @@ -91,6 +91,7 @@ readonly script_conf="${config_d}/config" readonly optmsg="/opt/var/log/messages" readonly jffslog="/jffs/syslog.log" readonly tmplog="/tmp/syslog.log" +syslog_loc="" export optmsg export tmplog export jffslog @@ -186,7 +187,7 @@ readonly LR_FLock_FName="/tmp/scribeLogRotate.flock" readonly logFilesRegExp="${optVarLogDir}/.*([.]log)?" readonly filteredLogList="${config_d}/.filteredlogs" readonly noConfigLogList="${config_d}/.noconfiglogs" -sysLogMsgSizeMAX=10240 +sysLogMsgeSizeMAX=2048 sysLogFiFoSizeMIN=1024 # color constants # @@ -198,8 +199,9 @@ readonly magenta="\033[1;35m" readonly cyan="\033[1;36m" readonly white="\033[1;37m" readonly std="\e[0m" -readonly CLRD="\e[0m" readonly BOLD="\e[1m" +readonly CLRct="\e[0m" +readonly GRNct="\e[1;32m" ##-------------------------------------## ## Added by Martinski W. [2025-Nov-29] ## @@ -209,8 +211,8 @@ readonly twoMByte=2097152 readonly LR_CronJobMins=5 readonly LR_CronJobHour=0 readonly LR_CronTagStr="scribeLogRotate" -readonly validHourRegExp="(3|4|6|8|12|24)" -readonly validHourLstStr="3, 4, 6, 8, 12, 24." +readonly validHourRegExp="(2|3|4|6|8|12|24)" +readonly validHourLstStr="2, 3, 4, 6, 8, 12, and 24." ##----------------------------------------## ## Modified by Martinski W. [2025-Jul-07] ## @@ -222,8 +224,7 @@ readonly uiscribeBranch="master" readonly uiscribeRepo="$raw_git/$uiscribeAuthor/$uiscribeName/$uiscribeBranch/${uiscribeName}.sh" readonly uiscribePath="$script_d/$uiscribeName" readonly uiscribeVerRegExp="v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})" - -readonly header="=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=${std}\n\n" +readonly menuSepStr="${white} =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=${CLRct}\n\n" # check if Scribe is already installed by looking for link in /opt/bin # [ -e "/opt/bin/$script_name" ] && scribeInstalled=true || scribeInstalled=false @@ -851,22 +852,26 @@ _Get_LogRotate_CronHour_() ##-------------------------------------## menu_LogRotate_CronJob_Time() { - local cronHourNum cronHourStr hourInput validInput - local GRNct="\\\e[1;32m" CLRct="\\\e[0m" validHoursStr + local GREEN="\\\e[1;32m" CLRD="\\\e[0m" + local validHoursANDstr validHoursORstr + local cronHourNum cronHourStr hourInput inputOK retCode + + validHoursANDstr="$(echo "$validHourLstStr" | sed -E "s/([1-9]+)/${GREEN}\1${CLRD}/g")" + validHoursORstr="$(echo "$validHoursANDstr" | sed 's/and/or/')" - validHoursStr="$(echo "$validHourLstStr" | sed -E "s/([1-9]+)/${GRNct}\1${CLRct}/g")" + retCode=1 + inputOK=false - validInput=false while true do ScriptLogo - printf "$white $header" + printf "$menuSepStr" cronHourNum="$(_Config_Option_Get_ LR_CRONJOB_HOUR)" - printf " ${BOLD}Current $lr cron job interval: " - printf "${green}Every ${cronHourNum} hours${CLRD}\n" - printf "\n ${BOLD}Please enter how often in HOURS to run the cron job." - printf "\n Valid values are $validHoursStr " - printf "(${green}e${CLRD}=Exit): " + printf " ${BOLD}Current $lr cron job frequency: " + printf "${green}Every ${cronHourNum} hours${CLRct}\n" + printf "\n ${BOLD}Please specify how often to run the cron job." + printf "\n Valid values are ${validHoursANDstr}\n" + printf "\n Enter frequency in HOURS (${green}e${CLRct}=Exit): " read -r hourInput if echo "$hourInput" | grep -qE "^[eE]$" @@ -875,28 +880,30 @@ menu_LogRotate_CronJob_Time() elif [ -z "$hourInput" ] || \ ! echo "$hourInput" | grep -qE "^${validHourRegExp}$" then - printf "\n ${red}Please enter a valid number:${CLRD} ${validHoursStr}\n\n" + printf "\n ${red}Please enter a valid number:${CLRct} ${validHoursORstr}\n\n" PressEnterTo "continue..." elif [ "$hourInput" -eq 24 ] then - validInput=true + inputOK=true cronHourNum="$hourInput" cronHourStr="$LR_CronJobHour" echo ; break else - validInput=true + inputOK=true cronHourNum="$hourInput" cronHourStr="*/$hourInput" echo ; break fi done - if "$validInput" + if "$inputOK" then + retCode=0 _Config_Option_Update_ LR_CRONJOB_HOUR "$cronHourNum" _Create_LogRotate_CronJob_ "$cronHourStr" LogRotate_CronJob_PostMount_Create fi + return "$retCode" } ##----------------------------------------## @@ -949,7 +956,7 @@ _SysLogMsgSizeFromConfig_() local msgSizeNum msgSizeOK=true msgSizeNum="$(grep -m1 'log_msg_size(' "$sng_conf" | cut -d ';' -f1 | grep -oE '[0-9]+')" - if [ -n "$msgSizeNum" ] && [ "$msgSizeNum" -gt "$sysLogMsgSizeMAX" ] + if [ -n "$msgSizeNum" ] && [ "$msgSizeNum" -gt "$sysLogMsgeSizeMAX" ] then msgSizeOK=false fi "$msgSizeOK" && return 0 @@ -958,7 +965,7 @@ _SysLogMsgSizeFromConfig_() then return 1 elif [ "$1" = "update" ] then - sed -i "s/log_msg_size($msgSizeNum)/log_msg_size($sysLogMsgSizeMAX)/g" "$sng_conf" + sed -i "s/log_msg_size($msgSizeNum)/log_msg_size($sysLogMsgeSizeMAX)/g" "$sng_conf" return 0 fi } @@ -1381,7 +1388,7 @@ _DoRotateLogFiles_() "$doPostRotateCleanup" && _DoPostRotateCleanup_ } -menu_status() +Menu_Status() { check_sng syslogd_check @@ -1600,7 +1607,7 @@ pre_install() ##----------------------------------------## ## Modified by Martinski W. [2025-Dec-05] ## ##----------------------------------------## -menu_install() +Menu_Install() { if [ ! -e "$sng_loc" ] then @@ -1763,7 +1770,7 @@ doUninstall() fi } -menu_uninstall() +Menu_Uninstall() { andre="remove" uni="UN" @@ -2086,7 +2093,7 @@ menu_restore() chmod 600 "$lrd_d"/* printf "\n$std Backup data has been restored from $cyan%s$std.\n" "$script_bakname" menu_restart - menu_status + Menu_Status ;; *) printf "\n\n$white *** RESTORE ABORTED! ***$std\n\n" @@ -2098,36 +2105,38 @@ menu_restore() ##----------------------------------------## ## Modified by Martinski W. [2024-Jul-07] ## ##----------------------------------------## -menu_about() +Menu_About() { - printf "About ${magenta}${SCRIPT_VERS_INFO}${std}\n" + printf "$menuSepStr" + printf " About ${magenta}${SCRIPT_VERS_INFO}${CLRct}\n" cat < Date: Mon, 5 Jan 2026 23:07:10 -0800 Subject: [PATCH 05/12] Improvements and Fine-Tuning. More improvements and fine-tuning. --- README.md | 2 +- scribe.sh | 8 +++++--- syslog-ng.share/syslog-ng.conf-scribe | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4b79d32..e6214ae 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **scribe** is a **syslog-ng** and **logrotate** installer for ASUS routers running **Asuswrt-Merlin** ## v3.2.7 -### Updated on 2026-Jan-04 +### Updated on 2026-Jan-05 ## Getting Started diff --git a/scribe.sh b/scribe.sh index 2a95d0f..d619e07 100644 --- a/scribe.sh +++ b/scribe.sh @@ -18,7 +18,7 @@ # curl --retry 3 "https://raw.githubusercontent.com/AMTM-OSR/scribe/master/scribe.h" -o "/jffs/scripts/scribe" && chmod 0755 /jffs/scripts/scribe && /jffs/scripts/scribe install # ################################################################## -# Last Modified: 2026-Jan-04 +# Last Modified: 2026-Jan-05 #----------------------------------------------------------------- ################ Shellcheck directives ################ @@ -35,7 +35,7 @@ readonly script_name="scribe" readonly scribe_ver="v3.2.7" -readonly scriptVer_TAG="26010422" +readonly scriptVer_TAG="26010522" scribe_branch="develop" script_branch="$scribe_branch" @@ -1021,7 +1021,9 @@ sync_conf() sed -i "s/$old_doc.*/$new_doc/" "$sng_conf" stats_freq="$( grep -m1 'stats_freq(' "$sng_conf" | cut -d ';' -f 1 | grep -oE '[0-9]*' )" [ -n "$stats_freq" ] && sed -i "s/stats_freq($stats_freq)/stats(freq($stats_freq))/g" "$sng_conf" - if [ -n "$sng_version_str" ] && [ -n "$sng_conf_verstr" ] + if [ -n "$sng_version_str" ] && \ + [ -n "$sng_conf_verstr" ] && \ + [ "$sng_version_str" != "$sng_conf_verstr" ] then sed -i "s/^${sng_conf_vtag2}${sng_conf_verstr}.*/$sng_conf_vtag1 $sng_version_str/" "$sng_conf" fi diff --git a/syslog-ng.share/syslog-ng.conf-scribe b/syslog-ng.share/syslog-ng.conf-scribe index 4a5d09d..ef2fc10 100644 --- a/syslog-ng.share/syslog-ng.conf-scribe +++ b/syslog-ng.share/syslog-ng.conf-scribe @@ -1,12 +1,12 @@ ############################################################################# -# syslog-ng.conf customized for scribe on Asuswrt-Merlin firmware -# compare to /opt/share/syslog-ng/examples/syslog-ng.conf-opkg for differences from Entware distribution +# syslog-ng.conf customized for Scribe on Asuswrt-Merlin firmware +# Compare to /opt/share/syslog-ng/examples/syslog-ng.conf-opkg for differences from the Entware distribution # # syslog-ng documentation: https://www.syslog-ng.com/technical-documents/list/syslog-ng-open-source-edition # # Release notes: https://github.com/syslog-ng/syslog-ng/releases -@version: 4.1 +@version: 4.7 #@include "scl.conf" # uncomment this line to for additional functionality, see syslog-ng documentation @include "/opt/etc/syslog-ng.d/" # Put any customization files in this directory From bacb15c94f6b0abb6f024b285b82763c19801bb0 Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Mon, 12 Jan 2026 01:32:12 -0800 Subject: [PATCH 06/12] Fixes and Improvements - Fixed bug when the call to Scribe found in the '/jffs/scripts/unmount' script was made *after* the Entware services are stopped, it failed to properly reset and put back the system log files so the built-in system loggers can then proceed to update them. This, in turn, was causing hundreds of log messages to be "lost" during a reboot sequence. - Upon a system reboot, when Entware services are started, syslog-ng was shutting down the built-in system loggers too early and with a minimum 2-second delay (and perhaps more in some cases), causing hundreds (and possibly close to a thousand) of reboot log messages to be "lost" due to the "deluge" of log entries flooding the system logs within the first ~2 to ~3 minutes of the bootup process. - Improvements in the display of CLI menu options. - Miscellaneous code improvements and fine-tuning. --- README.md | 2 +- init.d/rc.func.syslog-ng | 148 +++++--- scribe.sh | 775 ++++++++++++++++++++++++++++----------- 3 files changed, 652 insertions(+), 273 deletions(-) diff --git a/README.md b/README.md index e6214ae..bcdead4 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **scribe** is a **syslog-ng** and **logrotate** installer for ASUS routers running **Asuswrt-Merlin** ## v3.2.7 -### Updated on 2026-Jan-05 +### Updated on 2026-Jan-11 ## Getting Started diff --git a/init.d/rc.func.syslog-ng b/init.d/rc.func.syslog-ng index 894268f..743095e 100644 --- a/init.d/rc.func.syslog-ng +++ b/init.d/rc.func.syslog-ng @@ -1,40 +1,62 @@ #!/bin/sh - # # NB: rc.func only runs PRECMD on "start" -# Last Modified: 2026-Jan-02 +# Last Modified: 2026-Jan-11 # VERSION="3.1.3" #------------------------------------------- ## Run the F/W built-in native commands ## -psCmd="$(which -a ps | grep -v '^/opt/')" -awkCmd="$(which -a awk | grep -v '^/opt/')" -cutCmd="$(which -a cut | grep -v '^/opt/')" grepCmd="$(which -a grep | grep -v '^/opt/')" -pidofCmd="$(which -a pidof | grep -v '^/opt/')" -loggerCmd="$(which -a logger | grep -v '^/opt/')" +psCmd="$(which -a ps | $grepCmd -v '^/opt/')" +rmCmd="$(which -a rm | $grepCmd -v '^/opt/')" +lnCmd="$(which -a ln | $grepCmd -v '^/opt/')" +lsCmd="$(which -a ls | $grepCmd -v '^/opt/')" +awkCmd="$(which -a awk | $grepCmd -v '^/opt/')" +catCmd="$(which -a cat | $grepCmd -v '^/opt/')" +cutCmd="$(which -a cut | $grepCmd -v '^/opt/')" +pidofCmd="$(which -a pidof | $grepCmd -v '^/opt/')" +loggerCmd="$(which -a logger | $grepCmd -v '^/opt/')" logTagStr="Scribe:kill_logger[$$]" logPrioNum="-p 4" -prevSysLog_Loc="" ##----------------------------------------## -## Modified by Martinski W. [2026-Jan-02] ## +## Modified by Martinski W. [2026-Jan-11] ## ##----------------------------------------## kill_logger() { - # these will be set if coming from scribe; on bootup, these will not be set # + local serviceCallOK prevSysLog_Loc messagesLogSAVED + local scribeScriptFPath="/jffs/scripts/scribe" + local syslogNg_WaitnSEM_FPath="/tmp/var/tmp/scribe_SysLogNg.WAITN.SEM" + local syslogNg_StartSEM_FPath="/tmp/var/tmp/scribe_SysLogNg.START.SEM" + + if [ $# -eq 0 ] || [ -z "$1" ] || [ "$1" = "true" ] + then + serviceCallOK=true + else + serviceCallOK=false + [ ! -f "$syslogNg_StartSEM_FPath" ] && exit 1 + fi + + # If START Semaphore NOT found, call Scribe to set it up after a specified delay # + if [ ! -f "$syslogNg_StartSEM_FPath" ] + then + $loggerCmd -t "$logTagStr" $logPrioNum "Calling Scribe SysLogNgStartDelay..." + echo "150" > "$syslogNg_WaitnSEM_FPath" + nohup "$scribeScriptFPath" SysLogNgStartDelay >/dev/null 2>&1 & + exit 1 + fi + $rmCmd -f "$syslogNg_WaitnSEM_FPath" #Done waiting. We can start now# + + # These will be set if coming from Scribe; on bootup, these will NOT be set # [ -z "$tmplog" ] && tmplog="/tmp/syslog.log" [ -z "$jffslog" ] && jffslog="/jffs/syslog.log" [ -z "$optmsg" ] && optmsg="/opt/var/log/messages" [ -z "$script_conf" ] && script_conf="/jffs/addons/scribe.d/config" isjffs=false - - if [ $# -eq 0 ] || [ -z "$1" ] - then postLogMsgs=true - else postLogMsgs=false - fi prevSysLog_Loc="$syslog_loc" + messagesLogSAVED="${optmsg}.SAVED.LOG" - # figure out where syslogd expects log file to live # + # Figure out where syslogd expects log file to live # if [ -z "$syslog_loc" ] # do NOT look for config file if $syslog_loc is defined # then if [ -s "$script_conf" ] && $grepCmd -q "^SYSLOG_LOC=" "$script_conf" @@ -51,12 +73,12 @@ kill_logger() syslog_loc="$tmplog" # Make a reasonable guess # fi elif [ -z "$syslog_loc" ] - then # no config file, $syslog_loc not set, & syslogd not running!!! + then # NO config file, $syslog_loc not set, & syslogd not running!!! syslog_loc="$tmplog" # Make a reasonable guess # fi fi - if "$postLogMsgs" + if "$serviceCallOK" then $loggerCmd -t "$logTagStr" $logPrioNum "optmsg=[$optmsg]" $loggerCmd -t "$logTagStr" $logPrioNum "syslog_loc=[$syslog_loc]" @@ -65,7 +87,7 @@ kill_logger() [ "$syslog_loc" = "$jffslog" ] && isjffs=true - # touch 'logrotate.status' if it doesn't exist so syslog-ng doesn't whine # + # Touch 'logrotate.status' if it doesn't exist so syslog-ng doesn't whine # [ ! -f /var/lib/logrotate.status ] && touch /var/lib/logrotate.status ##----------------------------------------## @@ -74,59 +96,71 @@ kill_logger() # Set correct permissions to avoid "world-readable" status # chmod 600 /var/lib/logrotate.status - # export timezone if not already set # - [ -z "${TZ:+xSETx}" ] && export TZ="$(/bin/cat /etc/TZ)" + # Export timezone if not already set # + [ -z "${TZ:+xSETx}" ] && export TZ="$($catCmd /etc/TZ)" - if [ "$prevSysLog_Loc" = "$syslog_loc" ] && ! "$postLogMsgs" + if [ "$prevSysLog_Loc" = "$syslog_loc" ] && ! "$serviceCallOK" then return 0 fi - # kill any/all running klogd and/or syslogd # - count=30 - klgk=false - sldk=false - while [ "$count" -gt 0 ] - do - [ -n "$( $pidofCmd klogd )" ] && killall -q klogd - [ -n "$( $pidofCmd syslogd )" ] && killall -q syslogd - sleep 2 # give them a moment to shut down / unknown process to restart them # - [ -z "$( $pidofCmd klogd )" ] && klgk=true - [ -z "$( $pidofCmd syslogd )" ] && sldk=true - if "$klgk" && "$sldk" ; then count=-1 ; fi - count="$(( count - 1 ))" - done - [ "$count" -eq 0 ] && exit 1 - - # if syslog-ng was stopped by Scribe, /opt/var/log/messages will symlink to '$syslog_loc' # - [ -L "$optmsg" ] && /bin/rm -f "$optmsg" - - # if syslogd was running, '$syslog_loc' will exist and be a regular file (NOT a link) # - # this might be during bootup, or when starting scribe # + ##----------------------------------------## + ## Modified by Martinski W. [2026-Jan-10] ## + ##----------------------------------------## + # Kill any/all running klogd and/or syslogd # + [ -n "$( $pidofCmd klogd )" ] && killall -q klogd + [ -n "$( $pidofCmd syslogd )" ] && killall -q syslogd + # Give them a moment to shut down / unknown process to restart them # + usleep 500000 #0.5 sec# + # Background process to check and make sure built-in system loggers are terminated # + nohup "$scribeScriptFPath" SysLoggerCheck >/dev/null 2>&1 & + + # If syslog-ng was stopped by Scribe, /opt/var/log/messages will symlink to '$syslog_loc' # + [ -L "$optmsg" ] && $rmCmd -f "$optmsg" + + ##----------------------------------------## + ## Modified by Martinski W. [2026-Jan-11] ## + ##----------------------------------------## + # If syslogd was running, '$syslog_loc' will exist as a regular file (NOT a link) # + # This might be during bootup, or when starting Scribe # if [ ! -L "$syslog_loc" ] then - /bin/cat "$syslog_loc" >> "$optmsg" - /bin/rm -f "$syslog_loc" "$syslog_loc-1" - /bin/ln -s "$optmsg" "$syslog_loc" - echo "### Top of Log File ###" >> "${syslog_loc}-1" + if [ -s "$messagesLogSAVED" ] + then + $catCmd "$messagesLogSAVED" >> "$optmsg" + $rmCmd -f "$messagesLogSAVED" + fi + log1Msg="### Top of Log File ###" + if [ ! -d "${syslog_loc}-1" ] && \ + [ ! -L "${syslog_loc}-1" ] && \ + [ -s "${syslog_loc}-1" ] && \ + [ "$(head -n1 "${syslog_loc}-1")" != "$log1Msg" ] && \ + [ "$(tail -n1 "${syslog_loc}-1")" != "$log1Msg" ] + then ## Transfer 1st part of the system log ## + $catCmd "${syslog_loc}-1" >> "$optmsg" + fi + $catCmd "$syslog_loc" >> "$optmsg" + $rmCmd -f "$syslog_loc" "${syslog_loc}-1" + $lnCmd -s "$optmsg" "$syslog_loc" + echo "$log1Msg" > "${syslog_loc}-1" fi - # make /jffs/syslog.log and log-1 directories if default syslog location is not at /jffs # - # prevents system log saver from writing to jffs (not strictly necessary on newer routers) # + # Make /jffs/syslog.log and .log-1 directories if default syslog location is NOT at /jffs # + # Prevents system log saver from writing to jffs (not strictly necessary on newer routers) # if ! "$isjffs" && [ ! -d "$jffslog" ] then - /bin/rm -rf "$jffslog" "$jffslog-1" - /bin/mkdir "$jffslog" "$jffslog-1" + $rmCmd -rf "$jffslog" "${jffslog}-1" + /bin/mkdir "$jffslog" "${jffslog}-1" elif "$isjffs" then - # if syslogd is writing to /jffs, then ensure logfiles in /tmp # - # are properly linked in case something goes looking there # - [ ! -L "$tmplog" ] && /bin/ln -s "$optmsg" "$tmplog" - [ ! -L "$tmplog-1" ] && /bin/ln -s "${syslog_loc}-1" "${tmplog}-1" + # If syslogd is writing to /jffs, then ensure logfiles in /tmp # + # are properly linked, in case something goes looking there # + [ ! -L "$tmplog" ] && $lnCmd -s "$optmsg" "$tmplog" + [ ! -L "${tmplog}-1" ] && $lnCmd -s "${syslog_loc}-1" "${tmplog}-1" fi - # create /opt/var/run/syslog-ng/ directory if it doesn't exist # - # not needed for older versions of syslog-ng, but doesn't hurt anything # - [ ! -d "/opt/var/run/syslog-ng" ] && mkdir "/opt/var/run/syslog-ng" + # Create /opt/var/run/syslog-ng/ directory if it doesn't exist # + # Not needed for older versions of syslog-ng, but doesn't hurt anything # + [ ! -d "/opt/var/run/syslog-ng" ] && /bin/mkdir "/opt/var/run/syslog-ng" } PRECMD="kill_logger" diff --git a/scribe.sh b/scribe.sh index d619e07..8f8dc9a 100644 --- a/scribe.sh +++ b/scribe.sh @@ -18,7 +18,7 @@ # curl --retry 3 "https://raw.githubusercontent.com/AMTM-OSR/scribe/master/scribe.h" -o "/jffs/scripts/scribe" && chmod 0755 /jffs/scripts/scribe && /jffs/scripts/scribe install # ################################################################## -# Last Modified: 2026-Jan-05 +# Last Modified: 2026-Jan-11 #----------------------------------------------------------------- ################ Shellcheck directives ################ @@ -35,32 +35,35 @@ readonly script_name="scribe" readonly scribe_ver="v3.2.7" -readonly scriptVer_TAG="26010522" +readonly scriptVer_TAG="26011122" scribe_branch="develop" script_branch="$scribe_branch" # Ensure firmware binaries are used, not Entware # export PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH" -# set TMP if not set # +# Set TMP if not set # [ -z "${TMP:+xSETx}" ] && export TMP=/opt/tmp -# parse parameters # +# Parse parameters # action="X" got_zip=false banner=true +usbUnmountCaller=false + [ "${SCRIBE_LOGO:=xFALSEx}" = "nologo" ] && banner=false while { [ $# -gt 0 ] && [ -n "$1" ] ; } do case "$1" in gotzip) - got_zip=true - shift + got_zip=true ; shift ;; nologo) - banner=false - shift + banner=false ; shift + ;; + unmount) + usbUnmountCaller=true ; shift ;; service_event | LogRotate) banner=false @@ -68,8 +71,7 @@ do break ;; *) - action="$1" - shift + action="$1" ; shift ;; esac done @@ -170,6 +172,7 @@ readonly div_req="4.1" ## Added by Martinski W. [2025-Dec-05] ## ##-------------------------------------## readonly HOMEdir="/home/root" +readonly TEMPdir="/tmp/var/tmp" readonly optTempDir="/opt/tmp" readonly optVarLogDir="/opt/var/log" readonly syslogNgStr="syslog-ng" @@ -187,7 +190,10 @@ readonly LR_FLock_FName="/tmp/scribeLogRotate.flock" readonly logFilesRegExp="${optVarLogDir}/.*([.]log)?" readonly filteredLogList="${config_d}/.filteredlogs" readonly noConfigLogList="${config_d}/.noconfiglogs" -sysLogMsgeSizeMAX=2048 +readonly syslogNg_WaitnSEM_FPath="${TEMPdir}/scribe_SysLogNg.WAITN.SEM" +readonly syslogNg_StartSEM_FPath="${TEMPdir}/scribe_SysLogNg.START.SEM" +readonly sysLogLinesMAX=20480 +readonly sysLogMsgeSizeMAX=2048 sysLogFiFoSizeMIN=1024 # color constants # @@ -226,13 +232,13 @@ readonly uiscribePath="$script_d/$uiscribeName" readonly uiscribeVerRegExp="v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})" readonly menuSepStr="${white} =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=${CLRct}\n\n" -# check if Scribe is already installed by looking for link in /opt/bin # +# Check if Scribe is already installed by looking for link in /opt/bin # [ -e "/opt/bin/$script_name" ] && scribeInstalled=true || scribeInstalled=false -# check if uiScribe is installed # +# Check if uiScribe is installed # [ -e "$uiscribePath" ] && uiScribeInstalled=true || uiScribeInstalled=false -# check if Skynet is installed +# Check if Skynet is installed if [ -e "$fire_start" ] && grep -q "skynetloc" "$fire_start" then skynet_inst=true @@ -266,19 +272,19 @@ PressEnterTo() VersionStrToNum() { echo "$1" | sed 's/v//; s/_/./' | awk -F. '{ printf("%d%03d%02d\n", $1, $2, $3); }'; } -md5_file(){ md5sum "$1" | awk '{ printf( $1 ); }'; } # get md5sum of file +md5_file(){ md5sum "$1" | awk '{ printf( $1 ); }'; } strip_path(){ basename "$1"; } -dlt(){ rm -rf "$1"; } +delfr(){ rm -fr "$1"; } same_same(){ if [ "$( md5_file "$1" )" = "$( md5_file "$2" )" ]; then true; else false; fi; } -date_stamp(){ [ -e "$1" ] && mv "$1" "$1-$( date -Iseconds | cut -c 1-19 )"; } +date_stamp(){ [ -e "$1" ] && mv -f "$1" "$1-$( date -Iseconds | cut -c 1-19 )"; } SyslogNg_Running(){ if [ -n "$( pidof $sng )" ]; then true; else false; fi; } -SyslogDm_Running(){ if [ -n "$( pidof $sld )" ]; then true; else false; fi; } +SyslogD_Running(){ if [ -n "$( pidof $sld )" ]; then true; else false; fi; } ##-------------------------------------## ## Added by Martinski W. [2025-Nov-30] ## @@ -292,27 +298,41 @@ _GetFileSize_() return 0 } -# NB: ensure system log is backed up before doing this! -clear_loglocs() +##----------------------------------------## +## Modified by Martinski W. [2026-Jan-10] ## +##----------------------------------------## +Clear_Syslog_Links() { - dlt $tmplog - dlt $tmplog-1 - dlt $jffslog - dlt $jffslog-1 + if [ -L "$tmplog" ] + then delfr "$tmplog" + fi + if [ -L "${tmplog}-1" ] + then delfr "${tmplog}-1" + fi + if [ -L "$jffslog" ] || [ -d "$jffslog" ] + then delfr "$jffslog" + fi + if [ -L "${jffslog}-1" ] || [ -d "${jffslog}-1" ] + then delfr "${jffslog}-1" + fi } -start_syslogd() +##----------------------------------------## +## Modified by Martinski W. [2026-Jan-10] ## +##----------------------------------------## +Start_SyslogD() { service start_logger - count=30 - while ! SyslogDm_Running && [ "$count" -gt 0 ] + + "$usbUnmountCaller" && count=5 || count=30 + while ! SyslogD_Running && [ "$count" -gt 0 ] do - sleep 1 # give syslogd time to start up # + sleep 1 #Give syslogd time to start up# count="$(( count - 1 ))" done - if [ "$count" -eq 0 ] + if [ "$count" -eq 0 ] && ! "$usbUnmountCaller" then - printf "\n$red UNABLE TO START SYSLOGD! ABORTING!\n$std" + printf "\n ${red}UNABLE to start syslogd. ABORTING!!${std}\n" exit 1 fi } @@ -418,7 +438,7 @@ _Config_Option_Check_() ##----------------------------------------## ## Modified by Martinski W. [2025-Nov-29] ## ##----------------------------------------## -where_syslogd() +Where_SyslogD() { local findStr if [ -n "$(pidof syslogd)" ] @@ -429,63 +449,62 @@ where_syslogd() syslog_loc="$(echo "$findStr" | awk -F' ' '{print $2}')" fi fi - [ -n "$syslog_loc" ] && \ - _Config_Option_Update_ SYSLOG_LOC "$syslog_loc" + [ -n "$syslog_loc" ] && _Config_Option_Update_ SYSLOG_LOC "$syslog_loc" } ##----------------------------------------## ## Modified by Martinski W. [2025-Nov-30] ## ##----------------------------------------## -create_conf() +Create_Config() { printf "\n$white Detecting default syslog location... " if SyslogNg_Running then slg_was_rng=true printf "\n Briefly shutting down %s" "$sng" - killall -q $sng 2>/dev/null + killall -q "$sng" 2>/dev/null count=10 while SyslogNg_Running && [ "$count" -gt 0 ] do sleep 1 count="$(( count - 1 ))" done - clear_loglocs + Clear_Syslog_Links else slg_was_rng=false fi - if ! SyslogDm_Running - then start_syslogd + if ! SyslogD_Running + then Start_SyslogD fi - where_syslogd + Where_SyslogD if "$slg_was_rng" then - # if syslog-ng was running, kill syslogd and restart # + # If syslog-ng was running, kill syslogd and restart # $S01sng_init start elif [ -x "$sng_loc" ] && [ -x "$lr_loc" ] && \ [ -d "$lrd_d" ] && [ -n "$syslog_loc" ] && \ [ -s "$syslog_loc" ] && [ ! -L "$syslog_loc" ] then - # prepend /opt/var/messages to syslog & create link # + # Prepend /opt/var/messages to syslog & create link # cat "$syslog_loc" >> "$optmsg" mv -f "$optmsg" "$syslog_loc" ln -s "$syslog_loc" "$optmsg" fi - # assume uiScribe is still running if it was before stopping syslog-ng # + # Assume uiScribe is still running if it was before stopping syslog-ng # } ##----------------------------------------## ## Modified by Martinski W. [2025-Nov-29] ## ##----------------------------------------## -read_conf() +Read_Config() { if [ -s "$script_conf" ] && grep -q "^SYSLOG_LOC=" "$script_conf" then syslog_loc="$(_Config_Option_Get_ SYSLOG_LOC)" else - create_conf + Create_Config fi export syslog_loc @@ -555,7 +574,7 @@ _CenterTextStr_() ##----------------------------------------## ScriptLogo() { - if ! $banner + if ! "$banner" then return 0 fi local spaceLenT=45 spaceLenX=5 colorCT @@ -589,8 +608,8 @@ Get_ZIP_File() { if ! $got_zip then - dlt "$unzip_dirPath" - dlt "$script_zip_file" + delfr "$unzip_dirPath" + delfr "$script_zip_file" printf "\n$white Fetching %s from GitHub %s branch ...$std\n" "$script_name" "$script_branch" if curl -fL --retry 4 --retry-delay 5 --retry-connrefused "$script_repo_ZIP" -o "$script_zip_file" then @@ -605,24 +624,24 @@ Get_ZIP_File() fi } -Hup_uiScribe() +Restart_uiScribe() { if "$uiScribeInstalled" then - printf "$white Restarting $uiscribeName ...\n" + printf "\n$white Restarting ${uiscribeName}...\n" $uiscribePath startup fi } -rld_sngconf() +Reload_sngconf() { printf "$white reloading %s ... $cyan" "$( strip_path $sng_conf )" $sngctl_loc reload printf "\n$std" - Hup_uiScribe + Restart_uiScribe } -copy_rcfunc() +Copy_rcfunc() { printf "$white copying %s to %s ...$std" "$rcfunc_sng" "$init_d" cp -pf "$unzip_dirPath/init.d/$rcfunc_sng" "$init_d/" @@ -630,35 +649,62 @@ copy_rcfunc() finished } -check_sng() +##-------------------------------------## +## Added by Martinski W. [2026-Jan-11] ## +##-------------------------------------## +_ShowSysLogNg_WaitStart_Msge_() +{ + local waitSecs=180 + if [ -s "$syslogNg_WaitnSEM_FPath" ] + then waitSecs="$(head -n1 "$syslogNg_WaitnSEM_FPath")" + fi + printf " ${magenta}NOTICE:\n -------${CLRct}\n" + printf " ${yellow}%s will start in about ${GRNct}%d${yellow} seconds...\n" "$sng" "$waitSecs" + printf " Please wait until %s has been started.${CLRct}\n\n" "$sng" +} + +##----------------------------------------## +## Modified by Martinski W. [2026-Jan-11] ## +##----------------------------------------## +Check_SysLogNg() { printf "\n$white %34s" "checking $sng daemon ..." if SyslogNg_Running then - printf "$green alive. $std\n" + printf " ${green}alive.${std}\n" else - printf "$red dead. $std\n" + printf " ${red}dead.${std}\n" + if [ -f "$syslogNg_WaitnSEM_FPath" ] + then + echo ; _ShowSysLogNg_WaitStart_Msge_ + fi printf "$white %34s" "the system logger (syslogd) ..." - if SyslogDm_Running + if SyslogD_Running then - printf "$green is running. $std\n\n" - printf "$yellow Type$red %s restart$yellow at shell prompt or select$red rs$yellow\n" "$script_name" - printf " from %s main menu to start %s.\n" "$script_name" "$sng" + printf " ${green}is running.${std}\n\n" + if [ ! -f "$syslogNg_WaitnSEM_FPath" ] + then + printf " ${yellow}Type ${green}%s restart${yellow} at shell prompt or select ${green}rs${std}\n" "$script_name" + printf " ${yellow}from %s main menu to start %s.${std}\n\n" "$script_name" "$sng" + fi else - printf "$red is not running! $std\n\n" - printf "$white Type$red %s -Fevd$white at shell prompt or select$red sd$white\n" "$sng" - printf " from %s utilities menu ($red%s$white) to view %s\n" "$script_name" "su" "$sng" - printf " debugging data.\n" + printf " ${red}is NOT running!${std}\n\n" + if [ ! -f "$syslogNg_WaitnSEM_FPath" ] + then + printf " ${yellow}Type ${green}%s -Fevd${yellow} at shell prompt or select '${green}sd${std}'\n" "$sng" + printf " ${yellow}from %s utilities menu ('${green}su${yellow}' option) to view %s\n" "$script_name" "$sng" + printf " debugging information.${std}\n\n" + fi fi fi } -sed_sng() +sed_SysLogNg_Init() { printf "$white %34s" "checking $( strip_path "$S01sng_init" ) ..." if ! grep -q "$rcfunc_sng" "$S01sng_init" then - sed -i "\~/opt/etc/init.d/rc.func$~i . $rcfunc_loc # added by $script_name\n" "$S01sng_init" + sed -i "\~/opt/etc/init.d/rc.func$~i . $rcfunc_loc #${script_name}#\n" "$S01sng_init" updated else present @@ -672,7 +718,7 @@ rd_warn(){ ##----------------------------------------## ## Modified by Martinski W. [2025-Nov-29] ## ##----------------------------------------## -syslogd_check() +SysLogd_Check() { local checksys_loc @@ -715,9 +761,9 @@ sed_srvcEvent() if grep -q "$script_name kill_logger" "$srvcEvent" then sed -i "/$script_name kill_logger/d" "$srvcEvent" fi - if ! grep -q "$script_name service_event" "$srvcEvent" + if ! grep -q "^$script_loc service_event" "$srvcEvent" then - echo "$script_loc service_event \"\$@\" & # added by $script_name" >> "$srvcEvent" + echo "$script_loc service_event \"\$@\" & #${script_name}#" >> "$srvcEvent" updated else present @@ -725,7 +771,7 @@ sed_srvcEvent() else { echo "#!/bin/sh -" ; echo - echo "$script_loc service_event \"\$@\" & # added by $script_name" + echo "$script_loc service_event \"\$@\" & #${script_name}#" } > "$srvcEvent" printf "$green created. $std\n" fi @@ -790,15 +836,23 @@ LogRotate_CronJob_PostMount_Check() [ -f /var/lib/logrotate.status ] && chmod 600 /var/lib/logrotate.status } +##----------------------------------------## +## Modified by Martinski W. [2026-Jan-10] ## +##----------------------------------------## sed_unMount() { printf "$white %34s" "checking $( strip_path "$unMount" ) ..." if [ -f "$unMount" ] then [ "$( grep -c "#!/bin/sh" "$unMount" )" -ne 1 ] && sed -i "1s~^~#!/bin/sh -\n\n~" "$unMount" - if ! grep -q "$script_name stop" "$unMount" + + if grep -q " && $script_name stop nologo" "$unMount" then - echo "[ \"\$(find \$1/entware*/bin/$script_name 2> /dev/null)\" ] && $script_name stop nologo # added by $script_name" >> "$unMount" + sed -i "/&& $script_name stop nologo/d" "$unMount" + fi + if ! grep -q "&& $script_loc stop nologo unmount" "$unMount" + then + echo "[ \"\$(find \"\${1}/entware/bin/$script_name\" 2>/dev/null)\" ] && $script_loc stop nologo unmount #${script_name}#" >> "$unMount" updated else present @@ -806,7 +860,7 @@ sed_unMount() else { echo "#!/bin/sh" ; echo - echo "[ \"\$(find \$1/entware*/bin/$script_name 2> /dev/null)\" ] && $script_name stop nologo # added by $script_name" + echo "[ \"\$(find \"\${1}/entware/bin/$script_name\" 2>/dev/null)\" ] && $script_loc stop nologo unmount #${script_name}#" } > "$unMount" printf "$green created. $std\n" fi @@ -926,7 +980,7 @@ LogRotate_CronJob_Check() fi } -dir_links() +Check_Dir_Links() { printf "$white %34s" "checking directory links ..." if [ ! -L "$syslog_loc" ] || [ ! -d "/opt/var/run/syslog-ng" ] @@ -938,7 +992,7 @@ dir_links() # shellcheck source=/opt/etc/init.d/rc.func.syslog-ng ################################################################# . "$rcfunc_loc" - kill_logger + kill_logger true updated else present @@ -998,7 +1052,7 @@ _SysLogFiFoSizeFromConfig_() ##----------------------------------------## ## Modified by Martinski W. [2026-Jan-03] ## ##----------------------------------------## -sync_conf() +SysLogNg_Config_Sync() { local sng_conf_vtag1 sng_conf_vtag2 sng_version_str sng_conf_verstr @@ -1030,7 +1084,7 @@ sync_conf() _SysLogMsgSizeFromConfig_ update _SysLogFiFoSizeFromConfig_ update $S01sng_init start - Hup_uiScribe + Restart_uiScribe printf "$white %34s" "$( strip_path "$sng_conf" ) version ..." printf "$yellow updated! (%s) $std\n" "$sng_version_str" logger -t "$script_name" "$( strip_path "$sng_conf" ) version number updated ($sng_version_str)!" @@ -1039,7 +1093,7 @@ sync_conf() fi } -sng_syntax() +SysLogNg_Config_SyntaxCheck() { printf "$white %34s" "$( strip_path "$sng_conf" ) syntax check ..." if $sng_loc -s >> /dev/null 2>&1 @@ -1055,7 +1109,7 @@ get_vers() { # only get scribe from github once # script_md5="$( md5_file "$script_loc")" - dlt "$script_tmp_file" + delfr "$script_tmp_file" curl -LSs --retry 4 --retry-delay 5 --retry-connrefused "$script_repoFile" -o "$script_tmp_file" [ ! -e "$script_tmp_file" ] && \ printf "\n\n$white %s GitHub repository is unavailable! -- $red ABORTING! $std\n\n" "$script_name" && exit 1 @@ -1068,7 +1122,7 @@ get_vers() elif [ "$( VersionStrToNum "$github_ver" )" -gt "$( VersionStrToNum "$scribe_ver" )" ]; then new_vers="major" elif [ "$script_md5" != "$github_md5" ]; then new_vers="minor" fi - dlt "$script_tmp_file" + delfr "$script_tmp_file" } prt_vers() @@ -1135,7 +1189,7 @@ setup_exmpls() if [ -e "$conf_opkg" ] then update_file "$conf_opkg" "$share/examples/$opkg" "backup" - dlt "$conf_opkg" + delfr "$conf_opkg" elif [ ! -e "$share/examples/$opkg" ] then cp -fp "$conf" "$share/examples/$opkg" @@ -1151,7 +1205,7 @@ setup_exmpls() printf "$std" } -force_install() +Force_Install() { printf "\n$blue %s$white already installed!\n" "$1" [ "$1" != "$script_name" ] && printf "$yellow Forcing installation$red WILL OVERWRITE$yellow any modified configuration files!\n" @@ -1160,12 +1214,12 @@ force_install() return $? } -show_config() +SysLogNg_ShowConfig() { if [ -e "$sng_loc" ] then - dlt "$sngconf_merged" - dlt "$sngconf_error" + delfr "$sngconf_merged" + delfr "$sngconf_error" if $sng_loc --preprocess-into="$sngconf_merged" 2> "$sngconf_error" then less "$sngconf_merged" @@ -1181,7 +1235,7 @@ show_config() show_loaded() { - dlt "$sngconf_merged" + delfr "$sngconf_merged" $sngctl_loc config --preprocessed > "$sngconf_merged" less "$sngconf_merged" } @@ -1392,10 +1446,10 @@ _DoRotateLogFiles_() Menu_Status() { - check_sng - syslogd_check + Check_SysLogNg + SysLogd_Check printf "\n$magenta checking system for necessary %s hooks ...\n\n" "$script_name" - sed_sng + sed_SysLogNg_Init if SyslogNg_Running then sed_srvcEvent fi @@ -1404,11 +1458,11 @@ Menu_Status() if SyslogNg_Running then LogRotate_CronJob_Check - dir_links + Check_Dir_Links fi printf "\n$magenta checking %s configuration ...\n\n" "$sng" - sync_conf - sng_syntax + SysLogNg_Config_Sync + SysLogNg_Config_SyntaxCheck get_vers prt_vers } @@ -1429,8 +1483,8 @@ sng_ver_chk() Setup_SysLogNG() { printf "\n$magenta setting up %s ...\n$std" "$sng" - copy_rcfunc - sed_sng + Copy_rcfunc + sed_SysLogNg_Init sed_srvcEvent sed_unMount if [ "$( md5_file "$sng_share/examples/${sng}.conf-scribe" )" != "$( md5_file "$sng_conf" )" ] @@ -1439,7 +1493,7 @@ Setup_SysLogNG() update_file "$sng_share/examples/${sng}.conf-scribe" "$sng_conf" "backup" finished fi - sync_conf + SysLogNg_Config_Sync } Setup_LogRotate() @@ -1453,7 +1507,7 @@ Setup_LogRotate() ##----------------------------------------## ## Modified by Martinski W. [2025-Aug-23] ## ##----------------------------------------## -doInstall() +Do_Install() { forceOpt="" if [ $# -gt 1 ] && [ "$2" = "FORCE" ] @@ -1471,7 +1525,7 @@ doInstall() ##----------------------------------------## ## Modified by Martinski W. [2025-Jun-09] ## ##----------------------------------------## -setup_Scribe() +Setup_Scribe() { printf "\n$white setting up %s ...\n" "$script_name" cp -fp "$unzip_dirPath/${script_name}.sh" "$script_loc" @@ -1481,8 +1535,8 @@ setup_Scribe() # Install correct firewall or skynet file, these are mutually exclusive # if "$skynet_inst" then - dlt "$sngd_d/firewall" - dlt "$lrd_d/firewall" + delfr "$sngd_d/firewall" + delfr "$lrd_d/firewall" if [ ! -e "$sngd_d/skynet" ] || [ "$1" = "ALL" ] then printf "$white installing %s Skynet filter ...\n" "$sng" @@ -1492,8 +1546,8 @@ setup_Scribe() skynetlog="$( grep -m1 'file("' $sngd_d/skynet | awk -F\" '{ printf ( $2 ); }'; )" sh $skynet settings syslog "$skynetlog" > /dev/null 2>&1 else - dlt "$sngd_d/skynet" - dlt "$lrd_d/skynet" + delfr "$sngd_d/skynet" + delfr "$lrd_d/skynet" if [ ! -e "$sngd_d/firewall" ] || [ "$1" = "ALL" ] then printf "$white installing %s firewall filter ...\n" "$sng" @@ -1535,21 +1589,21 @@ Uninstall_uiScribe() fi } -pre_install() +PreInstall_Check() { - # check for required components - okay=true + # Check for required components # + reqsOK=true - # check if Entware & ASUSWRT-Merlin are installed and Merlin version number # + # Check if Entware & ASUSWRT-Merlin are installed and Merlin version number # if [ ! -x "/opt/bin/opkg" ] || \ [ "$fwName" != "$wrtMerlin" ] || \ [ "$( VersionStrToNum "$fwVerBuild" )" -lt "$( VersionStrToNum "$fwVerReqd" )" ] then printf "\n\n$red %s version %s or later with Entware is required! $std\n" "$wrtMerlin" "$fwVerReqd" - okay=false + reqsOK=false fi - # check if diversion is installed and version number + # Check if diversion is installed and version number # if [ -x "$divers" ] then printf "\n\n$white Diversion detected, checking version ..." @@ -1559,7 +1613,7 @@ pre_install() then printf "$red update required!\n" printf " Diversion %s or later is required! $std\n" "$div_req" - okay=false + reqsOK=false else printf "$green okay! $std\n" fi @@ -1575,7 +1629,7 @@ pre_install() then printf "$red update required!\n" printf " Skynet %s or later is required! $std\n" "$sky_req" - okay=false + reqsOK=false else printf "$green okay! $std\n" fi @@ -1587,21 +1641,21 @@ pre_install() printf " If Skynet is installed after %s, run \"%s install\"\n" "$script_name" "$script_name" printf " and force installation to configure %s and Skynet\n" "$script_name" printf " to work together.\n\n" - if $okay + if "$reqsOK" then printf " Do you want to continue installation of %s [y|n]? $std" "$script_name" if ! yes_no then - okay=false + reqsOK=false fi fi fi - # exit if requirements not met # - if ! "$okay" + # Exit if requirements NOT met # + if ! "$reqsOK" then printf "\n\n$magenta exiting %s installation. $std\n\n" "$script_name" - dlt "$script_loc" + delfr "$script_loc" exit 1 fi } @@ -1613,21 +1667,21 @@ Menu_Install() { if [ ! -e "$sng_loc" ] then - doInstall "$sng" - elif force_install "$sng" + Do_Install "$sng" + elif Force_Install "$sng" then $S01sng_init stop - doInstall "$sng" "FORCE" + Do_Install "$sng" "FORCE" fi echo $S01sng_init start if [ ! -e "$lr_loc" ] then - doInstall "$lr" - elif force_install "$lr" + Do_Install "$lr" + elif Force_Install "$lr" then - doInstall "$lr" "FORCE" + Do_Install "$lr" "FORCE" fi if _AcquireFLock_ nonblock @@ -1641,13 +1695,13 @@ Menu_Install() if ! "$scribeInstalled" then - setup_Scribe "ALL" - elif force_install "$script_name script" + Setup_Scribe "ALL" + elif Force_Install "$script_name script" then - setup_Scribe "ALL" + Setup_Scribe "ALL" fi - rld_sngconf + Reload_sngconf printf "\n$white %s setup complete!\n\n" "$script_name" PressEnterTo "continue..." if ! "$uiScribeInstalled" @@ -1655,47 +1709,72 @@ Menu_Install() fi } -menu_restart() +Menu_Restart() { if SyslogNg_Running then - printf "\n$yellow Restarting %s... $std\n" "$sng" + printf "\n ${yellow}Restarting %s...${std}\n" "$sng" $S01sng_init restart else - printf "\n$white %s$red NOT$white running! $yellow Starting %s ... $std\n" "$sng" + printf "\n ${white}%s ${red}NOT${white} running! ${yellow}Starting...${std}\n" "$sng" $S01sng_init start fi - Hup_uiScribe + sleep 1 #Allow time to start up# + Restart_uiScribe } ##----------------------------------------## -## Modified by Martinski W. [2025-Nov-30] ## +## Modified by Martinski W. [2026-Jan-11] ## ##----------------------------------------## StopSyslogNg() { - printf "$white stopping %s ...\n" "$sng" + local lastNLines logNumLines logFileSize + local messagesLogSAVED="${optmsg}.SAVED.LOG" + + printf "\n ${white}Stopping %s...\n" "$sng" $S01sng_init stop - # remove any syslog links # - clear_loglocs + # Remove any syslog links # + Clear_Syslog_Links ## Do NOT move very large files into JFFS/TMPFS ## + lastNLines=100 + logNumLines="$(wc -l < "$optmsg")" logFileSize="$(_GetFileSize_ "$optmsg")" + if [ "$(echo "$logFileSize $twoMByte" | awk -F ' ' '{print ($1 < $2)}')" -eq 1 ] then - mv -f "$optmsg" "$syslog_loc" + head -n -$lastNLines "$optmsg" > "${syslog_loc}-1" else - tail -n 16k "$optmsg" > "$syslog_loc" + if [ "$logNumLines" -le "$sysLogLinesMAX" ] + then + head -n -$lastNLines "$optmsg" > "${syslog_loc}-1" + else + startNum="$((logNumLines - sysLogLinesMAX))" + tail -n +"$startNum" "$optmsg" | head -n -$lastNLines > "${syslog_loc}-1" + fi fi - ln -s "$syslog_loc" "$optmsg" + tail -n $lastNLines "$optmsg" > "$syslog_loc" - printf "$white starting system klogd and syslogd ...\n" - start_syslogd - if ! $banner + if ! "$usbUnmountCaller" + then rm -f "$messagesLogSAVED" + else mv -f "$optmsg" "$messagesLogSAVED" + fi + ln -snf "$syslog_loc" "$optmsg" + + if [ "$syslog_loc" = "$jffslog" ] + then + ln -snf "$syslog_loc" "$tmplog" + ln -snf "${syslog_loc}-1" "${tmplog}-1" + fi + + printf " ${white}Starting system klogd and syslogd..." + Start_SyslogD + if ! "$banner" then return 0 fi - printf "\n$white %s will be started at next reboot; you\n" "$sng" - printf " may type '%s restart' at shell prompt, or\n" "$script_name" - printf " select rs from %s menu to restart %s $std\n\n" "$script_name" "$sng" + printf "\n ${yellow}%s will be started at the next router reboot.\n" "$sng" + printf " You may type ${green}%s restart${yellow} at the shell prompt, or\n" "$script_name" + printf " select '${green}rs${yellow}' from %s menu to restart %s.${std}\n\n" "$script_name" "$sng" } StopLogRotate() @@ -1705,7 +1784,7 @@ StopLogRotate() fi } -menu_stop() +Menu_Stop() { StopSyslogNg StopLogRotate @@ -1717,21 +1796,21 @@ menu_stop() doUninstall() { printf "\n\n" - banner=false # suppress certain messages # + banner=false # Suppress certain messages # if [ -e "$sng_loc" ] then if SyslogNg_Running then StopSyslogNg fi - sed -i "/$script_name stop/d" "$unMount" + sed -i "/$script_name stop nologo/d" "$unMount" sed -i "/$script_name service_event/d" "$srvcEvent" - dlt "$S01sng_init" - dlt "$rcfunc_loc" + delfr "$S01sng_init" + delfr "$rcfunc_loc" printf "\n$cyan" /opt/bin/opkg remove "$sng" - dlt "$sng_conf" - dlt "$sngd_d" - dlt "$sng_share" + delfr "$sng_conf" + delfr "$sngd_d" + delfr "$sng_share" if "$skynet_inst" && ! "$reinst" then @@ -1749,18 +1828,18 @@ doUninstall() sed -i "/cru a ${LR_CronTagStr}/d" "$postMount" printf "\n$cyan" /opt/bin/opkg remove "$lr" - dlt "$lr_conf" - dlt "$lrd_d" - dlt "$lr_share" - dlt "$lr_daily" + delfr "$lr_conf" + delfr "$lrd_d" + delfr "$lr_share" + delfr "$lr_daily" else not_installed "$lr" fi - dlt "$unzip_dirPath" - dlt "$script_zip_file" - dlt "/opt/bin/$script_name" - dlt "$script_loc" + delfr "$unzip_dirPath" + delfr "$script_zip_file" + delfr "/opt/bin/$script_name" + delfr "$script_loc" scribeInstalled=false if ! "$reinst" then @@ -1801,7 +1880,7 @@ Menu_Uninstall() esac } -menu_filters() +Menu_Filters() { printf "\n$white Do you want to update$yellow %s$white and$yellow %s$white filter files?\n" "$sng" "$lr" printf "$cyan 1) Adds any new files to$yellow %s$cyan directories\n" "$share_ex" @@ -1860,7 +1939,7 @@ menu_filters() done done printf "\n$white %s and %s example files updated!$std\n" "$sng" "$lr" - rld_sngconf + Reload_sngconf else printf "\n$white %s and %s example files$red not$white updated!$std\n" "$sng" "$lr" fi @@ -1869,7 +1948,7 @@ menu_filters() ##----------------------------------------## ## Modified by Martinski W. [2025-Jul-07] ## ##----------------------------------------## -menu_update() +Menu_Update() { if [ $# -eq 0 ] || [ -z "$1" ] then @@ -1895,8 +1974,8 @@ menu_update() if { [ $# -eq 1 ] && [ "$1" = "force" ] ; } || yes_no then Get_ZIP_File - setup_Scribe "NEWER" - copy_rcfunc + Setup_Scribe "NEWER" + Copy_rcfunc printf "\n$white %s updated!$std\n" "$script_name" sh "$script_loc" filters gotzip nologo sh "$script_loc" status nologo @@ -1915,7 +1994,7 @@ Update_Version() then get_vers prt_vers - menu_update "$@" + Menu_Update "$@" else not_recog=true fi @@ -1954,10 +2033,10 @@ menu_forgrnd() ##----------------------------------------## ## Modified by Martinski W. [2025-Aug-24] ## ##----------------------------------------## -gather_debug() +Gather_Debug() { local debugTarball="${script_debug}.tar.gz" - dlt "$script_debug" "$debugTarball" + delfr "$script_debug" "$debugTarball" printf "\n$white gathering debugging information...\n" get_vers @@ -2004,8 +2083,8 @@ gather_debug() printf "#### %s not running! ####\n%s\n" "$sng" "$debug_sep" >> "$script_debug" fi printf "\n%s\n### %s on-disk syntax check:\n" "$debug_sep" "$sng" >> "$script_debug" - dlt "$sngconf_merged" - dlt "$sngconf_error" + delfr "$sngconf_merged" + delfr "$sngconf_error" $sng_loc --preprocess-into="$sngconf_merged" 2> "$sngconf_error" cat "$sngconf_merged" >> "$script_debug" if [ -s "$sngconf_error" ] @@ -2088,13 +2167,13 @@ menu_restore() case "$rstit" in YES) printf "\n$white Restoring %s and %s Configurations ... \n" "$sng" "$lr" - dlt "$sngd_d" - dlt "$lrd_d" + delfr "$sngd_d" + delfr "$lrd_d" tar -zxvf "$script_bakname" -C / chmod 600 "$sngd_d"/* chmod 600 "$lrd_d"/* printf "\n$std Backup data has been restored from $cyan%s$std.\n" "$script_bakname" - menu_restart + Menu_Restart Menu_Status ;; *) @@ -2104,6 +2183,247 @@ menu_restore() fi } +##-------------------------------------## +## Added by Martinski W. [2026-Jan-10] ## +##-------------------------------------## +_Create_SysLogNgStartDelay_BGScript_() +{ + cat << 'EOFT' > "$bgScript_FPath" +#!/bin/sh +# Script to delay starting syslog-ng service (created by Scribe) +# +set -u + +readonly scriptFName="${0##*/}" +readonly TEMP_DIR="/tmp/var/tmp" +readonly logDateTime="%Y-%b-%d %I:%M:%S %p %Z" +readonly logFilePath="${TEMP_DIR}/${scriptFName%.*}.LOG" +readonly syslogNg_WaitnSEM_FPath="${TEMP_DIR}/scribe_SysLogNg.WAITN.SEM" +readonly syslogNg_StartSEM_FPath="${TEMP_DIR}/scribe_SysLogNg.START.SEM" + +readonly S01syslogNg_srvc="/opt/etc/init.d/S01syslog-ng" +readonly logTagStr="${scriptFName}_[$$]" + +export PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH" + +_LogDebugMsg_() +{ + local timeNow="$(date +"$logDateTime")" + if [ $# -gt 1 ] && [ "$2" = "_START_" ] + then echo "${timeNow}: $1" > "$logFilePath" + else echo "${timeNow}: $1" >> "$logFilePath" + fi + logger -t "$logTagStr" "$1" +} + +trap '' HUP + +_LogDebugMsg_ "Start of Background Script [$scriptFName][$$]" _START_ + +tempSecs=0 +sleepSecs=5 +checkSecs=30 +cntSleepSecs=0 +sleepSecsMIN=120 #2.0 mins# +minSleepSecs=150 #2.5 mins# +sleepSecsMAX=210 #3.5 mins# +readyToStart=false +timeCheckStatus=true +sysLogNg_Param="" + +if [ -s "$syslogNg_WaitnSEM_FPath" ] +then + tempSecs="$(head -n1 "$syslogNg_WaitnSEM_FPath")" + if echo "$tempSecs" | grep -qE "^[1-3][0-9]{2}$" && \ + [ "$tempSecs" -ge "$sleepSecsMIN" ] && [ "$tempSecs" -le "$sleepSecsMAX" ] + then minSleepSecs="$tempSecs" + fi +fi +echo "$minSleepSecs" > "$syslogNg_WaitnSEM_FPath" + +while true +do + if ! "$readyToStart" && \ + "$timeCheckStatus" && \ + [ -x /opt/bin/opkg ] && \ + [ -x "$S01syslogNg_srvc" ] && \ + [ "$(nvram get ntp_ready)" = "1" ] && \ + [ "$(nvram get start_service_ready)" = "1" ] && \ + [ "$(nvram get success_start_service)" = "1" ] + then readyToStart=true + fi + if "$readyToStart" && [ "$cntSleepSecs" -ge "$minSleepSecs" ] + then + if [ -z "$(pidof syslog-ng)" ] + then sysLogNg_Param=start + else sysLogNg_Param=restart + fi + _LogDebugMsg_ "Calling [$S01syslogNg_srvc $sysLogNg_Param]..." + + rm -f "$syslogNg_WaitnSEM_FPath" + echo "$cntSleepSecs" > "$syslogNg_StartSEM_FPath" + "$S01syslogNg_srvc" "$sysLogNg_Param" + + _LogDebugMsg_ "Exiting Background Loop [$cntSleepSecs][$$]..." + break + fi + if [ "$cntSleepSecs" -ge "$sleepSecsMAX" ] + then + rm -f "$syslogNg_WaitnSEM_FPath" + _LogDebugMsg_ "Exiting Background Loop [$cntSleepSecs][$$]..." + break #Escape WITHOUT starting service# + fi + if "$timeCheckStatus" + then + _LogDebugMsg_ "Sleeping $checkSecs secs [$cntSleepSecs][$$]..." + fi + sleep "$sleepSecs" + cntSleepSecs="$((cntSleepSecs + sleepSecs))" + echo "$((minSleepSecs - cntSleepSecs))" > "$syslogNg_WaitnSEM_FPath" + if [ "$((cntSleepSecs % checkSecs))" -eq 0 ] + then timeCheckStatus=true + else timeCheckStatus=false + fi +done + +_LogDebugMsg_ "End of Background Script [$scriptFName][$$]" +rm -f "$0" + +#EOF# +EOFT + + chmod a+x "$bgScript_FPath" +} + +##-------------------------------------## +## Added by Martinski W. [2026-Jan-10] ## +##-------------------------------------## +_Launch_SysLogNgStartDelay_BGScript_() +{ + local taskPID logTag="${script_name}_$$" + local bgScript_FName="scribe_SysLogNg_Delay.sh" + local bgScript_FPath="${TEMPdir}/$bgScript_FName" + + if [ -s "$bgScript_FPath" ] && \ + [ -x "$bgScript_FPath" ] && \ + [ -n "$(pidof "$bgScript_FName")" ] + then + logger -st "$logTag" -p 4 "INFO: Script [$bgScript_FName] is already running..." + return 1 + fi + + _Create_SysLogNgStartDelay_BGScript_ + + if [ ! -s "$bgScript_FPath" ] || [ ! -x "$bgScript_FPath" ] + then + logger -st "$logTag" -p 3 "**ERROR**: Script [$bgScript_FPath] NOT found." + return 1 + fi + + "$bgScript_FPath" & taskPID=$! + logger -st "$logTag" -p 5 "INFO: Background script [$bgScript_FName] started. PID: [$taskPID]" +} + +##-------------------------------------## +## Added by Martinski W. [2026-Jan-10] ## +##-------------------------------------## +_Create_SysLoggerCheck_BGScript_() +{ + cat << 'EOFT' > "$bgScript_FPath" +#!/bin/sh +# Script to check for system loggers (created by Scribe) +# +set -u + +readonly scriptFName="${0##*/}" +readonly TEMP_DIR="/tmp/var/tmp" +readonly logDateTime="%Y-%b-%d %I:%M:%S %p %Z" +readonly logFilePath="${TEMP_DIR}/${scriptFName%.*}.LOG" + +export PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH" + +_LogDebugMsg_() +{ + local timeNow="$(date +"$logDateTime")" + if [ $# -gt 1 ] && [ "$2" = "_START_" ] + then echo "${timeNow}: $1" > "$logFilePath" + else echo "${timeNow}: $1" >> "$logFilePath" + fi +} + +trap '' HUP + +_LogDebugMsg_ "Start of Background Script [$scriptFName][$$]" _START_ + +readyOK=false +klogdEXIT=false +syslogdEXIT=false + +tryCount=0 +maxCount=30 + +while true +do + usleep 500000 #0.5 sec# + [ -z "$(pidof klogd)" ] && klogdEXIT=true + [ -z "$(pidof syslogd)" ] && syslogdEXIT=true + if "$klogdEXIT" && "$syslogdEXIT" + then + _LogDebugMsg_ "System loggers [klogd & syslogd] were terminated." + _LogDebugMsg_ "Exiting Background Loop [$tryCount][$$]..." + break + fi + if [ "$tryCount" -gt "$maxCount" ] + then + _LogDebugMsg_ "Exiting Background Loop [$tryCount][$$]..." + break #Something went wrong# + fi + [ -n "$(pidof klogd)" ] && killall -q klogd + [ -n "$(pidof syslogd)" ] && killall -q syslogd + + _LogDebugMsg_ "Sleeping [$tryCount][$$]..." + sleep 1 + tryCount="$((tryCount + 1))" +done + +_LogDebugMsg_ "End of Background Script [$scriptFName][$$]" +rm -f "$0" + +#EOF# +EOFT + + chmod a+x "$bgScript_FPath" +} + +##-------------------------------------## +## Added by Martinski W. [2026-Jan-10] ## +##-------------------------------------## +_Launch_SysLoggerCheck_BGScript_() +{ + local taskPID logTag="${script_name}_$$" + local bgScript_FName="scribe_SysLogger_Check.sh" + local bgScript_FPath="${TEMPdir}/$bgScript_FName" + + if [ -s "$bgScript_FPath" ] && \ + [ -x "$bgScript_FPath" ] && \ + [ -n "$(pidof "$bgScript_FName")" ] + then + logger -st "$logTag" -p 4 "INFO: Script [$bgScript_FName] is already running..." + return 1 + fi + + _Create_SysLoggerCheck_BGScript_ + + if [ ! -s "$bgScript_FPath" ] || [ ! -x "$bgScript_FPath" ] + then + logger -st "$logTag" -p 3 "**ERROR**: Script [$bgScript_FPath] NOT found." + return 1 + fi + + "$bgScript_FPath" & taskPID=$! + logger -st "$logTag" -p 5 "INFO: Background script [$bgScript_FName] started. PID: [$taskPID]" +} + ##----------------------------------------## ## Modified by Martinski W. [2024-Jul-07] ## ##----------------------------------------## @@ -2183,46 +2503,57 @@ Utils_Menu() } ##----------------------------------------## -## Modified by Martinski W. [2025-Jan-04] ## +## Modified by Martinski W. [2026-Jan-11] ## ##----------------------------------------## Main_Menu() { - and_lr=" & $lr cron" if SyslogNg_Running then - res="Res" - ins="Rei" + resPrefix="Res" + insPrefix="Rei" else - res="S" - ins="I" + resPrefix="S" + if [ ! -f "$syslogNg_WaitnSEM_FPath" ] + then insPrefix="I" + else insPrefix="Rei" + fi fi + andLRcron="& $lr cron" + if "$scribeInstalled" then + if ! SyslogNg_Running && [ -f "$syslogNg_WaitnSEM_FPath" ] + then + _ShowSysLogNg_WaitStart_Msge_ + fi printf " ${GRNct}s${CLRct}. Show %s status\n" "$script_name" if SyslogNg_Running then printf " ${GRNct}rl${CLRct}. Reload %s.conf\n" "$sng" + printf " ${GRNct}lr${CLRct}. Run logrotate now\n" fi - printf " ${GRNct}lr${CLRct}. Run logrotate now\n" - printf " ${GRNct}rs${CLRct}. %start %s" "$res" "$sng" - if ! SyslogNg_Running + if SyslogNg_Running || [ ! -f "$syslogNg_WaitnSEM_FPath" ] then - printf "${and_lr}\n" - else - printf "\n ${GRNct}st${CLRct}. Stop %s${and_lr}" "$sng" - printf "\n ${GRNct}ct${CLRct}. Set $lr cron job run frequency\n" + printf " ${GRNct}rs${CLRct}. %s %s " "${resPrefix}tart" "$sng" + SyslogNg_Running && echo || printf "${andLRcron}\n" fi if SyslogNg_Running then - echo + printf " ${GRNct}st${CLRct}. Stop %s ${andLRcron}\n" "$sng" + printf " ${GRNct}ct${CLRct}. Set $lr cron job run frequency\n\n" printf " ${GRNct}u${CLRct}. Check for script updates\n" printf " ${GRNct}uf${CLRct}. Force update %s with latest version\n" "$script_name" printf " ${GRNct}ft${CLRct}. Update filters\n" fi - printf " ${GRNct}su${CLRct}. %s utilities\n" "$script_name" + if [ -f "$syslogNg_WaitnSEM_FPath" ] + then + echo + else + printf " ${GRNct}su${CLRct}. %s utilities\n\n" "$script_name" + fi fi - printf " ${GRNct}e${CLRct}. Exit %s\n\n" "$script_name" - printf " ${GRNct}is${CLRct}. %snstall %s\n" "$ins" "$script_name" + printf " ${GRNct}e${CLRct}. Exit %s\n" "$script_name" + printf " ${GRNct}is${CLRct}. %s %s\n" "${insPrefix}nstall" "$script_name" printf " ${GRNct}zs${CLRct}. Remove %s\n" "$script_name" } @@ -2262,7 +2593,7 @@ Scribe_Menu() rl) if SyslogNg_Running then - rld_sngconf + Reload_sngconf else not_recog=true fi @@ -2278,13 +2609,13 @@ Scribe_Menu() fi ;; rs) - menu_restart + Menu_Restart Menu_Status ;; st) if SyslogNg_Running then - menu_stop + Menu_Stop else not_recog=true fi @@ -2307,7 +2638,7 @@ Scribe_Menu() ft) if SyslogNg_Running then - menu_filters + Menu_Filters else not_recog=true fi @@ -2323,16 +2654,16 @@ Scribe_Menu() menu_restore ;; d) - gather_debug + Gather_Debug printf "\n$white Would you like to review the debug data (opens in less)? [y|n] $std" if yes_no; then pause=false; less "$script_debug"; fi ;; c) - show_config + SysLogNg_ShowConfig pause=false ;; rd) - create_conf + Create_Config ;; lc) if SyslogNg_Running @@ -2347,7 +2678,7 @@ Scribe_Menu() menu_forgrnd ;; ld) - dlt "$lr_temp" + delfr "$lr_temp" if _AcquireFLock_ then _DoRotateLogFiles_ DEBUG TEMP @@ -2389,7 +2720,7 @@ Scribe_Menu() fi if "$do_inst" then - pre_install + PreInstall_Check Get_ZIP_File Menu_Install sh "$script_loc" status nologo @@ -2434,25 +2765,26 @@ then sysLogFiFoSizeMIN=2048 else sysLogFiFoSizeMIN=1024 fi -if ! SyslogDm_Running && ! SyslogNg_Running +if ! SyslogD_Running && ! SyslogNg_Running && \ + ! "$usbUnmountCaller" && [ "$action" != "SysLoggerCheck" ] then - printf "\n\n${red} *WARNING*: $white No system logger was running!!\n" - printf "Starting system loggers ..." - start_syslogd + printf "\n\n ${red}*WARNING*${white}: No system logger was running!!${std}\n" + printf "Starting system loggers (klogd and syslogd)..." + Start_SyslogD fi if [ "$action" != "help" ] && \ [ "$action" != "about" ] then - # read or create config file # - read_conf + # Read or create config file # + Read_Config fi if [ "$action" = "menu" ] then menu_type="main" Scribe_Menu -elif ! echo "$action" | grep -q '^LogRotate' +elif ! echo "$action" | grep -qE '^(LogRotate|SysLog)' then ScriptLogo fi @@ -2477,7 +2809,7 @@ case "$action" in printf " Please use menu command 'is' to reinstall. ${std}\n\n" exit 1 fi - pre_install + PreInstall_Check Get_ZIP_File Menu_Install sh "$script_loc" status nologo @@ -2508,7 +2840,9 @@ case "$action" in show-config | config) if "$scribeInstalled" then - if show_config; then sng_syntax; fi + if SysLogNg_ShowConfig + then SysLogNg_Config_SyntaxCheck + fi fi ;; @@ -2522,7 +2856,7 @@ case "$action" in #reload syslog-ng configuration# reload) if SyslogNg_Running - then rld_sngconf + then Reload_sngconf fi ;; @@ -2530,15 +2864,15 @@ case "$action" in restart | start) if "$scribeInstalled" then - menu_restart + Menu_Restart Menu_Status fi ;; #stop syslog-ng & logrotate cron job# stop) - if SyslogNg_Running - then menu_stop + if SyslogNg_Running || "$usbUnmountCaller" + then Menu_Stop fi ;; @@ -2555,7 +2889,7 @@ case "$action" in LogRotateDebug) if _AcquireFLock_ then - dlt "$lr_temp" + delfr "$lr_temp" _DoRotateLogFiles_ DEBUG TEMP _ReleaseFLock_ more "$lr_temp" @@ -2569,20 +2903,31 @@ case "$action" in #generate debug tarball# debug) if "$scribeInstalled" - then gather_debug + then Gather_Debug fi ;; #update syslog-ng and logrotate filters - only used in update process# filters) if SyslogNg_Running - then menu_filters + then Menu_Filters fi ;; - #kill syslogd & klogd - only available via CLI# + SysLoggerCheck) + _Launch_SysLoggerCheck_BGScript_ + exit 0 + ;; + + SysLogNgStartDelay) + _Launch_SysLogNgStartDelay_BGScript_ + exit 0 + ;; + + #Kill syslogd & klogd - only available via CLI# service_event) if ! SyslogNg_Running || [ "$2" = "stop" ] || \ + [ "$2" = "reboot" ] || [ "$3" = "ntpd" ] || \ echo "$3" | grep -qE "^$uiscribeName" then exit 0 fi @@ -2596,13 +2941,13 @@ case "$action" in lastTimeSecs="$(_ServiceEventTime_ check)" thisTimeDiff="$(echo "$currTimeSecs $lastTimeSecs" | awk -F ' ' '{printf("%s", $1 - $2);}')" - #Only once every 15 minutes at most# - if [ "$thisTimeDiff" -ge 900 ] + #Only once every 20 minutes at most# + if [ "$thisTimeDiff" -ge 1200 ] then _ServiceEventTime_ update "$currTimeSecs" . "$rcfunc_loc" kill_logger false - sync_conf + SysLogNg_Config_Sync _ServiceEventTime_ update "$(date +'%s')" else exit 1 From 7a683d3ce45f1673efe92fc9542f41792595a654 Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Tue, 13 Jan 2026 00:12:43 -0800 Subject: [PATCH 07/12] Code Improvements Code improvements and fine-tuning. --- README.md | 2 +- scribe.sh | 54 ++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index bcdead4..edd8fd6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **scribe** is a **syslog-ng** and **logrotate** installer for ASUS routers running **Asuswrt-Merlin** ## v3.2.7 -### Updated on 2026-Jan-11 +### Updated on 2026-Jan-12 ## Getting Started diff --git a/scribe.sh b/scribe.sh index 8f8dc9a..fb58dec 100644 --- a/scribe.sh +++ b/scribe.sh @@ -18,7 +18,7 @@ # curl --retry 3 "https://raw.githubusercontent.com/AMTM-OSR/scribe/master/scribe.h" -o "/jffs/scripts/scribe" && chmod 0755 /jffs/scripts/scribe && /jffs/scripts/scribe install # ################################################################## -# Last Modified: 2026-Jan-11 +# Last Modified: 2026-Jan-12 #----------------------------------------------------------------- ################ Shellcheck directives ################ @@ -35,7 +35,7 @@ readonly script_name="scribe" readonly scribe_ver="v3.2.7" -readonly scriptVer_TAG="26011122" +readonly scriptVer_TAG="26011223" scribe_branch="develop" script_branch="$scribe_branch" @@ -644,11 +644,35 @@ Reload_sngconf() Copy_rcfunc() { printf "$white copying %s to %s ...$std" "$rcfunc_sng" "$init_d" - cp -pf "$unzip_dirPath/init.d/$rcfunc_sng" "$init_d/" + cp -fp "${unzip_dirPath}/init.d/$rcfunc_sng" "$init_d/" chmod 644 "$rcfunc_loc" finished } +##-------------------------------------## +## Added by Martinski W. [2026-Jan-12] ## +##-------------------------------------## +Copy_LogRotate_Global_Config() +{ + local forceUpdate=false + local srceFile="${unzip_dirPath}/${logRotateStr}.d/$logRotateGlobalName" + + [ ! -s "$srceFile" ] && return 1 + [ ! -d "$logRotateExamplesDir" ] && mkdir "$logRotateExamplesDir" + if [ $# -gt 0 ] && [ "$1" = "force" ] + then forceUpdate=true + fi + + for destFile in "$logRotateGlobalConf" "${logRotateExamplesDir}/$logRotateGlobalName" + do + if [ ! -s "$destFile" ] || "$forceUpdate" + then + cp -fp "$srceFile" "$destFile" 2>/dev/null + chmod 600 "$destFile" + fi + done +} + ##-------------------------------------## ## Added by Martinski W. [2026-Jan-11] ## ##-------------------------------------## @@ -1146,22 +1170,23 @@ prt_vers() printf "$std\n\n" } -# Install default file in /usr/etc/$1.d # +# Install default file in /opt/etc/$1.d # setup_ddir() { [ "$1" = "$sng" ] && d_dir="$sngd_d" [ "$1" = "$lr" ] && d_dir="$lrd_d" - for dfile in "$unzip_dirPath/${1}.d"/* + for dfile in "${unzip_dirPath}/${1}.d"/* do dfbase="$( strip_path "$dfile" )" ddfile="$d_dir/$dfbase" - { [ ! -e "$ddfile" ] || [ "$2" = "ALL" ]; } && cp -p "$dfile" "$ddfile" + { [ ! -e "$ddfile" ] || [ "$2" = "ALL" ]; } && \ + cp -p "$dfile" "$ddfile" done chmod 600 "$d_dir"/* } -# Install example files in /usr/share/$1/examples # +# Install example files in /opt/share/$1/examples # setup_exmpls() { [ "$1" = "$sng" ] && share="$sng_share" && conf="$sng_conf" @@ -1173,7 +1198,7 @@ setup_exmpls() [ ! -d "$share" ] && mkdir "$share" [ ! -d "$share/examples" ] && mkdir "$share/examples" - for exmpl in "$unzip_dirPath/${1}.share"/* + for exmpl in "${unzip_dirPath}/${1}.share"/* do shrfile="$share/examples/$( strip_path "$exmpl" )" if [ ! -e "$shrfile" ] || [ "$2" = "ALL" ] @@ -1938,10 +1963,10 @@ Menu_Filters() fi done done - printf "\n$white %s and %s example files updated!$std\n" "$sng" "$lr" + printf "\n ${white}%s and %s example files updated!${std}\n" "$sng" "$lr" Reload_sngconf else - printf "\n$white %s and %s example files$red not$white updated!$std\n" "$sng" "$lr" + printf "\n ${white}%s and %s example files ${red}not${white} updated!${std}\n" "$sng" "$lr" fi } @@ -1971,11 +1996,12 @@ Menu_Update() fi fi - if { [ $# -eq 1 ] && [ "$1" = "force" ] ; } || yes_no + if { [ $# -gt 0 ] && [ "$1" = "force" ] ; } || yes_no then Get_ZIP_File Setup_Scribe "NEWER" Copy_rcfunc + Copy_LogRotate_Global_Config "$@" printf "\n$white %s updated!$std\n" "$script_name" sh "$script_loc" filters gotzip nologo sh "$script_loc" status nologo @@ -2924,10 +2950,10 @@ case "$action" in exit 0 ;; - #Kill syslogd & klogd - only available via CLI# + #Kill syslogd & klogd# service_event) - if ! SyslogNg_Running || [ "$2" = "stop" ] || \ - [ "$2" = "reboot" ] || [ "$3" = "ntpd" ] || \ + if ! SyslogNg_Running || [ -z "$2" ] || \ + [ "$2" = "stop" ] || [ "$3" = "ntpd" ] || \ echo "$3" | grep -qE "^$uiscribeName" then exit 0 fi From 836a249b9f1d6ec554a976db45340c91cd86f3ed Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Thu, 15 Jan 2026 18:36:39 -0800 Subject: [PATCH 08/12] Update syslog-ng.conf-scribe --- syslog-ng.share/syslog-ng.conf-scribe | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/syslog-ng.share/syslog-ng.conf-scribe b/syslog-ng.share/syslog-ng.conf-scribe index ef2fc10..e00d53e 100644 --- a/syslog-ng.share/syslog-ng.conf-scribe +++ b/syslog-ng.share/syslog-ng.conf-scribe @@ -28,23 +28,23 @@ source src { unix-dgram("/dev/log" so_rcvbuf(65536) flags(syslog-protocol)); file("/proc/kmsg" program_override("kernel") flags(kernel)); internal(); -# udp(ip(192.168.x.y) port(514)); # uncomment this line to pass all network messages through syslog-ng filters +#OFF# udp(ip(192.168.x.y) port(514)); # uncomment this line to pass all network messages through syslog-ng filters }; # if you only want to pass network messages through some syslog-ng filters, uncomment the source line below # then add "source(net);" to the log statement in any filter you want to pass network messages through -#source net { udp(ip(192.168.x.y) port(514)); }; +#OFF# source net { udp(ip(192.168.x.y) port(514)); }; # set the filename for the default log file - anything not filtered out will end up here destination messages { file("/opt/var/log/messages"); }; # to send log messages to the local network, uncomment the destination line below # then add "destination(log_server);" to the log statement in any filter you want to pass network messages through -#destination log_server { udp("192.168.x.y" port(514)); }; +#OFF# destination log_server { udp("192.168.x.y" port(514)); }; log { source(src); -# source(net); # uncomment this and "source net" function above to get udp log messages from local network +#OFF# source(net); # uncomment this and "source net" function above to get udp log messages from local network destination(messages); -# destination(log_server); # uncomment this and "destination log_server" function above to send udp log messages to local network +#OFF# destination(log_server); # uncomment this and "destination log_server" function above to send udp log messages to local network }; From 8f9f93ec9e9c1b0c03c0c6ff67e06752153dca08 Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Thu, 15 Jan 2026 18:41:33 -0800 Subject: [PATCH 09/12] Update rc.func.syslog-ng --- init.d/rc.func.syslog-ng | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.d/rc.func.syslog-ng b/init.d/rc.func.syslog-ng index 743095e..6784b24 100644 --- a/init.d/rc.func.syslog-ng +++ b/init.d/rc.func.syslog-ng @@ -1,7 +1,7 @@ #!/bin/sh - # # NB: rc.func only runs PRECMD on "start" -# Last Modified: 2026-Jan-11 +# Last Modified: 2026-Jan-15 # VERSION="3.1.3" #------------------------------------------- @@ -16,7 +16,7 @@ catCmd="$(which -a cat | $grepCmd -v '^/opt/')" cutCmd="$(which -a cut | $grepCmd -v '^/opt/')" pidofCmd="$(which -a pidof | $grepCmd -v '^/opt/')" loggerCmd="$(which -a logger | $grepCmd -v '^/opt/')" -logTagStr="Scribe:kill_logger[$$]" +logTagStr="scribe:kill_logger[$$]" logPrioNum="-p 4" ##----------------------------------------## From 7be7e4ff93643d725ee5ac0022ad6efab17aa4eb Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Fri, 16 Jan 2026 00:28:52 -0800 Subject: [PATCH 10/12] Code Improvements and Fine-Tuning More code improvements and fine-tuning. --- README.md | 2 +- scribe.sh | 145 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 92 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index edd8fd6..ed41f4b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **scribe** is a **syslog-ng** and **logrotate** installer for ASUS routers running **Asuswrt-Merlin** ## v3.2.7 -### Updated on 2026-Jan-12 +### Updated on 2026-Jan-16 ## Getting Started diff --git a/scribe.sh b/scribe.sh index fb58dec..22eba00 100644 --- a/scribe.sh +++ b/scribe.sh @@ -18,7 +18,7 @@ # curl --retry 3 "https://raw.githubusercontent.com/AMTM-OSR/scribe/master/scribe.h" -o "/jffs/scripts/scribe" && chmod 0755 /jffs/scripts/scribe && /jffs/scripts/scribe install # ################################################################## -# Last Modified: 2026-Jan-12 +# Last Modified: 2026-Jan-15 #----------------------------------------------------------------- ################ Shellcheck directives ################ @@ -35,7 +35,7 @@ readonly script_name="scribe" readonly scribe_ver="v3.2.7" -readonly scriptVer_TAG="26011223" +readonly scriptVer_TAG="26011523" scribe_branch="develop" script_branch="$scribe_branch" @@ -182,7 +182,7 @@ readonly logRotateCmd="/opt/sbin/$logRotateStr" readonly logRotateDir="/opt/etc/${logRotateStr}.d" readonly logRotateShareDir="/opt/share/$logRotateStr" readonly logRotateExamplesDir="${logRotateShareDir}/examples" -readonly logRotateTopConf="/opt/etc/${logRotateStr}.conf" +readonly logRotateTopConfig="/opt/etc/${logRotateStr}.conf" readonly logRotateGlobalName="A01global" readonly logRotateGlobalConf="${logRotateDir}/$logRotateGlobalName" readonly LR_FLock_FD=513 @@ -190,6 +190,10 @@ readonly LR_FLock_FName="/tmp/scribeLogRotate.flock" readonly logFilesRegExp="${optVarLogDir}/.*([.]log)?" readonly filteredLogList="${config_d}/.filteredlogs" readonly noConfigLogList="${config_d}/.noconfiglogs" +readonly syslogNg_ShareDir="/opt/share/$syslogNgStr" +readonly syslogNg_ExamplesDir="${syslogNg_ShareDir}/examples" +readonly syslogNg_ConfName=${syslogNgStr}.conf +readonly syslogNg_TopConfig="/opt/etc/$syslogNg_ConfName" readonly syslogNg_WaitnSEM_FPath="${TEMPdir}/scribe_SysLogNg.WAITN.SEM" readonly syslogNg_StartSEM_FPath="${TEMPdir}/scribe_SysLogNg.START.SEM" readonly sysLogLinesMAX=20480 @@ -264,7 +268,7 @@ updated(){ printf "$yellow updated. $std\n"; } finished(){ printf "$green done. $std\n"; } -not_installed(){ printf "\n$blue %s$red NOT$white installed! $std\n" "$1"; } +not_installed(){ printf "\n ${blue}%s ${red}NOT${white} installed!${std}\n" "$1"; } PressEnterTo() { printf "$white Press key to %s $std" "$1"; read -rs inputKey; echo; } @@ -523,7 +527,7 @@ Read_Config() ##----------------------------------------## ## Modified by Martinski W. [2025-Aug-23] ## ##----------------------------------------## -update_file() +Update_File() { if [ $# -gt 2 ] && [ "$3" = "backup" ] then date_stamp "$2" @@ -531,8 +535,7 @@ update_file() cp -fp "$1" "$2" } -# Check Yes or No # -yes_no() +Yes_Or_No() { read -r resp case "$resp" in @@ -633,7 +636,7 @@ Restart_uiScribe() fi } -Reload_sngconf() +Reload_SysLogNg_Config() { printf "$white reloading %s ... $cyan" "$( strip_path $sng_conf )" $sngctl_loc reload @@ -641,7 +644,7 @@ Reload_sngconf() Restart_uiScribe } -Copy_rcfunc() +Copy_SysLogNg_RcFunc() { printf "$white copying %s to %s ...$std" "$rcfunc_sng" "$init_d" cp -fp "${unzip_dirPath}/init.d/$rcfunc_sng" "$init_d/" @@ -649,16 +652,40 @@ Copy_rcfunc() finished } +##-------------------------------------## +## Added by Martinski W. [2026-Jan-15] ## +##-------------------------------------## +Copy_SysLogNg_Top_Config() +{ + local forceUpdate=false + local srceFile="${unzip_dirPath}/${syslogNgStr}.share/${syslogNg_ConfName}-scribe" + + [ ! -s "$srceFile" ] && return 1 + [ ! -d "$syslogNg_ExamplesDir" ] && mkdir -p "$syslogNg_ExamplesDir" + if [ $# -gt 0 ] && [ "$1" = "force" ] + then forceUpdate=true + fi + + for destFile in "$syslogNg_TopConfig" "${syslogNg_ExamplesDir}/${syslogNg_ConfName}-scribe" + do + if [ ! -s "$destFile" ] || "$forceUpdate" + then + cp -fp "$srceFile" "$destFile" + chmod 644 "$destFile" + fi + done +} + ##-------------------------------------## ## Added by Martinski W. [2026-Jan-12] ## ##-------------------------------------## -Copy_LogRotate_Global_Config() +Copy_LogRotate_Global_Options() { local forceUpdate=false local srceFile="${unzip_dirPath}/${logRotateStr}.d/$logRotateGlobalName" [ ! -s "$srceFile" ] && return 1 - [ ! -d "$logRotateExamplesDir" ] && mkdir "$logRotateExamplesDir" + [ ! -d "$logRotateExamplesDir" ] && mkdir -p "$logRotateExamplesDir" if [ $# -gt 0 ] && [ "$1" = "force" ] then forceUpdate=true fi @@ -667,7 +694,7 @@ Copy_LogRotate_Global_Config() do if [ ! -s "$destFile" ] || "$forceUpdate" then - cp -fp "$srceFile" "$destFile" 2>/dev/null + cp -fp "$srceFile" "$destFile" chmod 600 "$destFile" fi done @@ -1203,17 +1230,17 @@ setup_exmpls() shrfile="$share/examples/$( strip_path "$exmpl" )" if [ ! -e "$shrfile" ] || [ "$2" = "ALL" ] then - update_file "$exmpl" "$shrfile" + Update_File "$exmpl" "$shrfile" elif ! same_same "$exmpl" "$shrfile" then printf " updating %s\n" "$shrfile" - update_file "$exmpl" "$shrfile" + Update_File "$exmpl" "$shrfile" fi done if [ -e "$conf_opkg" ] then - update_file "$conf_opkg" "$share/examples/$opkg" "backup" + Update_File "$conf_opkg" "$share/examples/$opkg" "backup" delfr "$conf_opkg" elif [ ! -e "$share/examples/$opkg" ] then @@ -1235,10 +1262,13 @@ Force_Install() printf "\n$blue %s$white already installed!\n" "$1" [ "$1" != "$script_name" ] && printf "$yellow Forcing installation$red WILL OVERWRITE$yellow any modified configuration files!\n" printf "$white Do you want to force re-installation of %s [y|n]? $std" "$1" - yes_no + Yes_Or_No return $? } +##----------------------------------------## +## Modified by Martinski W. [2026-Jan-15] ## +##----------------------------------------## SysLogNg_ShowConfig() { if [ -e "$sng_loc" ] @@ -1247,22 +1277,28 @@ SysLogNg_ShowConfig() delfr "$sngconf_error" if $sng_loc --preprocess-into="$sngconf_merged" 2> "$sngconf_error" then - less "$sngconf_merged" + printf "\n\n" ; more "$sngconf_merged" else - less "$sngconf_error" + printf "\n\n" ; more "$sngconf_error" fi - true + echo ; PressEnterTo "continue..." + return 0 else not_installed "$sng" - false + echo ; PressEnterTo "continue..." + return 1 fi } -show_loaded() +##----------------------------------------## +## Modified by Martinski W. [2026-Jan-15] ## +##----------------------------------------## +Show_SysLogNg_LoadedConfig() { delfr "$sngconf_merged" $sngctl_loc config --preprocessed > "$sngconf_merged" - less "$sngconf_merged" + printf "\n\n" ; more "$sngconf_merged" + echo ; PressEnterTo "continue..." } ##-------------------------------------## @@ -1380,6 +1416,7 @@ _DoPostRotateCleanup_() else cp -fp "${logRotateExamplesDir}/$logRotateGlobalName" "$logRotateGlobalConf" fi + chmod 600 "$logRotateGlobalConf" } ##-------------------------------------## @@ -1407,7 +1444,7 @@ _RotateAllLogFiles_Preamble_() then return 1 fi cp -fp "${logRotateExamplesDir}/$logRotateGlobalName" "$logRotateGlobalConf" - chmod 644 "$logRotateGlobalConf" + chmod 600 "$logRotateGlobalConf" fi cp -fp "$logRotateGlobalConf" "${config_d}/${logRotateGlobalName}.SAVED" @@ -1450,13 +1487,13 @@ _DoRotateLogFiles_() if [ "$callType" != "DEBUG" ] then rm -f "$lr_daily" - $logRotateCmd "$logRotateTopConf" >> "$lr_daily" 2>&1 + $logRotateCmd "$logRotateTopConfig" >> "$lr_daily" 2>&1 else if [ $# -gt 1 ] && [ "$2" = "TEMP" ] then debugLog="$lr_temp" else debugLog="$script_debug" fi - $logRotateCmd -d "$logRotateTopConf" >> "$debugLog" 2>&1 + $logRotateCmd -d "$logRotateTopConfig" >> "$debugLog" 2>&1 fi if [ "$callType" = "DORUN" ] @@ -1508,14 +1545,14 @@ sng_ver_chk() Setup_SysLogNG() { printf "\n$magenta setting up %s ...\n$std" "$sng" - Copy_rcfunc + Copy_SysLogNg_RcFunc sed_SysLogNg_Init sed_srvcEvent sed_unMount if [ "$( md5_file "$sng_share/examples/${sng}.conf-scribe" )" != "$( md5_file "$sng_conf" )" ] then printf "$white %34s" "updating $( strip_path "$sng_conf" ) ..." - update_file "$sng_share/examples/${sng}.conf-scribe" "$sng_conf" "backup" + Update_File "$sng_share/examples/${sng}.conf-scribe" "$sng_conf" "backup" finished fi SysLogNg_Config_Sync @@ -1593,7 +1630,7 @@ Install_uiScribe() printf "\n$white Would you like to install$cyan %s %s$white, a script by Jack Yaz\n" "$uiscribeName" "$uiscribeVer" printf " that modifies the webui$yellow System Log$white page to show the various logs\n" printf " generated by %s in individual drop-down windows [y|n]? " "$sng" - if yes_no + if Yes_Or_No then printf "\n" curl -LSs --retry 4 --retry-delay 5 --retry-connrefused "$uiscribeRepo" -o "$uiscribePath" && \ @@ -1669,7 +1706,7 @@ PreInstall_Check() if "$reqsOK" then printf " Do you want to continue installation of %s [y|n]? $std" "$script_name" - if ! yes_no + if ! Yes_Or_No then reqsOK=false fi @@ -1726,7 +1763,7 @@ Menu_Install() Setup_Scribe "ALL" fi - Reload_sngconf + Reload_SysLogNg_Config printf "\n$white %s setup complete!\n\n" "$script_name" PressEnterTo "continue..." if ! "$uiScribeInstalled" @@ -1920,7 +1957,7 @@ Menu_Filters() printf "$yellow If you are unsure, you should answer 'y' here; any changes to\n" printf " the running configuration will require confirmation.\n\n" printf "$white Update filter files? [y|n] $std" - if yes_no + if Yes_Or_No then Get_ZIP_File for pckg in $sng $lr @@ -1942,7 +1979,7 @@ Menu_Filters() read -r dispo case "$dispo" in a) - update_file "$comp_file" "$upd_file" + Update_File "$comp_file" "$upd_file" printf "\n$green %s updated!$std\n" "$upd_file" processed=true ;; @@ -1964,7 +2001,7 @@ Menu_Filters() done done printf "\n ${white}%s and %s example files updated!${std}\n" "$sng" "$lr" - Reload_sngconf + Reload_SysLogNg_Config else printf "\n ${white}%s and %s example files ${red}not${white} updated!${std}\n" "$sng" "$lr" fi @@ -1996,12 +2033,13 @@ Menu_Update() fi fi - if { [ $# -gt 0 ] && [ "$1" = "force" ] ; } || yes_no + if { [ $# -gt 0 ] && [ "$1" = "force" ] ; } || Yes_Or_No then Get_ZIP_File Setup_Scribe "NEWER" - Copy_rcfunc - Copy_LogRotate_Global_Config "$@" + Copy_SysLogNg_RcFunc + Copy_SysLogNg_Top_Config "$@" + Copy_LogRotate_Global_Options "$@" printf "\n$white %s updated!$std\n" "$script_name" sh "$script_loc" filters gotzip nologo sh "$script_loc" status nologo @@ -2037,7 +2075,7 @@ menu_forgrnd() printf " Debugging mode is intended for troubleshooting when\n" printf " %s will not start.\n\n" "$sng" printf " Are you certain you wish to start debugging mode [y|n]? $std" - if ! yes_no; then return; fi + if ! Yes_Or_No; then return; fi restrt=true fi printf "\n$yellow NOTE: If there are no errors, debugging mode will\n" @@ -2512,7 +2550,7 @@ Utils_Menu() printf " ${GRNct}rt${CLRct}. Restore configuration files\n\n" printf " ${GRNct}d${CLRct}. Generate debug file\n" printf " ${GRNct}rd${CLRct}. Re-detect syslog.log location\n" - printf " ${GRNct}c${CLRct}. Check on-disk %s config\n" "$sng" + printf " ${GRNct}ck${CLRct}. Check on-disk %s config\n" "$sng" if SyslogNg_Running then printf " ${GRNct}lc${CLRct}. Show loaded %s config\n" "$sng" @@ -2619,7 +2657,7 @@ Scribe_Menu() rl) if SyslogNg_Running then - Reload_sngconf + Reload_SysLogNg_Config else not_recog=true fi @@ -2682,9 +2720,9 @@ Scribe_Menu() d) Gather_Debug printf "\n$white Would you like to review the debug data (opens in less)? [y|n] $std" - if yes_no; then pause=false; less "$script_debug"; fi + if Yes_Or_No; then pause=false; less "$script_debug"; fi ;; - c) + ck) SysLogNg_ShowConfig pause=false ;; @@ -2694,7 +2732,7 @@ Scribe_Menu() lc) if SyslogNg_Running then - show_loaded + Show_SysLogNg_LoadedConfig pause=false else not_recog=true @@ -2709,9 +2747,9 @@ Scribe_Menu() then _DoRotateLogFiles_ DEBUG TEMP _ReleaseFLock_ - more "$lr_temp" ; echo + printf "\n\n" ; more "$lr_temp" + echo ; PressEnterTo "continue..." pause=false - PressEnterTo "continue..." else printf "\n${red} Unable to acquire lock to run logrotate.${std}\n" printf "\n${red} The program may be currently running.${std}\n\n" @@ -2862,7 +2900,7 @@ case "$action" in Update_Version force ;; - #show total combined config# + #Show total combined config# show-config | config) if "$scribeInstalled" then @@ -2872,21 +2910,20 @@ case "$action" in fi ;; - #verify syslog-ng is running and logrotate is listed in 'cru l'# + #Verify syslog-ng is running and logrotate Cron Job exists# status) if "$scribeInstalled" then Menu_Status fi ;; - #reload syslog-ng configuration# reload) if SyslogNg_Running - then Reload_sngconf + then Reload_SysLogNg_Config fi ;; - #restart (or start if not running) syslog-ng# + #Restart (or start if not running) syslog-ng# restart | start) if "$scribeInstalled" then @@ -2895,14 +2932,14 @@ case "$action" in fi ;; - #stop syslog-ng & logrotate cron job# + #Stop syslog-ng & logrotate Cron Job# stop) if SyslogNg_Running || "$usbUnmountCaller" then Menu_Stop fi ;; - # Calling logrotate via a cron Job ## + # Calling logrotate via a Cron Job ## LogRotate) if _AcquireFLock_ nonblock then @@ -2918,7 +2955,7 @@ case "$action" in delfr "$lr_temp" _DoRotateLogFiles_ DEBUG TEMP _ReleaseFLock_ - more "$lr_temp" + echo ; more "$lr_temp" ; echo else printf "\n${red} Unable to acquire lock to run logrotate.${std}\n" printf "\n${red} The program may be currently running.${std}\n\n" @@ -2926,14 +2963,14 @@ case "$action" in exit 0 ;; - #generate debug tarball# + #Generate Debug tarball# debug) if "$scribeInstalled" then Gather_Debug fi ;; - #update syslog-ng and logrotate filters - only used in update process# + #Update syslog-ng and logrotate filters - only used in update process# filters) if SyslogNg_Running then Menu_Filters From 4b35f0fa2add177688c21382e2e0b3eafa31f8b6 Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Mon, 19 Jan 2026 23:38:19 -0800 Subject: [PATCH 11/12] Removed "postrotate/endscript" directives Removed "postrotate/endscript" directive from each individual configuration file since that's already defined in the global set of configuration directives. --- logrotate.share/acsd | 3 --- logrotate.share/afpd | 3 --- logrotate.share/bcm63xx | 3 --- logrotate.share/bsd | 3 --- logrotate.share/crash | 3 --- logrotate.share/diversion | 4 +--- logrotate.share/ethernet | 4 +--- logrotate.share/hostapd | 3 --- logrotate.share/ioctl | 3 --- logrotate.share/jffs | 3 --- logrotate.share/meshUDB | 4 +--- logrotate.share/netdata | 3 --- logrotate.share/ntpd | 4 +--- logrotate.share/openvpn | 3 --- logrotate.share/pixelserv | 3 --- logrotate.share/roamast | 3 --- logrotate.share/spdmerlin | 4 +--- logrotate.share/suricata | 3 --- 18 files changed, 5 insertions(+), 54 deletions(-) diff --git a/logrotate.share/acsd b/logrotate.share/acsd index b89bd2e..ff28b8f 100644 --- a/logrotate.share/acsd +++ b/logrotate.share/acsd @@ -1,6 +1,3 @@ /opt/var/log/acsd.log { rotate 2 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/afpd b/logrotate.share/afpd index 43d11eb..87554e9 100644 --- a/logrotate.share/afpd +++ b/logrotate.share/afpd @@ -1,6 +1,3 @@ /opt/var/log/afpd.log { rotate 2 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/bcm63xx b/logrotate.share/bcm63xx index 867554a..46c11df 100644 --- a/logrotate.share/bcm63xx +++ b/logrotate.share/bcm63xx @@ -1,7 +1,4 @@ /opt/var/log/bcm63.log { monthly rotate 1 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/bsd b/logrotate.share/bsd index bf7913f..dc6ee59 100644 --- a/logrotate.share/bsd +++ b/logrotate.share/bsd @@ -1,6 +1,3 @@ /opt/var/log/bsd.log { rotate 2 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/crash b/logrotate.share/crash index d5c027d..e5c4a4d 100644 --- a/logrotate.share/crash +++ b/logrotate.share/crash @@ -1,7 +1,4 @@ /opt/var/log/crash.log { minsize 1024k daily - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/diversion b/logrotate.share/diversion index 4287d57..1b0e405 100644 --- a/logrotate.share/diversion +++ b/logrotate.share/diversion @@ -1,5 +1,3 @@ /opt/var/log/diversion.log { - postrotate - /usr/bin/killall -HUP syslog-ng - endscript + minsize 512k } diff --git a/logrotate.share/ethernet b/logrotate.share/ethernet index ed01914..5606c28 100644 --- a/logrotate.share/ethernet +++ b/logrotate.share/ethernet @@ -1,5 +1,3 @@ /opt/var/log/ethernet.log { - postrotate - /usr/bin/killall -HUP syslog-ng - endscript + minsize 512k } diff --git a/logrotate.share/hostapd b/logrotate.share/hostapd index 764e632..c6c6a96 100644 --- a/logrotate.share/hostapd +++ b/logrotate.share/hostapd @@ -1,6 +1,3 @@ /opt/var/log/hostapd.log { rotate 2 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/ioctl b/logrotate.share/ioctl index 88b229b..ece86d3 100644 --- a/logrotate.share/ioctl +++ b/logrotate.share/ioctl @@ -1,7 +1,4 @@ /opt/var/log/ioctl.log { monthly rotate 1 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/jffs b/logrotate.share/jffs index cca3746..43a7db7 100644 --- a/logrotate.share/jffs +++ b/logrotate.share/jffs @@ -2,7 +2,4 @@ minsize 1024k daily rotate 1 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/meshUDB b/logrotate.share/meshUDB index f6a168e..5c8e348 100644 --- a/logrotate.share/meshUDB +++ b/logrotate.share/meshUDB @@ -1,5 +1,3 @@ /opt/var/log/meshUDB.log { - postrotate - /usr/bin/killall -HUP syslog-ng - endscript + minsize 512k } diff --git a/logrotate.share/netdata b/logrotate.share/netdata index 1f4e419..b469cf6 100644 --- a/logrotate.share/netdata +++ b/logrotate.share/netdata @@ -2,7 +2,4 @@ minsize 1024k daily rotate 9 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/ntpd b/logrotate.share/ntpd index 3e5272f..c3091d5 100644 --- a/logrotate.share/ntpd +++ b/logrotate.share/ntpd @@ -1,5 +1,3 @@ /opt/var/log/ntp.log { - postrotate - /usr/bin/killall -HUP syslog-ng - endscript + minsize 512k } diff --git a/logrotate.share/openvpn b/logrotate.share/openvpn index 866b1a6..6f045b1 100644 --- a/logrotate.share/openvpn +++ b/logrotate.share/openvpn @@ -2,7 +2,4 @@ minsize 1024k daily rotate 9 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/pixelserv b/logrotate.share/pixelserv index e56eb01..3aef4af 100644 --- a/logrotate.share/pixelserv +++ b/logrotate.share/pixelserv @@ -2,7 +2,4 @@ minsize 1024K daily rotate 9 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/roamast b/logrotate.share/roamast index 36d3715..e6332f1 100644 --- a/logrotate.share/roamast +++ b/logrotate.share/roamast @@ -1,7 +1,4 @@ /opt/var/log/roamast.log { daily rotate 7 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } diff --git a/logrotate.share/spdmerlin b/logrotate.share/spdmerlin index 65e85aa..e0ea852 100644 --- a/logrotate.share/spdmerlin +++ b/logrotate.share/spdmerlin @@ -1,5 +1,3 @@ /opt/var/log/spdmerlin.log { - postrotate - /usr/bin/killall -HUP syslog-ng - endscript + minsize 512k } diff --git a/logrotate.share/suricata b/logrotate.share/suricata index db3d673..faa2044 100644 --- a/logrotate.share/suricata +++ b/logrotate.share/suricata @@ -2,7 +2,4 @@ minsize 1024k daily rotate 9 - postrotate - /usr/bin/killall -HUP syslog-ng - endscript } From 2b14cbd411c5b1ac0dc96e35607f44940c60df13 Mon Sep 17 00:00:00 2001 From: Martinski4GitHub <119833648+Martinski4GitHub@users.noreply.github.com> Date: Sat, 24 Jan 2026 23:10:22 -0800 Subject: [PATCH 12/12] Update README.md Updated date string. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed41f4b..ba7116a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **scribe** is a **syslog-ng** and **logrotate** installer for ASUS routers running **Asuswrt-Merlin** ## v3.2.7 -### Updated on 2026-Jan-16 +### Updated on 2026-Jan-24 ## Getting Started