From 761d00fcc8407fb2782a4851f6050446a3ec70ad Mon Sep 17 00:00:00 2001 From: lordjashin32 Date: Sat, 16 May 2020 00:25:39 -0400 Subject: [PATCH 1/6] no more writing to sdcard --- README.md | 5 +++-- _treehouses | 2 ++ modules/help.sh | 1 + modules/log2ram.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 modules/log2ram.sh diff --git a/README.md b/README.md index 5bba80c80..37602ddbe 100644 --- a/README.md +++ b/README.md @@ -126,9 +126,10 @@ log <0|1|2|3|4|show|max> gets/sets log level and shows log blocker <0|1|2|3|4||max> website blocking levels using /etc/hosts sdbench displays read and write speed of micro SD card inspire [joke|qotd|random] displays quote based on user input -shutdown [now|in|force] shutdown the system +shutdown [now|in|force] shutdown the system gpio displays raspberry pi model and corresponding GPIO ports -changelog [view|compare] displays the most recent changes to treehouses +changelog [view|compare] displays the most recent changes to treehouses +log2ram [on|off] force logs to be stored in ram and only writes to disk on shutdown ``` ## Additional README's diff --git a/_treehouses b/_treehouses index 59d6279aa..5d08916fb 100644 --- a/_treehouses +++ b/_treehouses @@ -198,6 +198,8 @@ treehouses log 4 treehouses log max treehouses log show treehouses log show 5 +treehouses log2ram off +treehouses log2ram on treehouses memory treehouses memory -g treehouses memory -m diff --git a/modules/help.sh b/modules/help.sh index da0081027..74a4e58a2 100644 --- a/modules/help.sh +++ b/modules/help.sh @@ -101,6 +101,7 @@ Usage: treehouses shutdown [now|in|force] shutdown the system gpio displays raspberry pi model and corresponding GPIO ports changelog displays the most recent changes to treehouses + log2ram [on|off] force logs to be stored in ram and only writes to disk on shutdown EOF echo "$helpdefault" } diff --git a/modules/log2ram.sh b/modules/log2ram.sh new file mode 100644 index 000000000..703cca287 --- /dev/null +++ b/modules/log2ram.sh @@ -0,0 +1,49 @@ +function log2ram { + checkrpi + checkroot + checkargn $# 1 + if [ "$1" = "" ]; then + if [[ $(df -h) != *"log2ram"* ]]; then + echo "log2ram is off" + else + echo "log2ram is on" + fi + elif [ "$1" = "on" ]; then + checkinternet + curl -s -Lo log2ram.tar.gz https://github.com/azlux/log2ram/archive/master.tar.gz &>"$LOGFILE" + tar xf log2ram.tar.gz &>"$LOGFILE" + rm log2ram.tar.gz + cd log2ram-master + chmod +x install.sh && ./install.sh &>"$LOGFILE" + cd .. + rm -r log2ram-master + echo "Successfully enabled log2ram, please reboot" + elif [ "$1" = "off" ]; then + if [ -f "/usr/local/bin/uninstall-log2ram.sh" ]; then + chmod +x /usr/local/bin/uninstall-log2ram.sh && /usr/local/bin/uninstall-log2ram.sh &>"$LOGFILE" + fi + echo "Sucessfully disabled log2ram" + else + log_and_exit1 "Error: only '', 'on', and 'off' options supported" + fi +} + +function log2ram_help { + echo + echo "Usage: $BASENAME log2ram [on|off]" + echo + echo "force logs to be stored in ram and only writes to disk on shutdown" + echo "https://github.com/azlux/log2ram" + echo "Stores logs in 40M (Megabytes) in mount point in memory" + echo + echo "Example:" + echo " $BASENAME log2ram" + echo " log2ram is off" + echo + echo " $BASENAME log2ram on" + echo " Successfully enabled log2ram, please reboot" + echo + echo " $BASENAME log2ram off" + echo " Successfully disabled log2ram" + echo +} From 4eeeb35ef292e9ab3aab7d6aa1103eb5bbb15905 Mon Sep 17 00:00:00 2001 From: lordjashin32 Date: Sat, 16 May 2020 00:29:39 -0400 Subject: [PATCH 2/6] add stub --- tests/log2ram.bats | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 tests/log2ram.bats diff --git a/tests/log2ram.bats b/tests/log2ram.bats new file mode 100755 index 000000000..e503118ff --- /dev/null +++ b/tests/log2ram.bats @@ -0,0 +1,3 @@ +#!/usr/bin/env bats +load test-helper +@test "$clinom log2ram (manually test w/out bats - requires reboots)" {} From 9f3e12cd9de34c0d2f269ec5b5592c8a816bd703 Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 16 May 2020 01:07:38 -0400 Subject: [PATCH 3/6] Update log2ram.sh --- modules/log2ram.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/log2ram.sh b/modules/log2ram.sh index 703cca287..e3b449c20 100644 --- a/modules/log2ram.sh +++ b/modules/log2ram.sh @@ -13,7 +13,7 @@ function log2ram { curl -s -Lo log2ram.tar.gz https://github.com/azlux/log2ram/archive/master.tar.gz &>"$LOGFILE" tar xf log2ram.tar.gz &>"$LOGFILE" rm log2ram.tar.gz - cd log2ram-master + cd log2ram-master || exit chmod +x install.sh && ./install.sh &>"$LOGFILE" cd .. rm -r log2ram-master From 521e7115ec2e10767d968427fbad51f793a37efa Mon Sep 17 00:00:00 2001 From: lordjashin32 Date: Mon, 18 May 2020 13:48:33 -0400 Subject: [PATCH 4/6] moved to log.sh --- README.md | 3 +-- _treehouses | 5 +++-- modules/help.sh | 3 +-- modules/log.sh | 46 ++++++++++++++++++++++++++++++++++++++++++- modules/log2ram.sh | 49 ---------------------------------------------- tests/log2ram.bats | 3 --- 6 files changed, 50 insertions(+), 59 deletions(-) delete mode 100644 modules/log2ram.sh delete mode 100755 tests/log2ram.bats diff --git a/README.md b/README.md index ab7d05549..bd1cc124c 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ cron [list|add|delete|deleteall] adds, deletes a custom cron job or del usb [on|off] turns usb ports on or off remote [check|status|upgrade|services] helps with treehouses remote android app [version|commands|allservices] -log <0|1|2|3|4|show|max> gets/sets log level and shows log +log [0|1|2|3|4|show|max|ram [on|off]] gets/sets log level and shows log blocker <0|1|2|3|4||max> website blocking levels using /etc/hosts sdbench displays read and write speed of micro SD card inspire [joke|qotd|random] displays quote based on user input @@ -131,7 +131,6 @@ convert converts audio and video files gpio displays raspberry pi model and corresponding GPIO ports changelog [view|compare] displays the most recent changes to treehouses shutdown [now|in|force] shutdown the system -log2ram [on|off] force logs to be stored in ram and only writes to disk on shutdown ``` ## Additional README's diff --git a/_treehouses b/_treehouses index 7381ee5f7..7b7220f7b 100644 --- a/_treehouses +++ b/_treehouses @@ -198,8 +198,9 @@ treehouses log 4 treehouses log max treehouses log show treehouses log show 5 -treehouses log2ram off -treehouses log2ram on +treehouses log ram +treehouses log ram on +treehouses log ram off treehouses memory treehouses memory -g treehouses memory -m diff --git a/modules/help.sh b/modules/help.sh index 7c6535e31..500ccab91 100644 --- a/modules/help.sh +++ b/modules/help.sh @@ -95,7 +95,7 @@ Usage: treehouses usb [on|off] turns usb ports on or off remote [check|status|upgrade|services] helps with treehouses remote android app [version|commands|allservices] - log <0|1|2|3|4|show|max> gets/sets log level and shows log + log [0|1|2|3|4|show|max|ram [on|off]] gets/sets log level and shows log blocker <0|1|2|3|4||max> website blocking levels using /etc/hosts sdbench displays read and write speed of micro SD card inspire [joke|qotd|random] displays quote based on user input @@ -103,7 +103,6 @@ Usage: treehouses gpio displays raspberry pi model and corresponding GPIO ports changelog displays the most recent changes to treehouses shutdown [now|in|force] shutdown the system - log2ram [on|off] force logs to be stored in ram and only writes to disk on shutdown EOF echo "$helpdefault" } diff --git a/modules/log.sh b/modules/log.sh index bf09e7c09..3017a02ca 100644 --- a/modules/log.sh +++ b/modules/log.sh @@ -1,3 +1,32 @@ +function log2ram { + checkrpi + checkargn $# 1 + if [ "$1" = "" ]; then + if [[ $(df -h) != *"log2ram"* ]]; then + echo "log2ram is off" + else + echo "log2ram is on" + fi + elif [ "$1" = "on" ]; then + checkinternet + curl -s -Lo log2ram.tar.gz https://github.com/azlux/log2ram/archive/master.tar.gz &>"$LOGFILE" + tar xf log2ram.tar.gz &>"$LOGFILE" + rm log2ram.tar.gz + cd log2ram-master || exit + chmod +x install.sh && ./install.sh &>"$LOGFILE" + cd .. + rm -r log2ram-master + echo "Successfully enabled log2ram, please reboot" + elif [ "$1" = "off" ]; then + if [ -f "/usr/local/bin/uninstall-log2ram.sh" ]; then + chmod +x /usr/local/bin/uninstall-log2ram.sh && /usr/local/bin/uninstall-log2ram.sh &>"$LOGFILE" + fi + echo "Sucessfully disabled log2ram" + else + log_and_exit1 "Error: only '', 'on', and 'off' options supported" + fi +} + # uses logger command to log to /var/log/syslog # logit "text" "whether or not to write to screen" "logging level" # e.g. logit "i logged some text" @@ -105,6 +134,9 @@ function log { LOG=max logit "log X: level set to max" "" "DEBUG" ;; + "ram") + log2ram "$2" + ;; *) log_and_exit1 "Error: only '0' '1' '2' '3' '4' 'show' 'max' options are supported" ;; @@ -114,7 +146,7 @@ function log { function log_help { echo - echo "Usage: $BASENAME log <0|1|2|3|4|show|max>" + echo "Usage: $BASENAME log [0|1|2|3|4|show|max|ram [on|off]]" echo echo "Example:" echo " $BASENAME log" @@ -146,4 +178,16 @@ function log_help { echo " $BASENAME log max" echo " log X: level set to max" echo + echo " $BASENAME log ram" + echo " log2ram is off" + echo " force logs to be stored in ram and only writes to disk on shutdown" + echo " https://github.com/azlux/log2ram" + echo " Stores logs in 40M (Megabytes) in mount point in memory" + echo + echo " $BASENAME log ram on" + echo " Successfully enabled log2ram, please reboot" + echo + echo " $BASENAME log ram off" + echo " Successfully disabled log2ram" + echo } diff --git a/modules/log2ram.sh b/modules/log2ram.sh deleted file mode 100644 index e3b449c20..000000000 --- a/modules/log2ram.sh +++ /dev/null @@ -1,49 +0,0 @@ -function log2ram { - checkrpi - checkroot - checkargn $# 1 - if [ "$1" = "" ]; then - if [[ $(df -h) != *"log2ram"* ]]; then - echo "log2ram is off" - else - echo "log2ram is on" - fi - elif [ "$1" = "on" ]; then - checkinternet - curl -s -Lo log2ram.tar.gz https://github.com/azlux/log2ram/archive/master.tar.gz &>"$LOGFILE" - tar xf log2ram.tar.gz &>"$LOGFILE" - rm log2ram.tar.gz - cd log2ram-master || exit - chmod +x install.sh && ./install.sh &>"$LOGFILE" - cd .. - rm -r log2ram-master - echo "Successfully enabled log2ram, please reboot" - elif [ "$1" = "off" ]; then - if [ -f "/usr/local/bin/uninstall-log2ram.sh" ]; then - chmod +x /usr/local/bin/uninstall-log2ram.sh && /usr/local/bin/uninstall-log2ram.sh &>"$LOGFILE" - fi - echo "Sucessfully disabled log2ram" - else - log_and_exit1 "Error: only '', 'on', and 'off' options supported" - fi -} - -function log2ram_help { - echo - echo "Usage: $BASENAME log2ram [on|off]" - echo - echo "force logs to be stored in ram and only writes to disk on shutdown" - echo "https://github.com/azlux/log2ram" - echo "Stores logs in 40M (Megabytes) in mount point in memory" - echo - echo "Example:" - echo " $BASENAME log2ram" - echo " log2ram is off" - echo - echo " $BASENAME log2ram on" - echo " Successfully enabled log2ram, please reboot" - echo - echo " $BASENAME log2ram off" - echo " Successfully disabled log2ram" - echo -} diff --git a/tests/log2ram.bats b/tests/log2ram.bats deleted file mode 100755 index e503118ff..000000000 --- a/tests/log2ram.bats +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bats -load test-helper -@test "$clinom log2ram (manually test w/out bats - requires reboots)" {} From a7ac8bf58b8d9876c59f2d2d87bbef73410ae321 Mon Sep 17 00:00:00 2001 From: Tristan Date: Wed, 20 May 2020 18:45:04 -0400 Subject: [PATCH 5/6] Update log.sh --- modules/log.sh | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/modules/log.sh b/modules/log.sh index 3017a02ca..08bd9e6e9 100644 --- a/modules/log.sh +++ b/modules/log.sh @@ -8,20 +8,13 @@ function log2ram { echo "log2ram is on" fi elif [ "$1" = "on" ]; then - checkinternet - curl -s -Lo log2ram.tar.gz https://github.com/azlux/log2ram/archive/master.tar.gz &>"$LOGFILE" - tar xf log2ram.tar.gz &>"$LOGFILE" - rm log2ram.tar.gz - cd log2ram-master || exit - chmod +x install.sh && ./install.sh &>"$LOGFILE" - cd .. - rm -r log2ram-master - echo "Successfully enabled log2ram, please reboot" - elif [ "$1" = "off" ]; then - if [ -f "/usr/local/bin/uninstall-log2ram.sh" ]; then - chmod +x /usr/local/bin/uninstall-log2ram.sh && /usr/local/bin/uninstall-log2ram.sh &>"$LOGFILE" + if [[ $(log2ram) = *off* ]]; then + log2ram start fi - echo "Sucessfully disabled log2ram" + echo "Successfully started log2ram" + elif [ "$1" = "off" ]; then + log2ram stop + echo "Sucessfully stopped log2ram" else log_and_exit1 "Error: only '', 'on', and 'off' options supported" fi @@ -185,9 +178,9 @@ function log_help { echo " Stores logs in 40M (Megabytes) in mount point in memory" echo echo " $BASENAME log ram on" - echo " Successfully enabled log2ram, please reboot" + echo " Successfully started log2ram" echo echo " $BASENAME log ram off" - echo " Successfully disabled log2ram" + echo " Successfully stopped log2ram" echo } From c06ff958f6368bd10b49983ff2c6448b84f62620 Mon Sep 17 00:00:00 2001 From: Tristan Date: Wed, 20 May 2020 18:46:15 -0400 Subject: [PATCH 6/6] Update log.sh --- modules/log.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/log.sh b/modules/log.sh index 08bd9e6e9..6237c3b50 100644 --- a/modules/log.sh +++ b/modules/log.sh @@ -9,11 +9,11 @@ function log2ram { fi elif [ "$1" = "on" ]; then if [[ $(log2ram) = *off* ]]; then - log2ram start + command log2ram start fi echo "Successfully started log2ram" elif [ "$1" = "off" ]; then - log2ram stop + command log2ram stop echo "Sucessfully stopped log2ram" else log_and_exit1 "Error: only '', 'on', and 'off' options supported"