Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage English #2

Merged
merged 8 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,42 @@ post
```
**IMPORTANT** : dont use try or silent if the command have >> | or > or < (output/input redirections), or in the last part of a piped command

try : will try the commands of the line and catch errors (and display them)
silent : no matter if the commands fails
try : will try the commands of the line and catch errors (and display them at the end)

silent : no matter if the commands fails, it'll be silent


add LANG_DEP=en before the `. ${BASEDIR}/dependance.lib` line if you want messages in english instead of french.

**example** :
```
######################### INCLUSION LIB ##########################
BASEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
wget https://raw.githubusercontent.com/NebzHB/dependance.lib/master/dependance.lib -O $BASEDIR/dependance.lib &>/dev/null
PLUGIN=$(basename "$(realpath $BASEDIR/..)")
LANG_DEP=en
. ${BASEDIR}/dependance.lib
##################################################################

pre
```


add TIMED=1 before the `. ${BASEDIR}/dependance.lib` line to time each step.

**example** :
```
######################### INCLUSION LIB ##########################
BASEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
wget https://raw.githubusercontent.com/NebzHB/dependance.lib/master/dependance.lib -O $BASEDIR/dependance.lib &>/dev/null
PLUGIN=$(basename "$(realpath $BASEDIR/..)")
TIMED=1
. ${BASEDIR}/dependance.lib
##################################################################

pre
```


**result if ok** :
```
Expand Down
94 changes: 77 additions & 17 deletions dependance.lib
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ PROGRESS_FILE=${TMPFOLDER}/dependance
HR=$(printf '=%.0s' {1..70})
TAB="echo -n "________""

if [ -z $LANG_DEP ]; then
LANG_DEP=fr
fi

echo_success() {
echo -en "[ OK ]\r"
return 0
}

echo_failure() {
echo -en "[ERREUR]\r"
if [ "$LANG_DEP" = "fr" ];then
echo -en "[ERREUR]\r"
else
echo -en "[ERROR]\r"
fi
return 1
}

Expand Down Expand Up @@ -44,7 +52,11 @@ info() {

pre() {
echo "$HR"
echo "== $(date +'%d/%m/%Y %H:%M:%S') == Installation des dépendances de $PLUGIN"
if [ "$LANG_DEP" = "fr" ];then
echo "== $(date +'%d/%m/%Y %H:%M:%S') == Installation des dépendances de $PLUGIN"
else
echo "== $(date +'%d/%m/%Y %H:%M:%S') == Dependencies installation for $PLUGIN"
fi
echo "$HR"
echo
touch $TMPFOLDER/errorLog.$$
Expand Down Expand Up @@ -82,11 +94,19 @@ try() {
echo 1 > $TMPFOLDER/hasError.$$

local LINE=${BASH_LINENO[0]}
echo -e "== Erreur à l'étape : $STEP_NAME" >> $TMPFOLDER/errorLog.$$
echo -e "== Ligne $LINE" >> $TMPFOLDER/errorLog.$$
echo -e "== La commande \`$*' pose problème" >> $TMPFOLDER/errorLog.$$
echo -e "== Le code de retour est $EXIT_CODE" >> $TMPFOLDER/errorLog.$$
echo -e "== Le message d'erreur :" >> $TMPFOLDER/errorLog.$$
if [ "$LANG_DEP" = "fr" ];then
echo -e "== Erreur à l'étape : $STEP_NAME" >> $TMPFOLDER/errorLog.$$
echo -e "== Ligne $LINE" >> $TMPFOLDER/errorLog.$$
echo -e "== La commande \`$*' pose problème" >> $TMPFOLDER/errorLog.$$
echo -e "== Le code de retour est $EXIT_CODE" >> $TMPFOLDER/errorLog.$$
echo -e "== Le message d'erreur :" >> $TMPFOLDER/errorLog.$$
else
echo -e "== Error in step : $STEP_NAME" >> $TMPFOLDER/errorLog.$$
echo -e "== Line $LINE" >> $TMPFOLDER/errorLog.$$
echo -e "== Command \`$*' have an issue" >> $TMPFOLDER/errorLog.$$
echo -e "== Return code is $EXIT_CODE" >> $TMPFOLDER/errorLog.$$
echo -e "== Error message :" >> $TMPFOLDER/errorLog.$$
fi
echo -e "$cmdout\n" >> $TMPFOLDER/errorLog.$$
echo -e "$HR" >> $TMPFOLDER/errorLog.$$
fi
Expand Down Expand Up @@ -124,63 +144,103 @@ post() {
next
fi
echo 100 > ${PROGRESS_FILE}
echo "[100% ] : Terminé !"
if [ "$LANG_DEP" = "fr" ];then
echo "[100% ] : Terminé !"
else
echo "[100% ] : Finished !"
fi
[[ -f $TMPFOLDER/hasError.$$ ]] && { hasError=$(< $TMPFOLDER/hasError.$$); rm -f $TMPFOLDER/hasError.$$; }
echo
if [[ $hasError -eq 1 ]]; then
echo "$HR"
echo "== KO == Erreur d'Installation"
if [ "$LANG_DEP" = "fr" ];then
echo "== KO == Erreur d'Installation"
else
echo "== KO == Installation Error"
fi
echo "$HR"
[[ -f $TMPFOLDER/errorLog.$$ ]] && {
HAS_FIX=0
echo "== ANALYSE DES ERREURS..."
if [ "$LANG_DEP" = "fr" ];then
echo "== ANALYSE DES ERREURS..."
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
echo "== TROUVÉ 'sudo apt --fix-broken install' dans l'erreur, je lance la commande, attendez 45sec et relancez les dépendances pour réessayer"
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
echo "== TROUVÉ 'dpkg --configure -a' dans l'erreur, je lance la commande, attendez 45sec et relancez les dépendances pour réessayer"
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
echo "== TROUVÉ 'EINTEGRITY' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer"
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
echo "== TROUVÉ 'code 128' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer"
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 'testing' to 'oldstable'" $TMPFOLDER/errorLog.$$ &>/dev/null
FOUND_OLDSTABLE=$?
if [[ $FOUND_OLDSTABLE -eq 0 ]]; then
echo "== TROUVÉ 'changed its 'Suite' value from 'testing' to 'oldstable'' dans l'erreur, je lance une commande pour corriger, attendez 45sec et relancez les dépendances pour réessayer"
if [ "$LANG_DEP" = "fr" ];then
echo "== TROUVÉ -changed its 'Suite' value from 'testing' to 'oldstable'- 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 'testing' to 'oldstable'- in error, launching countermeasures, wait 45sec and relaunch dependencies to retry"
fi
sudo apt-get --allow-releaseinfo-change update
HAS_FIX=1
fi

if [[ $HAS_FIX -eq 0 ]]; then
#show the error
echo "== AUCUNE ERREUR CONNUE DÉTECTÉE"
if [ "$LANG_DEP" = "fr" ];then
echo "== AUCUNE ERREUR CONNUE DÉTECTÉE"
else
echo "== NO KNOWN ERROR DETECTED"
fi
cat $TMPFOLDER/errorLog.$$;
fi
rm -f $TMPFOLDER/errorLog.$$;
}
else
echo "$HR"
echo "== OK == Installation Réussie"
if [ "$LANG_DEP" = "fr" ];then
echo "== OK == Installation Réussie"
else
echo "== OK == Installation Successful"
fi
echo "$HR"
fi
rm -f ${PROGRESS_FILE}
Expand Down