FIX: the download_front.sh code

That was update a lot. I've added verification skills to this script
This commit is contained in:
Michel Pereira 2023-01-28 16:26:20 -03:00 committed by GitHub
parent 41977541a4
commit 42bf6b15e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,57 +7,129 @@ printf "1 - Verifying if unzip is installed ...\n\n";
unzip -v > /dev/null 2>&1;
if test $? -ne 0 ; then # bash POSIX >> if [[ $(test $? -ne 0) ]]
if test $? -ne 0 ; then # bash POSIX >> if [[ $(test $? -ne 0) ]]
printf " FAIL - It seems unzip is not installed. Let's install it now ...\n\n" ;
printf " 1.1 - Installing unzip ...\n\n";
printf " It seems unzip is not installed. Let's install it now ...\n\n" ;
printf " 1.1 - Installing unzip ...\n\n";
apt-get install unzip -y > /dev/null 2>&1 ;
if ! test $? -eq 0 ; then
printf " FAIL - Installation FAILED. \n\t Please, run this script with elevated privileges OR trying install unzip manually then go back here :) \n\n" ;
if ! test $? -eq 0 ; then
printf ' FAIL - Installation FAILED. \n"
printf " Possible solutions here are:\n\n" ;
printf " # Please, execute this script with elevated privileges
printf " # OR: trying install unzip manually then go back here %s \n\n' ':)' ;
printf "See ya! \n\n";
exit 1;
else
printf " OK - unzip INSTALLED\n\n";
fi
else
printf " OK - unzip is already installed.\n\n";
printf " OK - unzip is ALREADY installed.\n\n";
fi
printf "2 - Downloading repository ...\n\n" ;
printf "2 - Verifying if repository is already downloaded ...\n\n" ;
wget -c -O front-repo https://github.com/becauro/games-store-front/archive/refs/heads/main.zip > /dev/null 2>&1 ;
ls front-repo > /dev/null 2>&1
if test $? -ne 0 ; then
if test $? -ne 0; then
printf " FAIL - download FAILED. \n\t Please, check parent folder permissions then go back here OR trying download repo manually :) \n\n" ;
printf "Exiting...! \n\n";
exit 1;
#######
else
printf " OK - Repo downloaded!\n\n" ;
ls ../games-store-front-main > /dev/null 2>&1
fi
if test $? -ne 0; then
ls ../games-store-front > /dev/null 2>&1
if test $? -ne 0; then
printf " Downloading repository ...\n\n" ;
wget -c -O front-repo https://github.com/becauro/games-store-front/archive/refs/heads/main.zip > /dev/null 2>&1 ;
if test $? -ne 0 ; then
printf " FAIL - download FAILED. \n"
printf " Possible solutions here are:\n\n" ;
printf " # Check parent folder permissions then execute this script again\n"
printf " # OR: trying to download the frontend repo manually at https://github.com/becauro/games-store-front/archive/refs/heads/main.zip and rename it to 'front-repo' \n\n" ;
printf " When you get it done, execute this script again\n\n"
printf "Exiting...! \n\n";
exit 1;
else
printf " OK - Repo downloaded!\n\n" ;
fi
else
printf " OK - Repo ALREADY downloaded!\n\n" ;
fi
else
printf " OK - Repo ALREADY downloaded!\n\n" ;
fi
#######
else
printf " OK - Repo ALREADY downloaded!\n\n" ;
fi
printf "3 - Unziping file ... \n\n" ;
unzip front-repo -d .. > /dev/null 2>&1 ;
printf "3 - Verifying unziping ...\n\n";
if test $? -ne 0 ; then
ls ../games-store-front-main > /dev/null 2>&1
printf " FAIL - unziping FAILED. \n\t Please, check the current/parent folder permissions, run this script with elevated privileges \
OR trying unzip the file manually :) \n\n" ;
if test $? -ne 0; then
printf "Exiting...! \n\n";
exit 1;
ls ../games-store-front > /dev/null 2>&1
else
printf " OK - file unziped! \n\n" ;
if test $? -ne 0; then
printf "Unziping the file ... \n\n" ;
unzip front-repo -d .. > /dev/null 2>&1 ;
if test $? -ne 0 ; then
printf " FAIL - unziping FAILED.\n"
printf " Possible solutions --- If you are under the 'games-store-back' folder:\n\n" ;
printf " # Trying unzip the file manually.\n"
printf " # OR: If the folder is already extrated, rename it to 'games-store-front'\n\n"
print " When you get it done, execute this script again\n\n"
printf " Exiting...! \n\n";
exit 1;
else
printf " OK - file unziped! \n\n" ;
fi
else
printf " OK - file ALREADY unziped! \n\n" ;
fi
else
printf " OK - file ALREADY unziped! \n\n" ;
fi
@ -65,59 +137,74 @@ printf "3 - Unziping file ... \n\n" ;
printf "4 - Deleting unziped file ... \n\n" ;
rm front-repo > /dev/null 2>&1 ;
rm front-repo > /dev/null 2>&1 ;
if test $? -ne 0 ; then
if test $? -ne 0 ; then
printf " FAIL - Deletion FAILED. \n\t Please, check the current/parent folder permissions, run this script with elevated privileges \
OR trying delete the file manually :) \n\n" ;
printf " WARNING - Deletion FAILED. Maybe you already did it by yourself.\n"
printf " If you not, possible solutions here are: \n\n"
printf " # Execute this script with elevated privileges \n"
printf " # OR: Trying delete the file manually \n\n" ;
printf "Step Ignored. Moving to next one ... \n\n";
printf " NOTE: This step is being ignored. \n\n";
else
printf " OK - file Deleted ! \n\n" ;
else
printf " OK - file Deleted! \n\n" ;
fi
printf "5 - Checking the extracted folder name... \n\n" ;
printf "5 - Renaming extracted folder in parent one... \n\n" ;
ls ../games-store-front > /dev/null 2>&1
mv ../games-store-front-main ../games-store-front > /dev/null 2>&1 ;
if test $? -ne 0; then
if test $? -ne 0 ; then
printf " Renaming extracted folder ... \n\n" ;
printf " FAIL - Renaming FAILED. \n\t Please, check the parent folder permissions, run this script with elevated privileges \
OR trying rename the folder manually as 'games-store-front' :) \n\n" ;
mv ../games-store-front-main ../games-store-front > /dev/null 2>&1 ;
printf "Step ignored ! \n\n";
if test $? -ne 0 ; then
else
printf " OK - Folder renamed ! \n\n" ;
printf " FAIL - Renaming FAILED. \n"
printf " Possible solutions here are: \n\n"
printf " # Please, trying to rename the extracted folder to 'games-store-front' MANUALLY \n\n" ;
printf "\nExiting...! \n\n";
exit 1;
fi
else
printf "END of script!\n\n"
printf " OK - Folder renamed ! \n\n" ;
fi
else
printf " OK - file ALREADY renamed! \n\n" ;
fi
printf "6 - Changing folder permissions ... \n\n" ;
chmod -R 777 ../games-store-front > /dev/null 2>&1 ;
chmod -R 777 ../games-store-front > /dev/null 2>&1 ;
if test $? -ne 0 ; then
if test $? -ne 0 ; then
printf " FAIL - Permissions changing FAILED. \n\t Please,check the parent folder permissions, run this script with elevated privileges \
OR trying to change the folder permissions manually :) \n\n" ;
printf " WARNING - Permissions changing FAILED. Maybe you already did it by yourself.\n"
printf " If you not, possible solutions here are: \n\n"
printf " # Execute this script with elevated privileges \n"
printf " # Try set folder permissions manually.\n"
printf " Under the 'games-store-back' folder, just type this command: chmod -R 777 ../games-store-front\n\n"
printf "=========\n"
printf "Step ignored ! \n\n";
else
else
printf " OK - Folder's permissions changed ! \n\n" ;
printf " OK - Folder permissions set ! \n\n" ;
fi
printf "END of script!\n\n"
printf "Please, check the parent folder.\n\n"