From d9316c9c4aa2654f3d5d4f2b8741679d77baa0c1 Mon Sep 17 00:00:00 2001 From: CDuffers Date: Fri, 24 Mar 2023 18:59:42 +0000 Subject: [PATCH 1/3] In repsonse to issue (enhancement) https://github.com/openenergymonitor/EmonScripts/issues/64 The install.sh and main.sh have been updated to copy stdout and stderr to both the terminal and also a log file. The script echos the log file name at the beginning and end of the script 'tee -a' used in case the scripts are run multiple times In addition main.sh is changed to move the shell directive to the top of the script and to remove superfluous code after the "exit 0" in the final if statement. Also removed the exit to enable the script output to be shown using one command after the if --- install/init.sh | 11 +++++++++++ install/main.sh | 20 ++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/install/init.sh b/install/init.sh index 57199da..9bbe28f 100755 --- a/install/init.sh +++ b/install/init.sh @@ -1,5 +1,14 @@ #!/bin/bash +# Copy stdout and stderr to a log file in addition to the console +# tee -a used in case script is run multiple times + +LOG_FILE=/tmp/$(basename "$0").log +exec > >(tee -a "${LOG_FILE}") 2>&1 + +echo "Script output also stored in ${LOG_FILE}" +echo -e "Started: $(date)\n" + user=$USER openenergymonitor_dir=/opt/openenergymonitor emoncms_dir=/opt/emoncms @@ -24,3 +33,5 @@ cd $openenergymonitor_dir/EmonScripts/install cd rm init.sh + +echo -e "\nScript output also stored in ${LOG_FILE}" diff --git a/install/main.sh b/install/main.sh index 989a9bf..d4f1b22 100755 --- a/install/main.sh +++ b/install/main.sh @@ -1,3 +1,4 @@ +#!/bin/bash # -------------------------------------------------------------------------------- # RaspberryPi Strech Build Script # Emoncms, Emoncms Modules, EmonHub & dependencies @@ -13,12 +14,20 @@ # - emonhub installer # Format as documentation +# Copy stdout and stderr to a log file in addition to the console +# tee -a used in case script is run multiple times + +LOG_FILE=/tmp/$(basename "$0").log +exec > >(tee -a "${LOG_FILE}") 2>&1 + +echo "Script output also stored in ${LOG_FILE}" +echo -e "Started: $(date)\n" + # fix interactive popup that keeps asking for service restart if [ -f /etc/needrestart/needrestart.conf ]; then sudo sed -i 's/#$nrconf{restart} = '"'"'i'"'"';/$nrconf{restart} = '"'"'a'"'"';/g' /etc/needrestart/needrestart.conf fi -#!/bin/bash if [ ! -f config.ini ]; then cp emonsd.config.ini config.ini fi @@ -100,13 +109,8 @@ if [ "$emonSD_pi_env" = "1" ]; then # update checks for image type and only runs with a valid image name file in the boot partition # Update this value to the latest safe image version - this could be automated to pull from safe list sudo touch /boot/emonSD-10Nov22 - exit 0 - # Reboot to complete - sudo reboot else $openenergymonitor_dir/EmonScripts/install/non_emonsd.sh; - # sudo touch /boot/emonSD-30Oct18 - exit 0 - # Reboot to complete - sudo reboot fi + +echo -e "\nScript output also stored in ${LOG_FILE}" From f6b1d78379b7d7575c032b6b44a371968d9a6a70 Mon Sep 17 00:00:00 2001 From: CDuffers Date: Sat, 25 Mar 2023 08:23:30 +0000 Subject: [PATCH 2/3] Added comments to the install-scripts.md and install.md highlighting that output is sent to screen and also log file --- docs/install-scripts.md | 4 ++-- docs/install.md | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/install-scripts.md b/docs/install-scripts.md index ab783d5..2b9771b 100644 --- a/docs/install-scripts.md +++ b/docs/install-scripts.md @@ -4,9 +4,9 @@ All these links, link to the `stable` branch. The installation process is broken out into separate scripts that can be run individually. -**[init.sh:](https://github.com/openenergymonitor/EmonScripts/blob/stable/install/init.sh)** Launches the full installation script, first downloading the EmonScripts repository that contains the rest of the installation scripts. +**[init.sh:](https://github.com/openenergymonitor/EmonScripts/blob/stable/install/init.sh)** Launches the full installation script, first downloading the EmonScripts repository that contains the rest of the installation scripts. All output sent to screen also stored in `/tmp/init.sh.log`. -**[main.sh:](https://github.com/openenergymonitor/EmonScripts/blob/stable/install/main.sh)** Loads the configuration file and runs the individual installation scripts as applicable. +**[main.sh:](https://github.com/openenergymonitor/EmonScripts/blob/stable/install/main.sh)** Loads the configuration file and runs the individual installation scripts as applicable. All output sent to screen also stored in `/tmp/main.sh.log`. --- diff --git a/docs/install.md b/docs/install.md index 90967ed..88f97b8 100644 --- a/docs/install.md +++ b/docs/install.md @@ -41,6 +41,8 @@ chmod +x init.sh && ./init.sh The `init` script automatically calls the `main` script. At this point you will be offered the option to configure the installation process. +Output from `init.sh` is displayed on screen and also stored in `/tmp/init.sh.log`. Output from `main.sh` is also displayed on screen and stored in `/tmp/main.sh.log`. + If you are on a RaspberryPi or EmonPi you can usually just proceed. Be patient, the install process takes some time. From 5bc2f385887811d931c188e5176e1552e28670cc Mon Sep 17 00:00:00 2001 From: CDuffers Date: Sun, 26 Mar 2023 18:20:14 +0100 Subject: [PATCH 3/3] Changed location for log file storage in init.sh and main.sh and updated install-scripts.md and install.md to reflect this change --- docs/install-scripts.md | 4 ++-- docs/install.md | 2 +- install/init.sh | 2 +- install/main.sh | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/install-scripts.md b/docs/install-scripts.md index 2b9771b..fd7c745 100644 --- a/docs/install-scripts.md +++ b/docs/install-scripts.md @@ -4,9 +4,9 @@ All these links, link to the `stable` branch. The installation process is broken out into separate scripts that can be run individually. -**[init.sh:](https://github.com/openenergymonitor/EmonScripts/blob/stable/install/init.sh)** Launches the full installation script, first downloading the EmonScripts repository that contains the rest of the installation scripts. All output sent to screen also stored in `/tmp/init.sh.log`. +**[init.sh:](https://github.com/openenergymonitor/EmonScripts/blob/stable/install/init.sh)** Launches the full installation script, first downloading the EmonScripts repository that contains the rest of the installation scripts. All output sent to screen also stored in the user's home directory `~/init.sh.log`. -**[main.sh:](https://github.com/openenergymonitor/EmonScripts/blob/stable/install/main.sh)** Loads the configuration file and runs the individual installation scripts as applicable. All output sent to screen also stored in `/tmp/main.sh.log`. +**[main.sh:](https://github.com/openenergymonitor/EmonScripts/blob/stable/install/main.sh)** Loads the configuration file and runs the individual installation scripts as applicable. All output sent to screen also stored in the user's home directory `~/main.sh.log`. --- diff --git a/docs/install.md b/docs/install.md index 88f97b8..07ca6cb 100644 --- a/docs/install.md +++ b/docs/install.md @@ -41,7 +41,7 @@ chmod +x init.sh && ./init.sh The `init` script automatically calls the `main` script. At this point you will be offered the option to configure the installation process. -Output from `init.sh` is displayed on screen and also stored in `/tmp/init.sh.log`. Output from `main.sh` is also displayed on screen and stored in `/tmp/main.sh.log`. +Output from `init.sh` is displayed on screen and also stored in the user's home directory `~/init.sh.log`. Output from `main.sh` is also displayed on screen and stored in the user's home directory `~/main.sh.log`. If you are on a RaspberryPi or EmonPi you can usually just proceed. diff --git a/install/init.sh b/install/init.sh index 9bbe28f..d6b1a83 100755 --- a/install/init.sh +++ b/install/init.sh @@ -3,7 +3,7 @@ # Copy stdout and stderr to a log file in addition to the console # tee -a used in case script is run multiple times -LOG_FILE=/tmp/$(basename "$0").log +LOG_FILE=~/$(basename "$0").log exec > >(tee -a "${LOG_FILE}") 2>&1 echo "Script output also stored in ${LOG_FILE}" diff --git a/install/main.sh b/install/main.sh index d4f1b22..0b2afd5 100755 --- a/install/main.sh +++ b/install/main.sh @@ -17,7 +17,7 @@ # Copy stdout and stderr to a log file in addition to the console # tee -a used in case script is run multiple times -LOG_FILE=/tmp/$(basename "$0").log +LOG_FILE=~/$(basename "$0").log exec > >(tee -a "${LOG_FILE}") 2>&1 echo "Script output also stored in ${LOG_FILE}"