-
-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ DietPi-RAMlog | Minor coding and output updates
- Loading branch information
Showing
1 changed file
with
21 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#!/bin/bash | ||
{ | ||
#//////////////////////////////////// | ||
# DietPi RAMLOG Script | ||
# DietPi RAMlog Script | ||
# | ||
#//////////////////////////////////// | ||
# Created by Daniel Knight / [email protected] / dietpi.com | ||
# | ||
#//////////////////////////////////// | ||
# | ||
# Info: | ||
# - Location: /{DietPi,boot}/dietpi/func/dietpi-ramlog | ||
# - /var/log is mounted as tmpfs (RAMdisk) before this script runs. | ||
# - Saves /var/log/* attributes and ownerships to $FP_STORE during shutdown | ||
# - Restores /var/log/* atrributes and ownerships from $FP_STORE during boot | ||
|
@@ -19,16 +20,8 @@ | |
# - /DietPi/dietpi/func/dietpi-ramlog 1 = Store from /var/log to $FP_STORE | ||
#//////////////////////////////////// | ||
|
||
#------------------------------------------------------------------------------------- | ||
#. /DietPi/dietpi/func/dietpi-globals # Not compatible until DietPi-PreBoot has finished and overkill for the purpose of this script. | ||
#export LC_ALL=en_GB.UTF-8 # Not required, as we do not parse any external command and "date" is allowed to be in user locale format. | ||
#cd $HOME # Not required, as we do not create any tmp files and produces and: "cd: HOME not set" | ||
#------------------------------------------------------------------------------------- | ||
|
||
[[ $1 =~ ^-?[0-9]+$ ]] && INPUT=$1 || INPUT=-1 | ||
|
||
INPUT=$1 | ||
EXIT_CODE=0 | ||
|
||
PROGRAM_NAME='DietPi-RAMlog' | ||
FP_STORE='/var/tmp/dietpi/logs/dietpi-ramlog_store' | ||
|
||
|
@@ -37,56 +30,54 @@ | |
#///////////////////////////////////////////////////////////////////////////////////// | ||
|
||
# Startup phase: Restore from disk | ||
if (( $INPUT == 0 )); then | ||
if [[ $INPUT == 0 ]]; then | ||
|
||
echo "$(date) | $PROGRAM_NAME: Restoring logs from disk..." | ||
echo "$(date) | $PROGRAM_NAME: [ INFO ] Restoring logs from disk..." | ||
|
||
if [[ -d $FP_STORE ]]; then | ||
|
||
# - Restore empty logs with ownership and permissions from disk | ||
cp -an --attributes-only $FP_STORE/. /var/log/ || EXIT_CODE=$? | ||
# Restore empty logs with ownership and permissions from disk | ||
if cp -an --attributes-only $FP_STORE/. /var/log/; then | ||
|
||
if (( $EXIT_CODE )); then | ||
|
||
echo "$(date) | $PROGRAM_NAME: [ERROR] Restoring logs from disk failed with exit code: $EXIT_CODE" | ||
echo "$(date) | $PROGRAM_NAME: [ OK ] Restored logs from disk." | ||
|
||
else | ||
|
||
echo "$(date) | $PROGRAM_NAME: Restored logs from disk." | ||
EXIT_CODE=$? | ||
echo "$(date) | $PROGRAM_NAME: [FAILED] Restoring logs from disk failed with exit code: $EXIT_CODE" | ||
|
||
fi | ||
|
||
else | ||
|
||
echo "$(date) | $PROGRAM_NAME: No logs found on disk. Aborting..." | ||
echo "$(date) | $PROGRAM_NAME: [ INFO ] No logs found on disk. Aborting..." | ||
|
||
fi | ||
|
||
# Shutdown phase: Store to disk | ||
elif (( $INPUT == 1 )); then | ||
|
||
echo "$(date) | $PROGRAM_NAME: Storing logs to disk..." | ||
elif [[ $INPUT == 1 ]]; then | ||
|
||
# - Assure empty $FP_STORE | ||
[[ -d $FP_STORE ]] && rm -Rf $FP_STORE/{,.??,.[^.]}* || mkdir -p $FP_STORE || EXIT_CODE=$? | ||
echo "$(date) | $PROGRAM_NAME: [ INFO ] Storing logs to disk..." | ||
|
||
# - Store empty logs with ownership and permissions to disk | ||
cp -af --attributes-only /var/log/. $FP_STORE/ || EXIT_CODE=$? | ||
# Assure empty $FP_STORE | ||
[[ -d $FP_STORE ]] && rm -Rf $FP_STORE/{,.??,.[^.]}* || mkdir -p $FP_STORE | ||
|
||
if (( $EXIT_CODE )); then | ||
# Store empty logs with ownership and permissions to disk | ||
if cp -af --attributes-only /var/log/. $FP_STORE/; then | ||
|
||
echo "$(date) | $PROGRAM_NAME: [ERROR] Storing logs to disk failed with exit code: $EXIT_CODE" | ||
echo "$(date) | $PROGRAM_NAME: [ OK ] Stored logs to disk." | ||
|
||
else | ||
|
||
echo "$(date) | $PROGRAM_NAME: Stored logs to disk." | ||
EXIT_CODE=$? | ||
echo "$(date) | $PROGRAM_NAME: [FAILED] Storing logs to disk failed with exit code: $EXIT_CODE" | ||
|
||
fi | ||
|
||
else | ||
|
||
echo "$(date) | $PROGRAM_NAME: [ERROR] Unknown argument: $INPUT. Aborting..." | ||
EXIT_CODE=1 | ||
echo "$(date) | $PROGRAM_NAME: [FAILED] Unknown argument: \"$INPUT\". Aborting..." | ||
|
||
fi | ||
|
||
|