diff --git a/reinstall-esp-idf.sh b/reinstall-esp-idf.sh index 14cc2ba..ce0a0d5 100644 --- a/reinstall-esp-idf.sh +++ b/reinstall-esp-idf.sh @@ -1,64 +1,89 @@ -echo "\n===== LFGGGGGGGG ======\n" +#!/bin/bash +set -e # exit on any error -echo "\nInstalling prerequisites\n" +runningDir="$( cd "$( dirname "$0" )" && pwd )" + +echo -e "\n===== LFGGGGGGGG ======\n" + +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 -echo "\nCleaning up environment\n" -if ! [ -d ~/esp ]; then - echo "\n~/esp not found, creating\n" - mkdir ~/esp - else - echo "\n~/esp found, skipping\n" +echo -e "\n" + +read -p "Enter directory to install/reinstall to (default ${HOME}/esp):" installDir + +installDir=${installDir:-$HOME/esp} +idfDir="${installDir}/esp-idf" + +echo -e "\nInstalling to ${installDir} esp-idf path will be ${idfDir}\n" + +echo -e "\nCleaning up environment\n" +if ! [ -d $installDir ]; then + echo -e "\n${installDir} not found, creating\n" + mkdir $installDir +else + echo -e "\n${installDir} found, skipping delete\n" fi -if [ -d ~/esp/esp-idf ]; then - echo "\n~/esp/esp-idf found, deleting\n" - rm -rf ~/esp/esp-idf - else - echo "\n~/esp/esp-idf not found, skipping\n" +if [ -d "${idfDir}" ]; then + echo -e "\n${idfDir} found, deleting\n" + rm -rf $idfDir +else + echo -e "\n${idfDir} not found, skipping delete\n" fi -if [ -d ~/.espressif ]; then - echo "\n~/.espressif found, deleting\n" - rm -rf ~/.espressif - else - echo "\n~/.espressif not found, skipping\n" +if [ -d "${HOME}/.espressif" ]; then + echo -e "\n${HOME}/.espressif found, deleting\n" + rm -rf "${HOME}/.espressif" +else + echo -e "\n${HOME} not found, skipping delete\n" fi -if [ -d ~/esp/.custom_bin ]; then - echo "\n~/esp/.custom_bin found, deleting\n" - rm -rf ~/esp/.custom_bin +if [ -d "${installDir}/.custom_bin" ]; then + echo -e "\n${installDir}/.custom_bin found, deleting\n" + rm -rf "${installDir}/.custom_bin" +else + echo -e "\n${installDir}/.custom_bin not found, skipping delete\n" fi -echo "\nPlacing and enabeling custom bins\n" -cp -r .custom_bin ~/esp -chmod +x ~/esp/.custom_bin/* +echo -e "\nPlacing and enabeling custom bins\n" +cp -r .custom_bin $installDir +chmod +x "${installDir}/.custom_bin/*" -echo "\nPulling latest esp-idf code from github\n" -git clone --recursive --jobs 5 https://github.com/espressif/esp-idf.git ~/esp/esp-idf +echo -e "\nPulling latest esp-idf code from github\n" +git clone --recursive --jobs 5 https://github.com/espressif/esp-idf.git $idfDir -echo "\nRunning install script\n" -bash ~/esp/esp-idf/install.sh all +echo -e "\nRunning install script\n" +bash "${idfDir}/install.sh all" -echo "\nInstalling optional tools\n" -python ~/esp/esp-idf/tools/idf_tools.py install all +echo -e "\nInstalling optional tools\n" +python "${idfDir}/tools/idf_tools.py install all" if ! [ -z $(alias | grep get_idf) ]; then - echo "\nget_idf alias not found, appending to ~/.zshrc\n" - echo "alias get_idf='. ~/esp/esp-idf/export.sh'" >> ~/.zshrc - else - echo "\nget_idf alias already installed, skipping\n" + echo -e "\nget_idf alias not found, appending to ${HOME}/.zshrc\n" + echo "alias get_idf='. ${idfDir}export.sh'" >> ~/.zshrc +else + echo -e "\nget_idf alias already installed, skipping\n" fi -echo "\nMaking a backup of ~/esp/esp-idf/export.sh to ~/esp/esp-idf/export.sh.bak\n" -cp ~/esp/esp-idf/export.sh ~/esp/esp-idf/export.sh.bak +echo -e "\nMaking a backup of ${idfDir}/export.sh to +${idfDir}/export.sh.bak\n" +cp "${idfDir}/export.sh" "${idfDir}/export.sh.bak" -echo "\nEditing ~/esp/esp-idf/export.sh\n" -sed -i 's/return 0/# return 0/g' ~/esp/esp-idf/export.sh +echo -e "\nEditing ${idfDir}/export.sh\n" +sed -i 's/return 0/# return 0/g' "${idfDir}/export.sh" -echo "\nAppending custom additions to ~/esp/esp-idf/export.sh\n" -cat ./add-to-export-sh.txt >> ~/esp/esp-idf/export.sh +echo -e "\nAppending custom additions to ${idfDir}/export.sh\n" +cat "${runningDir}/add-to-export-sh.txt" >> "${idfDir}/export.sh" -echo '\nRestart shell with `source ~/.zshrc` and run `get_idf` to use\n' -echo "\nEnjoy your new esp-idf install and environment\n" -echo "\nAll done :3\n" +echo -e "\nCreating version/commit and date file at ${idfDir}/version-date.txt\n" + +datestamp=$(date +"%A, %B %-d %Y at %r %Z (epoch %s)") +commitHash=$(git -C "${idfDir} rev-parse HEAD") +gitBranch=$(git -C "${idfDir} rev-parse --abbrev-ref HEAD") + +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" + +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" diff --git a/test-scratch.sh b/test-scratch.sh new file mode 100644 index 0000000..5434e02 --- /dev/null +++ b/test-scratch.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +echo "Script executed from: ${PWD}" + +BASEDIR=$(dirname $0) +echo "Script location: ${BASEDIR}" + +DIR="$( cd "$( dirname "$0" )" && pwd )" +echo $DIR \ No newline at end of file