-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Fourdee/testing
v68 (14/06/15) Release Notes: General | DietPi's logging system has been completely rewritten. Please see here for full list of options: http://fuzon.co.uk/phpbb/viewtopic.php?f=8&t=5&start=20#p68 General | DietPi now automates and manages Apt-get update. apt-get update is automatically called when its required and/or, hasnt been updated in 7 days. Also runs as a sperate thread to speed up initial installation, and, future dieti-software installations. General | Changed image creation methods. Total image sizes have been reduced. DietPi-Software | Added DietPi choice system for various system logging options. Features 3 choices: 2 Ramlog modes and 1 full system logging option (rsyslog logrotate). DietPi-Logclear | New addition. Multiple options for clearing log files. Also includes backup feature. Run dietpi-logclear to get available modes. DietPi-BugReport | Can now generate an offline bugreport.zip if no network is detected.
- Loading branch information
Showing
21 changed files
with
1,121 additions
and
367 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
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
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 +1 @@ | ||
67 | ||
68 |
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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
{ | ||
#//////////////////////////////////// | ||
# DietPi Cron.Hourly script | ||
# | ||
#//////////////////////////////////// | ||
# | ||
# Info: | ||
# - Location /etc/cron.hourly/dietpi | ||
# | ||
#//////////////////////////////////// | ||
|
||
LOGGING_MODE=0 | ||
if [ -f /boot/dietpi/.installed ]; then | ||
LOGGING_MODE=$(cat /boot/dietpi/.installed | grep 'INDEX_LOGGING_CURRENT ' | awk '{print $2}') | ||
fi | ||
|
||
#---------------------------------------------------------------- | ||
# Main Loop | ||
#---------------------------------------------------------------- | ||
# Logging | ||
|
||
#clear all log files. | ||
if (( $LOGGING_MODE == -1 )); then | ||
/boot/dietpi/dietpi-logclear 1 &> /dev/null | ||
#Update current log files data to /"$HOME"/logfile_storage/*. Then clear. | ||
elif (( $LOGGING_MODE == -2 )); then | ||
/boot/dietpi/dietpi-logclear 0 &> /dev/null | ||
fi | ||
|
||
#---------------------------------------------------------------- | ||
exit | ||
#---------------------------------------------------------------- | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,223 @@ | ||
#!/bin/bash | ||
{ | ||
#//////////////////////////////////// | ||
# DietPi Function: | ||
# - dietpi-apt-get_update | ||
# | ||
#//////////////////////////////////// | ||
# Created by Dan Knight / daniel_haze@hotmail.com / fuzon.co.uk | ||
# | ||
#//////////////////////////////////// | ||
# | ||
# Info: | ||
# - Allows the running of apt-get update as a seperate background thead/process | ||
# - Uses $STATE_CURRENT which contains current state and hours since last update. | ||
# | ||
# Usage: | ||
# - /tmp/dietpi/dietpi-apt-get_update -1 (clears the state file if its not in use. New updates can then be run) | ||
# - /tmp/dietpi/dietpi-apt-get_update 0 (starts a new update as another process, if $STATE_CURRENT is -2/-1) | ||
# - /tmp/dietpi/dietpi-apt-get_update 1 (blocking/check/visual mode, starts if it is -2/-1, else, waits for a "done" state) | ||
# - /tmp/dietpi/dietpi-apt-get_update 2 (blocking/check/visual mode, waits for "done", resets STATE_FILE , waits for a "done" state) | ||
# - /tmp/dietpi/dietpi-apt-get_update 3 (returns hours since last successful update.) | ||
# | ||
# $STATE_FILE_TEMP values: | ||
# line 1 | ||
# - $STATE_CURRENT 0 = apt-get update is running | ||
# - $STATE_CURRENT 1 = apt-get updated and completed | ||
# - $STATE_CURRENT -1 = failed (error and/or warning from apt) | ||
# - $STATE_CURRENT -2 = apt-get update has never been run, and/or, ready to be run. | ||
# line 2: | ||
# - Hours since last successful update. | ||
#//////////////////////////////////// | ||
|
||
INPUT=0 | ||
if [[ $1 =~ ^-?[0-9]+$ ]]; then | ||
INPUT=$1 | ||
fi | ||
|
||
#///////////////////////////////////////////////////////////////////////////////////// | ||
# Globals | ||
#///////////////////////////////////////////////////////////////////////////////////// | ||
|
||
TEMP_OUTPUT="/tmp/dietpi/apt_update_temp" | ||
STATE_FILE_TEMP="/tmp/dietpi/.dietpi-apt-get_update" | ||
#Master used for next boot. | ||
STATE_FILE_MASTER="/boot/dietpi/.dietpi-apt-get_update" | ||
|
||
#-2 | Has never been run, and/or, ready to be run. | ||
STATE_CURRENT=-2 | ||
|
||
HOURS_SINCE_1970=0 | ||
HOURS_SINCE_1970_TO_LASTUPDATE=1337 | ||
|
||
Get_Current_State(){ | ||
|
||
#Obtain values from file | ||
if [ -f "$STATE_FILE_TEMP" ]; then | ||
STATE_CURRENT=$(sed -n 1p "$STATE_FILE_TEMP") | ||
HOURS_SINCE_1970_TO_LASTUPDATE=$(sed -n 2p "$STATE_FILE_TEMP") | ||
fi | ||
|
||
} | ||
|
||
Get_Hours_Since_Last_Update(){ | ||
|
||
Get_Current_State | ||
|
||
#Get current | ||
HOURS_SINCE_1970=$(( $(date +'%s') / 60 / 60 )) | ||
|
||
#Use return value | ||
STATE_CURRENT=$(( $HOURS_SINCE_1970 - $HOURS_SINCE_1970_TO_LASTUPDATE )) | ||
} | ||
|
||
Update_Apt(){ | ||
|
||
#Run only if: -2 (ready to run) / -1 (ready, but failed previously). | ||
if (( $STATE_CURRENT == -2 )) || | ||
(( $STATE_CURRENT == -1 )); then | ||
|
||
# 0 = running | ||
STATE_CURRENT=0 | ||
|
||
#Update state file | ||
Write_StateFile_Temp | ||
|
||
#clean | ||
apt-get clean | ||
|
||
#Update apt, output to temp file | ||
apt-get update > "$TEMP_OUTPUT" | ||
|
||
#read temp file | ||
if (( $(cat "$TEMP_OUTPUT" | grep -ci -m1 '[WE]: ') == 0 )); then | ||
#ok | ||
STATE_CURRENT=1 | ||
#Reset hours since update to current. | ||
HOURS_SINCE_1970_TO_LASTUPDATE=$(( $(date +'%s') / 60 / 60 )) | ||
else | ||
#failed | ||
STATE_CURRENT=-1 | ||
fi | ||
|
||
#Update master for next boot. | ||
Write_StateFile_Master | ||
|
||
#Update state file | ||
Write_StateFile_Temp | ||
|
||
#clean up | ||
rm "$TEMP_OUTPUT" | ||
|
||
fi | ||
|
||
} | ||
|
||
Wait_For_Completion(){ | ||
|
||
local info_cpu=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}') | ||
|
||
Get_Current_State | ||
|
||
#Currently running | ||
while (( $STATE_CURRENT == 0 )); do | ||
|
||
local cache_folder_size=$(ls -l /var/cache/apt | grep 'total ' | sed 's/total //g') | ||
|
||
/tmp/dietpi/dietpi-banner 0 | ||
echo -e "\n Waiting for apt-get update to finish: Please wait..." | ||
echo -e "\n apt-cache database size: $cache_folder_size KB" | ||
|
||
#2+ cores, use one thread for making it look pretty :P | ||
if (( $(nproc) > 1 )); then | ||
|
||
/tmp/dietpi/dietpi-funtime | ||
|
||
#1 core, go easy on it ;) | ||
else | ||
sleep 2 | ||
fi | ||
|
||
Get_Current_State | ||
|
||
done | ||
|
||
} | ||
|
||
Write_StateFile_Temp(){ | ||
|
||
#Update state file | ||
echo -e "$STATE_CURRENT" > "$STATE_FILE_TEMP" | ||
echo -e "$HOURS_SINCE_1970_TO_LASTUPDATE" >> "$STATE_FILE_TEMP" | ||
|
||
} | ||
|
||
Write_StateFile_Master(){ | ||
|
||
#Update master state file which will be loaded on next boot. | ||
echo -e "$STATE_CURRENT" > "$STATE_FILE_MASTER" | ||
echo -e "$HOURS_SINCE_1970_TO_LASTUPDATE" >> "$STATE_FILE_MASTER" | ||
|
||
} | ||
|
||
Reset_StateFile(){ | ||
|
||
STATE_CURRENT=-2 | ||
Write_StateFile_Temp | ||
|
||
} | ||
|
||
#///////////////////////////////////////////////////////////////////////////////////// | ||
# Main Loop | ||
#///////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#Reset STATE file if not currently updating (allows a new update) | ||
if (( $INPUT == -1 )); then | ||
|
||
Get_Current_State | ||
if (( $STATE_CURRENT != 0 )); then | ||
Reset_StateFile | ||
fi | ||
|
||
#Default input | Run update as another process. | ||
elif (( $INPUT == 0 )); then | ||
|
||
Get_Current_State | ||
Update_Apt & | ||
|
||
#Visual Blocking mode - Starts update if required | ||
elif (( $INPUT == 1 )); then | ||
|
||
Get_Current_State | ||
Update_Apt & | ||
|
||
#Wait / inform user | ||
Wait_For_Completion | ||
|
||
#Visual Blocking mode with rerun - Waits for existing updates, resets, starts update again, waits for "done". | ||
elif (( $INPUT == 2 )); then | ||
|
||
#Wait for previous if running | ||
Wait_For_Completion | ||
|
||
#Reset | ||
Reset_StateFile | ||
|
||
#Run again | ||
Update_Apt & | ||
|
||
#Wait / inform user | ||
Wait_For_Completion | ||
|
||
#Return hours since last update | ||
elif (( $INPUT == 3 )); then | ||
|
||
Get_Hours_Since_Last_Update | ||
|
||
fi | ||
|
||
#------------------------------------------------------------------------------------- | ||
echo -e "$STATE_CURRENT" | ||
exit | ||
#------------------------------------------------------------------------------------- | ||
} |
Oops, something went wrong.