This commit is contained in:
2024-11-09 04:28:25 -07:00
parent 7a2adb11db
commit d01d739b7e
+24 -24
View File
@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
cronVers=30-live # version of this script cronVers=32-live # version of this script
sleepSecs=180 # seconds of warning to wait for user to log out sleepSecs=180 # seconds of warning to wait for user to log out
log=$HOME/esp/install.log log=$HOME/esp/install.log
@@ -23,12 +23,12 @@ function write_to_log() {
startTime=$(date '+%s') startTime=$(date '+%s')
write_to_log " === $(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): new reinstall ===" write_to_log " === $(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): new reinstall ==="
write_to_log "Cron version: ${cronVers}" write_to_log "Cron version: ${cronVers}"
warningString="WARNING:\n\tReinstalling esp-idf in ${sleepSecs} seconds! Save and log out!\n\tmonitor with \`tail -f -n 50 $HOME/esp/install.log\`\n\tterminate with \`sudo killall cron-reinstall-esp-idf.sh\`\n\t$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)')" warningString="WARNING:\n\tReinstalling esp-idf in ${sleepSecs} seconds! Save and log out!\n\tmonitor with \`tail -f -n 50 $HOME/esp/install.log\`\n\tterminate with \`sudo killall cron-reinstall-esp-idf.sh\`\n\t$(date '+%d/%m/%Y %H:%M:%S %Z (%s)')"
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): sending warning message to $myUser" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): sending warning message to $myUser"
write_to_log "$warningString" write_to_log "$warningString"
echo -e "$warningString" | sudo write $myUser echo -e "$warningString" | sudo write $myUser
return_status return_status
@@ -46,92 +46,92 @@ espressifLocation=$HOME/.espressif
customBinLocation=$installDir/.custom_bin customBinLocation=$installDir/.custom_bin
customBinFrom=$runningDir/custom_bin customBinFrom=$runningDir/custom_bin
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)')\nvars:\n\tmyUser: $myUser\n\tcronVers: $cronVers\n\tgitJobs: $gitJobs\n\tlog: $log\n\tsleepSecs: $sleepSecs\n\tinstallDir: $installDir\n\tgitBranch: $gitBranch\n\trunningDir: $runningDir\n\tidfDir: $idfDir\n\tespressifLocation: $espressifLocation\n\tcustomBinLocation: $customBinLocation\n\tcustomBinFrom: $customBinFrom" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)')\nvars:\n\tmyUser: $myUser\n\tcronVers: $cronVers\n\tgitJobs: $gitJobs\n\tlog: $log\n\tsleepSecs: $sleepSecs\n\tinstallDir: $installDir\n\tgitBranch: $gitBranch\n\trunningDir: $runningDir\n\tidfDir: $idfDir\n\tespressifLocation: $espressifLocation\n\tcustomBinLocation: $customBinLocation\n\tcustomBinFrom: $customBinFrom"
return_status return_status
if ! [ -d $installDir ]; then if ! [ -d $installDir ]; then
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): creating ${installDir}" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): creating ${installDir}"
mkdir $installDir mkdir $installDir
return_status return_status
fi fi
if [ -d $idfDir ]; then if [ -d $idfDir ]; then
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): deleting ${idfDir}" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${idfDir}"
rm -rf $idfDir rm -rf $idfDir
return_status return_status
fi fi
if [ -d $espressifLocation ]; then if [ -d $espressifLocation ]; then
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): deleting ${espressifLocation}" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${espressifLocation}"
rm -rf "${espressifLocation}" rm -rf "${espressifLocation}"
return_status return_status
fi fi
if [ -d $customBinLocation ]; then if [ -d $customBinLocation ]; then
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): deleting ${customBinLocation}" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${customBinLocation}"
rm -rf $customBinLocation rm -rf $customBinLocation
return_status return_status
fi fi
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): copying scripts from ${customBinFrom} to ${customBinLocation}" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): copying scripts from ${customBinFrom} to ${customBinLocation}"
cp -r $customBinFrom $customBinLocation cp -r $customBinFrom $customBinLocation
return_status return_status
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): making scripts executable at ${customBinLocation}" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): making scripts executable at ${customBinLocation}"
chmod -R +x $customBinLocation chmod -R +x $customBinLocation
return_status return_status
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): cloning git branch ${gitBranch} with ${gitJobs} jobs to ${idfDir}" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): cloning git branch ${gitBranch} with ${gitJobs} jobs to ${idfDir}"
git clone --recursive --jobs $gitJobs --branch $gitBranch https://github.com/espressif/esp-idf $idfDir git clone --recursive --jobs $gitJobs --branch $gitBranch https://github.com/espressif/esp-idf $idfDir
return_status return_status
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): installing with ${idfDir}/install.sh all" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installing with ${idfDir}/install.sh all"
eval "${idfDir}/install.sh all" eval "${idfDir}/install.sh all"
return_status return_status
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): installing tools with idf_tools.py" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installing tools with idf_tools.py"
python $idfDir/tools/idf_tools.py install all python $idfDir/tools/idf_tools.py install all
return_status return_status
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): backing up export.sh" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): backing up export.sh"
cp $idfDir/export.sh $idfDir/export.sh.bak cp $idfDir/export.sh $idfDir/export.sh.bak
return_status return_status
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): editing export.sh" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): editing export.sh"
sed -i 's/return 0/# return 0/g' $idfDir/export.sh sed -i 's/return 0/# return 0/g' $idfDir/export.sh
return_status return_status
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): adding add-to-export-sh.txt to export.ss" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): adding add-to-export-sh.txt to export.ss"
cat $runningDir/add-to-export-sh.txt >> $idfDir/export.sh cat $runningDir/add-to-export-sh.txt >> $idfDir/export.sh
return_status return_status
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): getting the commit hash" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): getting the commit hash"
commitHash=$(git -C $idfDir rev-parse HEAD) commitHash=$(git -C $idfDir rev-parse HEAD)
return_status return_status
gitDataLog="Installed at:\n\t$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)')\n\tat commit $commitHash\n\tfrom branch $gitBranch" gitDataLog="Installed at:\n\t$(date '+%d/%m/%Y %H:%M:%S %Z (%s)')\n\tat commit $commitHash\n\tfrom branch $gitBranch"
write_to_log $gitDataLog write_to_log $gitDataLog
echo -e $gitDataLog >> $idfDir/version-data.txt echo -e $gitDataLog >> $idfDir/version-data.txt
return_status return_status
rebootMsg="$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): rebooting in ${sleepSecs} seconds. seave and log out" rebootMsg="$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): rebooting in ${sleepSecs} seconds. seave and log out"
write_to_log $rebootMsg write_to_log $rebootMsg
echo $rebootMsg | sudo write princesspi echo $rebootMsg | sudo write princesspi
return_status return_status
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): sleeping ${sleepSecs} seconds" write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): sleeping ${sleepSecs} seconds"
sleep $sleepSecs sleep $sleepSecs
return_status return_status
write_to_log "$(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): sending final message and rebooting"; write_to_log "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): sending final message and rebooting";
echo "rebooting NOW bye bye" | sudo write $myUser echo "rebooting NOW bye bye" | sudo write $myUser
return_status return_status
endTime=$(date '+%s') endTime=$(date '+%s')
timeElapsed=(($endTime-$startTime)) timeElapsed=(($endTime-$startTime))
write_to_log "total install time $timeElapsed seconds" write_to_log "reinstall completed in $timeElapsed seconds"
write_to_log " === $(date '+%d/%m/%Y-%H.%M.%S %Z (%s)'): finished ===\n" write_to_log " === $(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): finished ===\n"
sudo reboot sudo reboot