This commit is contained in:
2024-11-12 11:25:47 -07:00
parent 601529345e
commit 4add95da8f
3 changed files with 64 additions and 46 deletions
+8 -2
View File
@@ -5,9 +5,12 @@
# begin esp-idf stuffss I made ################ # begin esp-idf stuffss I made ################
############################################### ###############################################
echo "\n=======CUSTOM=======\n" echo "\n=======CUSTOM=======\n"
versionData="versionTAG"
commitHash="commitTagTAG"
installDate="installDateTAG"
if [ -z $ESPIDF_INSTALLDIR ]; then if [ -z $ESPIDF_INSTALLDIR ]; then
echo "\nFAIL: ESPIDF_INSTALLDIR environment variable not found!\nReinstall via script or manually add to ~/.zshrc\n" echo "\nFAIL: ESPIDF_INSTALLDIR environment variable not found!\nReinstall via script or manually add to ~/.zshrc\n"
exit exit
@@ -15,7 +18,6 @@ fi
binDir="${ESPIDF_INSTALLDIR}/.custom_bin" binDir="${ESPIDF_INSTALLDIR}/.custom_bin"
echo "TTY devices found in dmesg:" echo "TTY devices found in dmesg:"
COUNTER=0 COUNTER=0
devarr=() devarr=()
@@ -40,6 +42,10 @@ export ESPPORT="${ttyselect}"
export ESPBAUD=460800 export ESPBAUD=460800
export ESPTARGET=$esp export ESPTARGET=$esp
echo "esp-install-custom version: $versionData"
echo "esp-idf commmit hash: $commitHash"
echo "install date: $installDate"
echo "ESPBAUD = ${ESPBAUD}" echo "ESPBAUD = ${ESPBAUD}"
echo "ESPTARGET = ${ESPTARGET}" echo "ESPTARGET = ${ESPTARGET}"
echo "ESPPORT = ${ESPPORT}" echo "ESPPORT = ${ESPPORT}"
+55 -43
View File
@@ -53,73 +53,81 @@ function returnStatus() {
} }
function writeToLog() { function writeToLog() {
echo -e "$1" echo -e "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): $1"
echo -e "$1" >> $log echo -e "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): $1" >> $log
} }
function handleSleep() { function handleSleep() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling sleep hold (function ran)" writeToLog "Handling sleep hold (function ran)"
sleepSecs=$(($sleepMins*60)) # calculated seconds of warning to wait for user to log out 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" writeToLog "sleeping ${sleepMins} minutes"
sleep $sleepSecs sleep $sleepSecs
returnStatus returnStatus
} }
function handleCustomBins() { function handleCustomBins() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling custon bins (function ran)" writeToLog "Handling custon bins (function ran)"
if [ -d $customBinLocation ]; then if [ -d $customBinLocation ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${customBinLocation}" writeToLog "deleting ${customBinLocation}"
rm -rf $customBinLocation rm -rf $customBinLocation
returnStatus returnStatus
else else
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): ${customBinLocation} not found, skipping delete" writeToLog "${customBinLocation} not found, skipping delete"
fi fi
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): copying scripts from ${customBinFrom} to ${customBinLocation}" writeToLog "copying scripts from ${customBinFrom} to ${customBinLocation}"
cp -r $customBinFrom $customBinLocation cp -r $customBinFrom $customBinLocation
returnStatus returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): making scripts executable at ${customBinLocation}" writeToLog "making scripts executable at ${customBinLocation}"
chmod -R +x $customBinLocation chmod -R +x $customBinLocation
returnStatus returnStatus
} }
function handleExport() { function handleExport() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling export.sh (function ran)" writeToLog "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" writeToLog "backing up ${idfDir}/export.sh to ${idfDir}/export.sh.bak"
cp $idfDir/export.sh $idfDir/export.sh.bakno cp $idfDir/export.sh $idfDir/export.sh.bakno
returnStatus returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): editing ${idfDir}/export.sh" writeToLog "editing ${idfDir}/export.sh"
sed -i 's/return 0/# return 0/g' $idfDir/export.sh sed -i 's/return 0/# return 0/g' $idfDir/export.sh
returnStatus returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): adding ${runningDir}/add-to-export-sh.txt to ${idfDir}/export.sh" writeToLog "adding ${runningDir}/add-to-export-sh.txt to ${idfDir}/export.sh"
cat $runningDir/add-to-export-sh.txt >> $idfDir/export.sh cat $runningDir/add-to-export-sh.txt >> $idfDir/export.sh
returnStatus returnStatus
writeToLog "editing $idfDir/export.sh with version information"
sed -i "s/versionTAG/${versionData}/g" $idfDir/export.sh
returnStatus
writeToLog "editing $idfDir/export.sh with install date information"
sed -i "s/versionTAG/$(date '+%d/%m/%Y %H:%M:%S %Z (%s)')/g" $idfDir/export.sh
returnStatus
} }
function handleSetupEnvironment() { function handleSetupEnvironment() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling setup environment (function ran)" writeToLog "Handling setup environment (function ran)"
if ! [ -d $installDir ]; then if ! [ -d $installDir ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): creating ${installDir}" writeToLog "creating ${installDir}"
mkdir $installDir mkdir $installDir
returnStatus returnStatus
fi fi
if [ -d $idfDir ]; then if [ -d $idfDir ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${idfDir}" writeToLog "deleting ${idfDir}"
rm -rf $idfDir rm -rf $idfDir
returnStatus returnStatus
fi fi
if [ -d $espressifLocation ]; then if [ -d $espressifLocation ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): deleting ${espressifLocation}" writeToLog "deleting ${espressifLocation}"
rm -rf "${espressifLocation}" rm -rf "${espressifLocation}"
returnStatus returnStatus
fi fi
@@ -127,67 +135,71 @@ function handleSetupEnvironment() {
function handleAliasEnviron() { function handleAliasEnviron() {
if ! [ -z $(alias | grep get_idf) ]; then 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}" writeToLog "get_idf alias not found, appending to ${$rcFile}"
echo -e "\nalias get_idf='. ${idfDir}/export.sh'" >> $rcFile echo -e "\nalias get_idf='. ${idfDir}/export.sh'" >> $rcFile
returnStatus returnStatus
else else
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): get_idf alias already installed, skipping" writeToLog "get_idf alias already installed, skipping"
fi fi
if [ -z $ESPIDF_INSTALLDIR ]; then if [ -z $ESPIDF_INSTALLDIR ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): ESPIDF_INSTALLDIR environment variable not found, appending to ${rcFile}" writeToLog "ESPIDF_INSTALLDIR environment variable not found, appending to ${rcFile}"
echo -e "export ESPIDF_INSTALLDIR=\"${installDir}\"\n" >> $rcFile echo -e "export ESPIDF_INSTALLDIR=\"${installDir}\"\n" >> $rcFile
returnStatus returnStatus
else else
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): ESPIDF_INSTALLDIR environment variable already installed, skipping" writeToLog "ESPIDF_INSTALLDIR environment variable already installed, skipping"
fi fi
} }
function handleDownloadInstall() { function handleDownloadInstall() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling download and install (function ran)" writeToLog "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}" writeToLog "cloning git branch ${gitBranch} with ${gitJobs} jobs to ${idfDir}"
eval "$gitCmd" eval "$gitCmd"
returnStatus returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installing with ${idfDir}/install.sh all" writeToLog "installing with ${idfDir}/install.sh all"
eval "$installCmd" eval "$installCmd"
returnStatus returnStatus
# silly python envvar workans testant # silly python envvar workans testant
if [ -z $IDF_PYTHON_ENV_PATH ]; then if [ -z $IDF_PYTHON_ENV_PATH ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): IDF_PYTHON_ENV_PATH not set" writeToLog "IDF_PYTHON_ENV_PATH not set"
return return
else else
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): IDF_PYTHON_ENV_PATH: $IDF_PYTHON_ENV_PATH" writeToLog "IDF_PYTHON_ENV_PATH: $IDF_PYTHON_ENV_PATH"
ls -lah $IDF_PYTHON_ENV_PATH/bin/python ls -lah $IDF_PYTHON_ENV_PATH/bin/python
returnStatus returnStatus
fi fi
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installing tools with python ${idfDir}/tools/idf_tools.py install all" writeToLog "installing tools with python ${idfDir}/tools/idf_tools.py install all"
eval "$toolsInstallCmd" eval "$toolsInstallCmd"
returnStatus returnStatus
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): getting the commit hash" writeToLog "getting the commit hash"
commitHash=$(git -C $idfDir rev-parse HEAD) commitHash=$(git -C $idfDir rev-parse HEAD)
returnStatus returnStatus
gitDataLog="$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): installed esp-idf from commit $commitHash from branch $gitBranch using $scriptVers" writeToLog "editing $idfDir/export.sh with git commit hash data"
sed -i "s/commitTagTAG/${commitHash}/g" $idfDir/export.sh
returnStatus
gitDataLog="installed esp-idf from commit $commitHash from branch $gitBranch using $scriptVers"
writeToLog "$gitDataLog" writeToLog "$gitDataLog"
echo -e "$gitDataLog" >> $versionData echo -e "$gitDataLog" >> $versionData
returnStatus returnStatus
} }
handleReboot() { handleReboot() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)') Handling reboot: (function ran)" writeToLog "Handling reboot: (function ran)"
sudo reboot sudo reboot
} }
handleWarnAllUsers() { handleWarnAllUsers() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Warning all users of impending logout (function called)" writeToLog "Warning all users of impending logout (function called)"
warningString="$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'):\nWARNING:\n\tReinstalling esp-idf:\n\tForce logut in ${sleepMins} minutes!!\n\tSave and log out!\n\tmonitor with \`tail -f -n 50 $HOME/esp/install.log\`\n\tterminate with \`sudo killall reinstall-esp-idf.sh\`" warningString="\nWARNING:\n\tReinstalling esp-idf:\n\tForce logut in ${sleepMins} minutes!!\n\tSave and log out!\n\tmonitor with \`tail -f -n 50 $HOME/esp/install.log\`\n\tterminate with \`sudo killall reinstall-esp-idf.sh\`"
writeToLog "$warningString" writeToLog "$warningString"
@@ -196,10 +208,10 @@ handleWarnAllUsers() {
loggedIn=$(who | awk '{print $1}' | uniq) loggedIn=$(who | awk '{print $1}' | uniq)
if [ -z $loggedIn ]; then if [ -z $loggedIn ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): no users logged in to warn" writeToLog "no users logged in to warn"
return return
else else
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Warning all logged in users:" # make sure dis workan writeToLog "Warning all logged in users:" # make sure dis workan
echo $loggedIn | while read line; do echo $loggedIn | while read line; do
writeToLog "\tWarning $line" writeToLog "\tWarning $line"
@@ -211,17 +223,17 @@ handleWarnAllUsers() {
} }
function handleLogoutAllUsers() { function handleLogoutAllUsers() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Handling user logout (function ran)" writeToLog "Handling user logout (function ran)"
handleWarnAllUsers handleWarnAllUsers
loggedIn=$(who | awk '{print $1}' | uniq) loggedIn=$(who | awk '{print $1}' | uniq)
if [ -z $loggedIn ]; then if [ -z $loggedIn ]; then
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): no logged in users to log out" writeToLog "no logged in users to log out"
return return
else else
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): logging out all logged in users:" writeToLog "logging out all logged in users:"
echo $loggedIn | while read line; do echo $loggedIn | while read line; do
writeToLog "\tlogging out $line" writeToLog "\tlogging out $line"
sudo loginctl terminate-user $line sudo loginctl terminate-user $line
@@ -243,15 +255,15 @@ function handleStart() {
fi fi
if [ "$arg" != "interactive" -a "$arg" != "i" ]; then if [ "$arg" != "interactive" -a "$arg" != "i" ]; then
writeToLog "\n === $(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): new ${action} ===" writeToLog "\n === new ${action} ==="
writeToLog "\tVersion: ${scriptVers}\n" writeToLog "\tVersion: ${scriptVers}\n"
fi fi
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)')\nvars:\n\tuser: $USER\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" writeToLog "\nvars:\n\tuser: $USER\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() { function handleEmptyLogs() {
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Emptying and touching logs (function ran)" writeToLog "Emptying and touching logs (function ran)"
rm -f $log rm -f $log
touch $log touch $log
@@ -267,7 +279,7 @@ function handleEnd() {
echo -e "\nesp-idf re/installed! run \`source $rcFile\` and then \`get_idf\`\n to go\n\nAll done :3\n\n" 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 "reinstall completed in $timeElapsed seconds"
writeToLog " === $(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): finished ===\n\n" writeToLog " === finished ===\n\n"
} }
if [ "$arg" == "--help" -o "$arg" == "help" -o "$arg" == "-h" -o "$arg" == "h" ]; then if [ "$arg" == "--help" -o "$arg" == "help" -o "$arg" == "-h" -o "$arg" == "h" ]; then
@@ -336,10 +348,10 @@ elif [ "$arg" == "interactive" -o "$arg" == "i" ]; then
gitJobs=$readGitJobs gitJobs=$readGitJobs
fi fi
writeToLog "\n === $(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): new ${action} ===" writeToLog "\n === new ${action} ==="
writeToLog "\tVersion: ${scriptVers}\n" writeToLog "\tVersion: ${scriptVers}\n"
writeToLog "$(date '+%d/%m/%Y %H:%M:%S %Z (%s)'): Interactive vars set:\n\tinstallDir: $installDir\n\tgitBranch: $gitBranch\n\trcFile: $rcFile\n\tgitJobs: $gitJobs" writeToLog "Interactive vars set:\n\tinstallDir: $installDir\n\tgitBranch: $gitBranch\n\trcFile: $rcFile\n\tgitJobs: $gitJobs"
handleStart handleStart
handleSetupEnvironment handleSetupEnvironment
+1 -1
View File
@@ -1 +1 @@
60-rc1 60-rc1.1