From b5e454e3038a464ff4b98fa05317f2e1415763c3 Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Tue, 28 Jun 2022 18:08:16 +0200 Subject: [PATCH 1/5] implement add_fix_handler `add_fix_handler "string to grep in errors" "message to show if the string is found" "command to fix the error"` or ``` myFixFunc() { echo "this is my fix" } add_fix_handler "string to grep in errors" "message to show if the string is found" myFixFunc ``` or ``` myTestFunct() { echo "this is my test" return 0; # 0 will trigger the fix, other return don't trigger the fix } add_fix_handler myTestFunct "message to show if the string is found" "command to fix the error" ``` or `add_fix_handler "string to grep in errors" "*short message to show in default message" "command to fix the error"` or `add_fix_handler "string to grep in errors" "" "command to fix the error" #empty message uses the default message with "string to grep in errors"` --- dependance.lib | 166 +++++++++++++++++++++++-------------------------- 1 file changed, 78 insertions(+), 88 deletions(-) diff --git a/dependance.lib b/dependance.lib index 59d4a54..4b87fdc 100644 --- a/dependance.lib +++ b/dependance.lib @@ -7,11 +7,20 @@ fi PROGRESS_FILE=${TMPFOLDER}/${PROGRESS_FILENAME} HR=$(printf '=%.0s' {1..70}) TAB="echo -n "________"" +declare -A fix_handlers +h=0 # no fix_handlers if [ -z $LANG_DEP ]; then LANG_DEP=fr fi +add_fix_handler() { + fix_handlers[$h,grepOrFunct]=$1 + fix_handlers[$h,msgIfFound]=$2 + fix_handlers[$h,fixStringOrFunct]=$3 + ((h++)) +} + echo_success() { echo -en "[ OK ]\r" return 0 @@ -144,6 +153,43 @@ next() { return $STEP_OK } +fix () { + for (( f=0;f/dev/null + SEARCH_RESULT=$? + fi + if [ "$SEARCH_RESULT" -eq 0 ];then + if [ "${fix_handlers[$f,msgIfFound]}" = "" ]; then + if [ "$LANG_DEP" = "fr" ]; then + echo "== TROUVÉ '${fix_handlers[$f,grepOrFunct]}' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer" + else + echo "== FOUND '${fix_handlers[$f,grepOrFunct]}' in error, launching countermeasures, wait 45sec and relaunch dependencies to retry" + fi + else + if [ "${fix_handlers[$f,msgIfFound]:0:1}" = "*" ]; then + if [ "$LANG_DEP" = "fr" ]; then + echo "== TROUVÉ '${fix_handlers[$f,msgIfFound]:1}' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer" + else + echo "== FOUND '${fix_handlers[$f,msgIfFound]:1}' in error, launching countermeasures, wait 45sec and relaunch dependencies to retry" + fi + else + echo ${fix_handlers[$f,msgIfFound]} + fi + fi + if [ "$(type -t ${fix_handlers[$f,fixStringOrFunct]})" = "function" ]; then + ${fix_handlers[$f,fixStringOrFunct]} + else + eval ${fix_handlers[$f,fixStringOrFunct]} + fi + HAS_FIX=1 + fi + done +} + post() { if [[ $STEP_IN_PROG -eq 1 ]]; then STEP=99 @@ -176,95 +222,10 @@ post() { else echo "== ANALYSING ERRORS..." fi + #try to fix if possible - grep "apt --fix-broken install" $TMPFOLDER/errorLog.$$ &>/dev/null - FOUND_FIX_BROKEN=$? - if [[ $FOUND_FIX_BROKEN -eq 0 ]]; then - if [ "$LANG_DEP" = "fr" ]; then - echo "== TROUVÉ 'sudo apt --fix-broken install' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer" - else - echo "== FOUND 'sudo apt --fix-broken install' in error, launching countermeasures, wait 45sec and relaunch dependencies to retry" - fi - yes | sudo apt --fix-broken install - HAS_FIX=1 - fi - grep "sudo dpkg --configure -a" $TMPFOLDER/errorLog.$$ &>/dev/null - FOUND_DPKG_CONFIGURE_A=$? - if [[ $FOUND_DPKG_CONFIGURE_A -eq 0 ]]; then - if [ "$LANG_DEP" = "fr" ]; then - echo "== TROUVÉ 'dpkg --configure -a' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer" - else - echo "== FOUND 'dpkg --configure -a' in error, launching countermeasures, wait 45sec and relaunch dependencies to retry" - fi - sudo dpkg --configure -a --force-confdef - HAS_FIX=1 - fi - grep "EINTEGRITY" $TMPFOLDER/errorLog.$$ &>/dev/null - FOUND_EINTEGRITY=$? - if [[ $FOUND_EINTEGRITY -eq 0 ]]; then - if [ "$LANG_DEP" = "fr" ]; then - echo "== TROUVÉ 'EINTEGRITY' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer" - else - echo "== FOUND 'EINTEGRITY' in error, launching countermeasures, wait 45sec and relaunch dependencies to retry" - fi - sudo npm cache clean --force - HAS_FIX=1 - fi - grep "npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/" $TMPFOLDER/errorLog.$$ &>/dev/null - FOUND_E128=$? - if [[ $FOUND_E128 -eq 0 ]]; then - if [ "$LANG_DEP" = "fr" ]; then - echo "== TROUVÉ 'code 128' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer" - else - echo "== FOUND 'code 128' in error, launching countermeasures, wait 45sec and relaunch dependencies to retry" - fi - sudo chown -R root:root /root/.npm - HAS_FIX=1 - fi - grep "changed its 'Suite' value from" $TMPFOLDER/errorLog.$$ &>/dev/null - FOUND_SUITECHANGED=$? - if [[ $FOUND_SUITECHANGED -eq 0 ]]; then - if [ "$LANG_DEP" = "fr" ]; then - echo "== TROUVÉ -changed its 'Suite' value from- dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer" - else - echo "== FOUND -changed its 'Suite' value from- in error, launching countermeasures, wait 45sec and relaunch dependencies to retry" - fi - sudo apt-get --allow-releaseinfo-change update - HAS_FIX=1 - fi - grep "npm ERR! dest /usr/local/lib/node_modules/.homebridge-config-ui-x-" $TMPFOLDER/errorLog.$$ &>/dev/null - FOUND_ENOTEMPTY=$? - if [[ $FOUND_ENOTEMPTY -eq 0 ]]; then - if [ "$LANG_DEP" = "fr" ]; then - echo "== TROUVÉ 'ENOTEMPTY' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer" - else - echo "== FOUND 'ENOTEMPTY' in error, launching countermeasures, wait 45sec and relaunch dependencies to retry" - fi - sudo rm -fR /usr/local/lib/node_modules/.homebridge-config-ui-x-* - HAS_FIX=1 - fi - grep "npm ERR! dest /usr/lib/node_modules/.homebridge-config-ui-x-" $TMPFOLDER/errorLog.$$ &>/dev/null - FOUND_ENOTEMPTY=$? - if [[ $FOUND_ENOTEMPTY -eq 0 ]]; then - if [ "$LANG_DEP" = "fr" ]; then - echo "== TROUVÉ 'ENOTEMPTY' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer" - else - echo "== FOUND 'ENOTEMPTY' in error, launching countermeasures, wait 45sec and relaunch dependencies to retry" - fi - sudo rm -fR /usr/lib/node_modules/.homebridge-config-ui-x-* - HAS_FIX=1 - fi - npm -v | grep "8.11.0" &>/dev/null - NPM_8110=$? - if [[ $NPM_8110 -eq 0 ]]; then - if [ "$LANG_DEP" = "fr" ]; then - echo "== TROUVÉ 'NPM 8.11.0', je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer" - else - echo "== FOUND 'NPM 8.11.0', launching countermeasures, wait 45sec and relaunch dependencies to retry" - fi - sudo npm install -g npm@8.12.2 - HAS_FIX=1 - fi + fix + if [[ $HAS_FIX -eq 0 ]]; then #show the error if [ "$LANG_DEP" = "fr" ]; then @@ -291,3 +252,32 @@ post() { fi rm -f ${PROGRESS_FILE} } + +# fix apt broken install +add_fix_handler "apt --fix-broken install" "" "yes | sudo apt --fix-broken install" + +# fix dkpg error (probably stopped during apt install) +add_fix_handler "sudo dpkg --configure -a" "*dpkg --configure -a" "sudo dpkg --configure -a --force-confdef" + +# fix npm cache integrity issue +add_fix_handler "EINTEGRITY" "" "sudo npm cache clean --force" + +# fix npm cache permissions +add_fix_handler "npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/" "*code 128" "sudo chown -R root:root /root/.npm" + +# if debian have changed the Suite value, allow releaseinfo change in apt-get +add_fix_handler "changed its 'Suite' value from" "*changed its Suite value from" "sudo apt-get --allow-releaseinfo-change update" + +# check for ENOTEMPTY error in both /usr and /usr/local +add_fix_handler "npm ERR! dest /usr/local/lib/node_modules/.homebridge-config-ui-x-" "*ENOTEMPTY" "sudo rm -fR /usr/local/lib/node_modules/.homebridge-config-ui-x-*" +add_fix_handler "npm ERR! dest /usr/lib/node_modules/.homebridge-config-ui-x-" "*ENOTEMPTY" "sudo rm -fR /usr/lib/node_modules/.homebridge-config-ui-x-*" + +# check if npm is v8.11.0, if it is upgrade to 8.12.2 (bug in 8.11.0) +test_npm_ver() { + npm -v | grep "8.11.0" &>/dev/null + return $? +} +fix_npm_ver() { + sudo npm install -g npm@8.12.2 +} +add_fix_handler test_npm_ver "*NPM 8.11.0" fix_npm_ver From 72c1b708d7c8586dcddbe38497c6afd5269be385 Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Tue, 28 Jun 2022 18:13:48 +0200 Subject: [PATCH 2/5] Update README.md --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/README.md b/README.md index cd3ee1c..02ad026 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,64 @@ E: Unable to locate package fdsfqfqfsqdf ====================================================================== ``` +# NEW + +Implement your own error handler add your handler anywhere after the *include header* and before the `post` : + +``` +add_fix_handler "string to grep in errors" "message to show if the string is found" "command to fix the error" +``` + +or + +``` +myFixFunc() { + echo "this is my fix" +} +add_fix_handler "string to grep in errors" "message to show if the string is found" myFixFunc +``` + +or + +``` +myTestFunct() { + echo "this is my test" + return 0; # 0 will trigger the fix, other return don't trigger the fix +} +add_fix_handler myTestFunct "message to show if the string is found" "command to fix the error" +``` + +or + +``` +add_fix_handler "string to grep in errors" "*short message to show in default message" "command to fix the error" +``` + +or + +``` +add_fix_handler "string to grep in errors" "" "command to fix the error" #empty message uses the default message with "string to grep in errors" +``` + +Real life examples : + +``` +test_npm_ver() { + npm -v | grep "8.11.0" &>/dev/null + return $? +} +fix_npm_ver() { + sudo npm install -g npm@8.12.2 +} +add_fix_handler test_npm_ver "*NPM 8.11.0" fix_npm_ver +``` + +or + +``` +add_fix_handler "EINTEGRITY" "" "sudo npm cache clean --force" +``` + Auto fix for this common errors : `apt --fix-broken install` From 2025fb8a5868f8d1fd1fb61ab11baad34114e369 Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Wed, 29 Jun 2022 06:59:12 +0200 Subject: [PATCH 3/5] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 02ad026..044d3b4 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ E: Unable to locate package fdsfqfqfsqdf # NEW -Implement your own error handler add your handler anywhere after the *include header* and before the `post` : +Implement your own error handler : add your handler anywhere after the *include header* and before the `post` cmd : ``` add_fix_handler "string to grep in errors" "message to show if the string is found" "command to fix the error" @@ -148,7 +148,7 @@ or ``` myTestFunct() { echo "this is my test" - return 0; # 0 will trigger the fix, other return don't trigger the fix + return 0; # 0 will trigger the fix, other return value don't trigger the fix } add_fix_handler myTestFunct "message to show if the string is found" "command to fix the error" ``` @@ -184,14 +184,14 @@ or add_fix_handler "EINTEGRITY" "" "sudo npm cache clean --force" ``` -Auto fix for this common errors : +Auto fix alreday included for this common errors : - `apt --fix-broken install` + apt `apt --fix-broken install` - `sudo dpkg --configure -a` + dkpg `sudo dpkg --configure -a` - `EINTEGRITY` + npm `EINTEGRITY` - `npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/'` + npm `npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/'` - `changed its 'Suite' value from 'testing' to 'oldstable'` + apt `changed its 'Suite' value from 'testing' to 'oldstable'` From fb0baafb39c8a5fb599111263bef4669a8df334b Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Thu, 7 Jul 2022 09:01:11 +0200 Subject: [PATCH 4/5] remove npm fix (directly in nodejs_installer) --- dependance.lib | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/dependance.lib b/dependance.lib index 4b87fdc..cb44d78 100644 --- a/dependance.lib +++ b/dependance.lib @@ -271,13 +271,3 @@ add_fix_handler "changed its 'Suite' value from" "*changed its Suite value from" # check for ENOTEMPTY error in both /usr and /usr/local add_fix_handler "npm ERR! dest /usr/local/lib/node_modules/.homebridge-config-ui-x-" "*ENOTEMPTY" "sudo rm -fR /usr/local/lib/node_modules/.homebridge-config-ui-x-*" add_fix_handler "npm ERR! dest /usr/lib/node_modules/.homebridge-config-ui-x-" "*ENOTEMPTY" "sudo rm -fR /usr/lib/node_modules/.homebridge-config-ui-x-*" - -# check if npm is v8.11.0, if it is upgrade to 8.12.2 (bug in 8.11.0) -test_npm_ver() { - npm -v | grep "8.11.0" &>/dev/null - return $? -} -fix_npm_ver() { - sudo npm install -g npm@8.12.2 -} -add_fix_handler test_npm_ver "*NPM 8.11.0" fix_npm_ver From a15a7adda3d919beae8538bad2cf8b61671d96d9 Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Sun, 17 Jul 2022 10:01:25 +0200 Subject: [PATCH 5/5] Update dependance.lib --- dependance.lib | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dependance.lib b/dependance.lib index cb44d78..d61bbf9 100644 --- a/dependance.lib +++ b/dependance.lib @@ -271,3 +271,6 @@ add_fix_handler "changed its 'Suite' value from" "*changed its Suite value from" # check for ENOTEMPTY error in both /usr and /usr/local add_fix_handler "npm ERR! dest /usr/local/lib/node_modules/.homebridge-config-ui-x-" "*ENOTEMPTY" "sudo rm -fR /usr/local/lib/node_modules/.homebridge-config-ui-x-*" add_fix_handler "npm ERR! dest /usr/lib/node_modules/.homebridge-config-ui-x-" "*ENOTEMPTY" "sudo rm -fR /usr/lib/node_modules/.homebridge-config-ui-x-*" + +add_fix_handler "npm ERR! dest /usr/local/lib/node_modules/.homebridge-alexa-" "*ENOTEMPTY" "sudo rm -fR /usr/local/lib/node_modules/.homebridge-alexa-*" +add_fix_handler "npm ERR! dest /usr/lib/node_modules/.homebridge-alexa-" "*ENOTEMPTY" "sudo rm -fR /usr/lib/node_modules/.homebridge-alexa-*"