60-beta.5

This commit is contained in:
2024-11-12 08:45:01 -07:00
parent 68aea82121
commit 25f894ff6a
5 changed files with 323 additions and 418 deletions
+7 -7
View File
@@ -31,27 +31,27 @@ only currently tested on zsh
Modes: Modes:
default: default:
reinstalls non-interactively with no delays, logouts, or reboots reinstalls non-interactively with no delays, logouts, or reboots
bash cron-reinstall-esp-idf.sh bash reinstall-esp-idf.sh
test: test:
tests the script. very fast. minimal actions taken. no reinstall is done tests the script. very fast. minimal actions taken. no reinstall is done
bash cron-reinstall-esp-idf.sh test bash reinstall-esp-idf.sh test
retool: retool:
reinstalls bins and export.sh, nothing else reinstalls bins and export.sh, nothing else
bash cron-reinstall-esp-idf.sh retool bash reinstall-esp-idf.sh retool
cron: cron:
runs noninteractively with forced user logout and automatic reboot, plus delays runs noninteractively with forced user logout and automatic reboot, plus delays
bash cron-reinstall-esp-idf.sh cron bash reinstall-esp-idf.sh cron
interactive: interactive:
interactively installs/reinstalls esp-idf interactively installs/reinstalls esp-idf
bash cron-reinstall-esp-idf.sh interactive bash reinstall-esp-idf.sh interactive
help: help:
display this help text display this help text
bash cron-reinstall-esp-idf.sh help bash reinstall-esp-idf.sh help
``` ```
@@ -60,7 +60,7 @@ Modes:
cron: cron:
reinstall from master everyday at 8pm, logging out users with warn delays and rebooting after reinstall from master everyday at 8pm, logging out users with warn delays and rebooting after
crontab -e crontab -e
0 8 * * * bash $HOME/esp/esp-install-custom/cron-reinstall-esp-idf.sh cron 0 8 * * * bash $HOME/esp/esp-install-custom/reinstall-esp-idf.sh cron
manually wipe logs: manually wipe logs:
rm $ESPIDF_INSTALLDIR/install.log; rm $ESPIDF_INSTALLDIR/version-data.txt; touch $ESPIDF_INSTALLDIR/install.log; touch $ESPIDF_INSTALLDIR/version-data.txt; rm $ESPIDF_INSTALLDIR/install.log; rm $ESPIDF_INSTALLDIR/version-data.txt; touch $ESPIDF_INSTALLDIR/install.log; touch $ESPIDF_INSTALLDIR/version-data.txt;
-318
View File
@@ -1,318 +0,0 @@
#!/bin/bash
# set -e # for testan, die on eelrror
startTime=$(date '+%s') # to time the (re)install time for the logs
myUser=princesspi # user installing esp-ids
gitJobs=5 # number of jobs to download from github with
gitBranch=master # branch from github
rcFile=$HOME/.zshrc # shell rc file
if [ -z $ESPIDF_INSTALLDIR ]; then
installDir=$HOME/esp
else
installDir=$ESPIDF_INSTALLDIR
fi
# installDir=/home/$myUser/esp # install dir
log=$installDir/install.log # log file
versionData=$installDir/version-data.txt # version data log file
idfDir=$installDir/esp-idf # esp-idf path
espressifLocation=$HOME/.espressif # espressif tools install location
customBinLocation=$installDir/.custom_bin # where custom bin scripts are placed
runningDir="$( cd "$( dirname "$0" )" && pwd )"
customBinFrom=$runningDir/custom_bin # dir where custom scripts are coming FROM
helpText=$runningDir/help.txt
scriptVers=$(cat $runningDir/version.txt) # make sure version.txt does NOT have newline
arg=$1 # just rename the argument var for clarity with the functions
# full order:
# handleStart
# handleLogoutAllUsers
# sleepHold
# handleLogoutAllUsers
# handleSetupEnvironment
# handleCustomBins
# handleDownloadInstall
# handleExport
# handleAliasEnviron
# handleLogoutAllUsers
# handleEnd
# handleReboot
# exit
function returnStatus() {
strii="\treturn status: ${?}"
echo -e "$strii\n"
echo -e "$strii\n" >> $log
}
function writeToLog() {
echo -e "$1"
echo -e "$1" >> $log
}
function sleepHold() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling sleep hold (function ran)"
sleepSecs=$(($sleepMins*60)) # calculated seconds of warning to wait for user to log out
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): sleeping ${sleepMins} minutes"
sleep $sleepSecs
returnStatus
}
function handleCustomBins() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling custon bins (function ran)"
if [ -d $customBinLocation ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${customBinLocation}"
rm -rf $customBinLocation
returnStatus
else
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): ${customBinLocation} not found, skipping delete"
fi
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): copying scripts from ${customBinFrom} to ${customBinLocation}"
cp -r $customBinFrom $customBinLocation
returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): making scripts executable at ${customBinLocation}"
chmod -R +x $customBinLocation
returnStatus
}
function handleExport() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling export.sh (function ran)"
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): backing up ${idfDir}/export.sh to ${idfDir}/export.sh.bak"
cp $idfDir/export.sh $idfDir/export.sh.bakno
returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): editing ${idfDir}/export.sh"
sed -i 's/return 0/# return 0/g' $idfDir/export.sh
returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): adding ${runningDir}/add-to-export-sh.txt to ${idfDir}/export.sh"
cat $runningDir/add-to-export-sh.txt >> $idfDir/export.sh
returnStatus
}
function handleSetupEnvironment() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling setup environment (function ran)"
if ! [ -d $installDir ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): creating ${installDir}"
mkdir $installDir
returnStatus
fi
if [ -d $idfDir ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${idfDir}"
rm -rf $idfDir
returnStatus
fi
if [ -d $espressifLocation ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${espressifLocation}"
rm -rf "${espressifLocation}"
returnStatus
fi
}
function handleAliasEnviron() {
if ! [ -z $(alias | grep get_idf) ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): get_idf alias not found, appending to ${$rcFile}"
echo -e "\nalias get_idf='. ${idfDir}/export.sh'" >> $rcFile
returnStatus
else
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): get_idf alias already installed, skipping"
fi
if [ -z $ESPIDF_INSTALLDIR ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): ESPIDF_INSTALLDIR environment variable not found, appending to ${rcFile}"
echo -e "export ESPIDF_INSTALLDIR=\"${installDir}\"\n" >> $rcFile
returnStatus
else
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): ESPIDF_INSTALLDIR environment variable already installed, skipping"
fi
}
function handleDownloadInstall() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling download and install (function ran)"
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): cloning git branch ${gitBranch} with ${gitJobs} jobs to ${idfDir}"
eval "$gitCmd"
returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installing with ${idfDir}/install.sh all"
eval "$installCmd"
returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installing tools with python ${idfDir}/tools/idf_tools.py install all"
eval "$toolsInstallCmd"
returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): getting the commit hash"
commitHash=$(git -C $idfDir rev-parse HEAD)
returnStatus
gitDataLog="$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installed esp-idf from commit $commitHash from branch $gitBranch using $scriptVers"
writeToLog "$gitDataLog"
echo -e "$gitDataLog" >> $versionData
returnStatus
}
handleReboot() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)') Handling reboot: (function ran)"
rebootMsg="$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): rebooting in $sleepMins minutes. save and log out"
writeToLog "$rebootMsg"
echo "$rebootMsg" | sudo write "$myUser"
returnStatus
}
function handleWarn() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling warn (function ran)"
warningString="WARNING:\n\tReinstalling esp-idf in ${sleepMins} minutes! You will be force logged out in ${sleepMins} minutes! 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)')"
writeToLog $warningString
sleepHold
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Force logging out ${myUser}"
echo -e "$warningString" | sudo write "$myUser"
returnStatus
}
function handleLogoutAllUsers() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling user logout (function ran)"
handleWarn
# logout all users
who | sudo awk '$1 !~ /root/{ cmd="/usr/bin/loginctl terminate-user " $1; system(cmd)}'
returnStatus
}
function handleStart() {
if [ -z $sleepMins ]; then
sleepMins="disabled"
fi
if [ -z $ESPIDF_INSTALLDIR ]; then
installdirEnvvar="not set"
else
installdirEnvvar=$ESPIDF_INSTALLDIR
fi
writeToLog "\n === $(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): new ${action} ==="
writeToLog "\tVersion: ${scriptVers}\n"
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)')\nvars:\n\tmyUser: $myUser\n\tscriptVers: $scriptVers\n\tversionData: $versionData\n\tlog: $log\n\tsleepMins: $sleepMins\n\tinstallDir: $installDir\n\tgitJobs: $gitJobs\n\tgitBranch: $gitBranch\n\tgitCmd: $gitCmd\n\trunningDir: $runningDir\n\tidfDir: $idfDir\n\tespressifLocation: $espressifLocation\n\tcustomBinLocation: $customBinLocation\n\tcustomBinFrom: $customBinFrom\n\tinstallCmd: $installCmd\n\ttoolsInstallCmd: $toolsInstallCmd\n\trcFile: $rcFile\n\t(envvar) ESPIDF_INSTALLDIR: $installdirEnvvar"
}
function handleEmptyLogs() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Emptying and touching logs (function ran)"
rm -f $log
touch $log
rm -f $versionData
touch $versionData
}
function handleEnd() {
endTime=$(date '+%s')
timeElapsed=$(($endTime-$startTime))
echo -e "\nesp-idf re/installed! run \`source $rcFile\` and then \`get_idf\`\n to go\n\nAll done :3\n\n"
writeToLog "reinstall completed in $timeElapsed seconds"
writeToLog " === $(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): finished ===\n\n"
}
if [ "$arg" == "--help" -o "$arg" == "help" -o "$arg" == "-h" -o "$arg" == "h" ]; then
cat $helpText;
exit
elif [ "$arg" == "test" ]; then # minimal actions taken, echo the given commands and such
action="TEST"
gitCmd="echo git clone --jobs $gitJobs --branch $gitBranch --single-branch https://github.com/espressif/esp-idf $idfDir"
installCmd="echo $idfDir/install.sh all"
toolsInstallCmd="echo python $idfDir/tools/idf_tools.py install all"
sleepMins=0
handleStart
handleCustomBins
handleDownloadInstall
handleExport
handleAliasEnviron
# handleEmptyLogs
handleEnd
exit
elif [ "$arg" == "retool" ]; then # just reinstall bins and export
action="RETOOL"
handleStart
handleCustomBins
handleExport
handleEnd
exit
elif [ "$arg" == "interactive" ]; then
action="REINSTALL (INTERACTIVE)"
# something here lmfao
exit
elif [ "$arg" == "cron" ]; then # full install with warn, sleep, and reboot
action="REINSTALL (CRON)"
gitCmd="git clone --jobs $gitJobs --branch $gitBranch --single-branch https://github.com/espressif/esp-idf $idfDir"
installCmd="$idfDir/install.sh all"
toolsInstallCmd="python $idfDir/tools/idf_tools.py install all"
handleStart
handleLogoutAllUsers
handleSetupEnvironment
handleCustomBins
handleDownloadInstall
handleExport
handleLogoutAllUsers
handleEnd
handleReboot
exit
else # full noninteractive (re)install without logout, reboot, or sleeps
action="REINSTALL (DEFAULT)"
gitCmd="git clone --jobs $gitJobs --branch $gitBranch --single-branch https://github.com/espressif/esp-idf $idfDir"
installCmd="$idfDir/install.sh all"
toolsInstallCmd="python $idfDir/tools/idf_tools.py install all"
handleStart
handleSetupEnvironment
handleCustomBins
handleDownloadInstall
handleExport
handleAliasEnviron
handleEnd
exit
fi
+7 -7
View File
@@ -1,27 +1,27 @@
Modes: Modes:
default: default:
reinstalls non-interactively with no delays, logouts, or reboots reinstalls non-interactively with no delays, logouts, or reboots
`bash cron-reinstall-esp-idf.sh` `bash reinstall-esp-idf.sh`
test: test:
tests the script. very fast. minimal actions taken. no reinstall is done tests the script. very fast. minimal actions taken. no reinstall is done
`bash cron-reinstall-esp-idf.sh test` `bash reinstall-esp-idf.sh test`
retool: retool:
reinstalls bins and export.sh, nothing else reinstalls bins and export.sh, nothing else
`bash cron-reinstall-esp-idf.sh retool` `bash reinstall-esp-idf.sh retool`
cron: cron:
runs noninteractively with forced user logout and automatic reboot, plus delays runs noninteractively with forced user logout and automatic reboot, plus delays
`bash cron-reinstall-esp-idf.sh cron` `bash reinstall-esp-idf.sh cron`
interactive: interactive:
interactively installs/reinstalls esp-idf interactively installs/reinstalls esp-idf
`bash cron-reinstall-esp-idf.sh interactive` `bash reinstall-esp-idf.sh interactive`
help: help:
display this help text display this help text
`bash cron-reinstall-esp-idf.sh help` `bash reinstall-esp-idf.sh help`
Usage: Usage:
@@ -50,7 +50,7 @@ Helpful Stuff:
cron: cron:
reinstall from master everyday at 8pm, logging out users with warn delays and rebooting after reinstall from master everyday at 8pm, logging out users with warn delays and rebooting after
`crontab -e` `crontab -e`
0 8 * * * bash $HOME/esp/esp-install-custom/cron-reinstall-esp-idf.sh cron 0 8 * * * bash $HOME/esp/esp-install-custom/reinstall-esp-idf.sh cron
manually wipe logs: manually wipe logs:
`rm $ESPIDF_INSTALLDIR/install.log; rm $ESPIDF_INSTALLDIR/version-data.txt; touch $ESPIDF_INSTALLDIR/install.log; touch $ESPIDF_INSTALLDIR/version-data.txt;` `rm $ESPIDF_INSTALLDIR/install.log; rm $ESPIDF_INSTALLDIR/version-data.txt; touch $ESPIDF_INSTALLDIR/install.log; touch $ESPIDF_INSTALLDIR/version-data.txt;`
+289 -66
View File
@@ -1,95 +1,318 @@
#!/bin/bash #!/bin/bash
echo -e "\n===== LFGGGGGGGG ======\n" # set -e # for testan, die on eelrror
startTime=$(date '+%s') # to time the (re)install time for the logs
echo -e "\n" myUser=princesspi # user installing esp-ids
# read -p "Enter directory to install/reinstall to (default ${HOME}/esp):" installDir gitJobs=5 # number of jobs to download from github with
# installDir=${installDir:-$HOME/esp} gitBranch=master # branch from github
rcFile=$HOME/.zshrc # shell rc file
installDir="${HOME}/esp" if [ -z $ESPIDF_INSTALLDIR ]; then
installDir=$HOME/esp
gitBranch=master else
installDir=$ESPIDF_INSTALLDIR
gitJobs=5 fi
# echo -e "\nInstalling prerequisites\n"
# sudo apt install -y git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
# installDir=/home/$myUser/esp # install dir
log=$installDir/install.log # log file
versionData=$installDir/version-data.txt # version data log file
idfDir=$installDir/esp-idf # esp-idf path
espressifLocation=$HOME/.espressif # espressif tools install location
customBinLocation=$installDir/.custom_bin # where custom bin scripts are placed
runningDir="$( cd "$( dirname "$0" )" && pwd )" runningDir="$( cd "$( dirname "$0" )" && pwd )"
idfDir="${installDir}/esp-idf" customBinFrom=$runningDir/custom_bin # dir where custom scripts are coming FROM
espressifLocation="${HOME}/.espressif" helpText=$runningDir/help.txt
customBinLocation="${installDir}/.custom_bin" scriptVers=$(cat $runningDir/version.txt) # make sure version.txt does NOT have newline
customBinFrom="${runningDir}/custom_bin" arg=$1 # just rename the argument var for clarity with the functions
echo -e "\nInstalling to ${installDir} esp-idf path will be ${idfDir}\n" # full order:
# handleStart
# handleLogoutAllUsers
# sleepHold
# handleLogoutAllUsers
# handleSetupEnvironment
# handleCustomBins
# handleDownloadInstall
# handleExport
# handleAliasEnviron
# handleLogoutAllUsers
# handleEnd
# handleReboot
# exit
echo -e "\nCleaning up environment\n" function returnStatus() {
strii="\treturn status: ${?}"
echo -e "$strii\n"
echo -e "$strii\n" >> $log
}
if ! [ -d "${installDir}" ]; then function writeToLog() {
echo -e "\n${installDir} not found, creating\n" echo -e "$1"
mkdir "${installDir}" echo -e "$1" >> $log
}
function sleepHold() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling sleep hold (function ran)"
sleepSecs=$(($sleepMins*60)) # calculated seconds of warning to wait for user to log out
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): sleeping ${sleepMins} minutes"
sleep $sleepSecs
returnStatus
}
function handleCustomBins() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling custon bins (function ran)"
if [ -d $customBinLocation ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${customBinLocation}"
rm -rf $customBinLocation
returnStatus
else else
echo -e "\n${installDir} found, skipping delete\n" writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): ${customBinLocation} not found, skipping delete"
fi fi
if [ -d "${idfDir}" ]; then writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): copying scripts from ${customBinFrom} to ${customBinLocation}"
echo -e "\n${idfDir} found, deleting\n" cp -r $customBinFrom $customBinLocation
returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): making scripts executable at ${customBinLocation}"
chmod -R +x $customBinLocation
returnStatus
}
function handleExport() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling export.sh (function ran)"
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): backing up ${idfDir}/export.sh to ${idfDir}/export.sh.bak"
cp $idfDir/export.sh $idfDir/export.sh.bakno
returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): editing ${idfDir}/export.sh"
sed -i 's/return 0/# return 0/g' $idfDir/export.sh
returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): adding ${runningDir}/add-to-export-sh.txt to ${idfDir}/export.sh"
cat $runningDir/add-to-export-sh.txt >> $idfDir/export.sh
returnStatus
}
function handleSetupEnvironment() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling setup environment (function ran)"
if ! [ -d $installDir ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): creating ${installDir}"
mkdir $installDir
returnStatus
fi
if [ -d $idfDir ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${idfDir}"
rm -rf $idfDir rm -rf $idfDir
else returnStatus
echo -e "\n${idfDir} not found, skipping delete\n"
fi fi
if [ -d "${espressifLocation}" ]; then if [ -d $espressifLocation ]; then
echo -e "\n${espressifLocation} found, deleting\n" writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${espressifLocation}"
rm -rf "${espressifLocation}" rm -rf "${espressifLocation}"
else returnStatus
echo -e "\n${espressifLocation} not found, skipping delete\n"
fi fi
}
if [ -d "${customBinLocation}" ]; then function handleAliasEnviron() {
echo -e "\n${customBinLocation} found, deleting\n"
rm -rf "${customBinLocation}"
else
echo -e "\n${customBinLocation} not found, skipping delete\n"
fi
echo -e "\nPlacing and enabeling custom scripts at ${customBinLocation}\n"
cp -r "${customBinFrom}" "${customBinLocation}"
chmod -R +x "${customBinLocation}"
echo -e "\nPulling latest esp-idf code from github\n"
git clone --recursive --jobs $gitJobs --single-branch --branch $gitBranch https://github.com/espressif/esp-idf.git $idfDir
echo -e "\nRunning install script\n"
bash $idfDir/install.sh all
echo -e "\nInstalling optional tools\n"
python $idfDir/tools/idf_tools.py install all
if ! [ -z $(alias | grep get_idf) ]; then if ! [ -z $(alias | grep get_idf) ]; then
echo -e "\nget_idf alias not found, appending to ${HOME}/.zshrc\n" writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): get_idf alias not found, appending to ${$rcFile}"
echo "alias get_idf='. ${idfDir}/export.sh'" >> "${HOME}/.zshrc" echo -e "\nalias get_idf='. ${idfDir}/export.sh'" >> $rcFile
returnStatus
else else
echo -e "\nget_idf alias already installed, skipping\n" writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): get_idf alias already installed, skipping"
fi fi
echo -e "\nMaking a backup of ${idfDir}/export.sh to ${idfDir}/export.sh.bak\n" if [ -z $ESPIDF_INSTALLDIR ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): ESPIDF_INSTALLDIR environment variable not found, appending to ${rcFile}"
echo -e "export ESPIDF_INSTALLDIR=\"${installDir}\"\n" >> $rcFile
returnStatus
else
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): ESPIDF_INSTALLDIR environment variable already installed, skipping"
fi
}
cp "${idfDir}/export.sh" "${idfDir}/export.sh.bak" function handleDownloadInstall() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling download and install (function ran)"
echo -e "\nEditing ${idfDir}/export.sh\n" writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): cloning git branch ${gitBranch} with ${gitJobs} jobs to ${idfDir}"
sed -i 's/return 0/# return 0/g' "${idfDir}/export.sh" eval "$gitCmd"
returnStatus
echo -e "\nAppending custom additions to ${idfDir}/export.sh\n" writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installing with ${idfDir}/install.sh all"
cat "${runningDir}/add-to-export-sh.txt" >> "${idfDir}/export.sh" eval "$installCmd"
returnStatus
echo -e "\nCreating version/commit and date file at ${idfDir}/version-date.txt\n" writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installing tools with python ${idfDir}/tools/idf_tools.py install all"
eval "$toolsInstallCmd"
returnStatus
datestamp=$(date +"%A, %B %-d %Y at %r %Z (epoch %s)") writeToLog "$(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)
# gitBranch=$(git -C $idfDir rev-parse --abbrev-ref HEAD) returnStatus
echo -e "Installed at:\n\t${datestamp}\n\tat commit ${commitHash}\n\tfrom branch ${gitBranch}\n\tsource: https://github.com/espressif/esp-idf" > "${idfDir}/version-data.txt" gitDataLog="$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installed esp-idf from commit $commitHash from branch $gitBranch using $scriptVers"
writeToLog "$gitDataLog"
echo -e "$gitDataLog" >> $versionData
returnStatus
}
handleReboot() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)') Handling reboot: (function ran)"
rebootMsg="$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): rebooting in $sleepMins minutes. save and log out"
writeToLog "$rebootMsg"
echo "$rebootMsg" | sudo write "$myUser"
returnStatus
}
function handleWarn() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling warn (function ran)"
warningString="WARNING:\n\tReinstalling esp-idf in ${sleepMins} minutes! You will be force logged out in ${sleepMins} minutes! Save and log out!\n\tmonitor with \`tail -f -n 50 $HOME/esp/install.log\`\n\tterminate with \`sudo killall reinstall-esp-idf.sh\`\n\t$(date '+%d/%m/%Y %H:%M:%S %Z (%s)')"
writeToLog $warningString
sleepHold
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Force logging out ${myUser}"
echo -e "$warningString" | sudo write "$myUser"
returnStatus
}
function handleLogoutAllUsers() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling user logout (function ran)"
handleWarn
# logout all users
who | sudo awk '$1 !~ /root/{ cmd="/usr/bin/loginctl terminate-user " $1; system(cmd)}'
returnStatus
}
function handleStart() {
if [ -z $sleepMins ]; then
sleepMins="disabled"
fi
if [ -z $ESPIDF_INSTALLDIR ]; then
installdirEnvvar="not set"
else
installdirEnvvar=$ESPIDF_INSTALLDIR
fi
writeToLog "\n === $(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): new ${action} ==="
writeToLog "\tVersion: ${scriptVers}\n"
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)')\nvars:\n\tmyUser: $myUser\n\tscriptVers: $scriptVers\n\tversionData: $versionData\n\tlog: $log\n\tsleepMins: $sleepMins\n\tinstallDir: $installDir\n\tgitJobs: $gitJobs\n\tgitBranch: $gitBranch\n\tgitCmd: $gitCmd\n\trunningDir: $runningDir\n\tidfDir: $idfDir\n\tespressifLocation: $espressifLocation\n\tcustomBinLocation: $customBinLocation\n\tcustomBinFrom: $customBinFrom\n\tinstallCmd: $installCmd\n\ttoolsInstallCmd: $toolsInstallCmd\n\trcFile: $rcFile\n\t(envvar) ESPIDF_INSTALLDIR: $installdirEnvvar"
}
function handleEmptyLogs() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Emptying and touching logs (function ran)"
rm -f $log
touch $log
rm -f $versionData
touch $versionData
}
function handleEnd() {
endTime=$(date '+%s')
timeElapsed=$(($endTime-$startTime))
echo -e "\nesp-idf re/installed! run \`source $rcFile\` and then \`get_idf\`\n to go\n\nAll done :3\n\n"
writeToLog "reinstall completed in $timeElapsed seconds"
writeToLog " === $(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): finished ===\n\n"
}
if [ "$arg" == "--help" -o "$arg" == "help" -o "$arg" == "-h" -o "$arg" == "h" ]; then
cat $helpText;
exit
elif [ "$arg" == "test" ]; then # minimal actions taken, echo the given commands and such
action="TEST"
gitCmd="echo git clone --jobs $gitJobs --branch $gitBranch --single-branch https://github.com/espressif/esp-idf $idfDir"
installCmd="echo $idfDir/install.sh all"
toolsInstallCmd="echo python $idfDir/tools/idf_tools.py install all"
sleepMins=0
handleStart
handleCustomBins
handleDownloadInstall
handleExport
handleAliasEnviron
# handleEmptyLogs
handleEnd
exit
elif [ "$arg" == "retool" ]; then # just reinstall bins and export
action="RETOOL"
handleStart
handleCustomBins
handleExport
handleEnd
exit
elif [ "$arg" == "interactive" ]; then
action="REINSTALL (INTERACTIVE)"
# something here lmfao
exit
elif [ "$arg" == "cron" ]; then # full install with warn, sleep, and reboot
action="REINSTALL (CRON)"
gitCmd="git clone --jobs $gitJobs --branch $gitBranch --single-branch https://github.com/espressif/esp-idf $idfDir"
installCmd="$idfDir/install.sh all"
toolsInstallCmd="python $idfDir/tools/idf_tools.py install all"
handleStart
handleLogoutAllUsers
handleSetupEnvironment
handleCustomBins
handleDownloadInstall
handleExport
handleLogoutAllUsers
handleEnd
handleReboot
exit
else # full noninteractive (re)install without logout, reboot, or sleeps
action="REINSTALL (DEFAULT)"
gitCmd="git clone --jobs $gitJobs --branch $gitBranch --single-branch https://github.com/espressif/esp-idf $idfDir"
installCmd="$idfDir/install.sh all"
toolsInstallCmd="python $idfDir/tools/idf_tools.py install all"
handleStart
handleSetupEnvironment
handleCustomBins
handleDownloadInstall
handleExport
handleAliasEnviron
handleEnd
exit
fi
echo -e '\nRestart shell with `source ~/.zshrc` and run `get_idf` to use\n'
echo -e "\nEnjoy your new esp-idf install and environment\n"
echo -e "\nAll done :3\n"
+1 -1
View File
@@ -1 +1 @@
60-beta.4 60-beta.5