Skip to content

Commit

Permalink
In repsonse to issue (enhancement) openenergymonitor#64
Browse files Browse the repository at this point in the history
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
  • Loading branch information
CDuffers authored and CDuffers committed Mar 24, 2023
1 parent 582b137 commit d9316c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
11 changes: 11 additions & 0 deletions install/init.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,3 +33,5 @@ cd $openenergymonitor_dir/EmonScripts/install
cd

rm init.sh

echo -e "\nScript output also stored in ${LOG_FILE}"
20 changes: 12 additions & 8 deletions install/main.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
# --------------------------------------------------------------------------------
# RaspberryPi Strech Build Script
# Emoncms, Emoncms Modules, EmonHub & dependencies
Expand All @@ -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
Expand Down Expand Up @@ -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}"

0 comments on commit d9316c9

Please sign in to comment.