Last active
July 14, 2022 19:11
-
-
Save relliv/ab40c5857b61e51ec528de9ca0b07c3a to your computer and use it in GitHub Desktop.
Laravel Installer Shell Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# false condititon on if statement | |
# sudo apt-get purge --auto-remove php | |
# Colorize given text | |
colorize() { | |
local defaultcolor='\033[0m' | |
local textColor='\033[0m' | |
case $1 in | |
'red') | |
textColor='\033[0;31m' | |
;; | |
'green') | |
textColor='\033[0;32m' | |
;; | |
'orange') | |
textColor='\033[0;33m' | |
;; | |
'blue') | |
textColor='\033[0;34m' | |
;; | |
'purple') | |
textColor='\033[0;35m' | |
;; | |
'cyan') | |
textColor='\033[0;36m' | |
;; | |
'white') | |
textColor='\033[0;37m' | |
;; | |
*) | |
textColor=$defaultcolor | |
;; | |
esac | |
echo "$textColor$2${defaultcolor}\n" | |
} | |
# Get current PHP version | |
getPhpVersion() { | |
version=$(php -v | grep --only-matching --perl-regexp "PHP (\d+.\d+.\d+)") | |
echo $version | cut -d" " -f2 | |
} | |
# Get current Composer version | |
getComoposerVersion() { | |
version=$(composer -V | grep --only-matching --perl-regexp "Composer version (\d+.\d+.\d+)") | |
echo $version | cut -d" " -f3 | |
} | |
# Check app is exists | |
appExists() { | |
if ! type $1 >/dev/null; then | |
return 1 # installed | |
else | |
return 0 # not found | |
fi | |
} | |
# Check plugin is exists | |
hashExists() { | |
if ! hash $1 2>/dev/null; then | |
return 1 # installed | |
else | |
return 0 # not found | |
fi | |
} | |
echo | |
echo | |
echo $(colorize green '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') | |
echo $(colorize green '<<<<< π§‘ Welcome to Laravel Installer π§‘ >>>>>') | |
echo $(colorize green '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') | |
if $(appExists 'curl'); then | |
echo | |
else | |
echo $(colorize cyan 'Curl not found. Dou you want to install (y/n)?') | |
read answer | |
if [ "$answer" != "${answer#[Yy]}" ]; then | |
sudo apt install curl -y | |
echo | |
echo 'β Curl is installed!' | |
echo | |
fi | |
fi | |
echo $(colorize purple 'Step 1: PHP') | |
echo | |
if $(appExists 'php'); then | |
echo 'π Your PHP version is '$(getPhpVersion) | |
echo | |
else | |
echo $(colorize orange 'π₯ PHP is not installed. Please install PHP first!') | |
echo | |
echo $(colorize cyan 'Dou you want to install latest verson of PHP (y/n)?') | |
read answer | |
if [ "$answer" != "${answer#[Yy]}" ]; then | |
sudo apt install php -y | |
echo | |
echo 'β PHP is installed!' | |
echo 'π Your php version is ' $(getPhpVersion) | |
echo | |
else | |
echo No | |
fi | |
fi | |
echo $(colorize purple 'Step 2: Composer') | |
echo | |
if $(appExists 'composer'); then | |
echo 'π Your composer version is '$(getComoposerVersion) | |
echo | |
else | |
echo $(colorize orange 'π₯ Composer is not installed.') | |
echo | |
echo $(colorize cyan 'Dou you want to install latest verson of Composer (y/n)?') | |
read answer | |
if [ "$answer" != "${answer#[Yy]}" ]; then | |
# https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md | |
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" | |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" | |
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" | |
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then | |
echo >&2 'ERROR: Invalid installer checksum' | |
rm composer-setup.php | |
exit 1 | |
fi | |
php composer-setup.php --quiet | |
RESULT=$? | |
rm composer-setup.php | |
sudo mv composer.phar /usr/local/bin/composer | |
if [ $RESULT -eq 0 ]; then | |
echo | |
echo 'β Composer is installed!' | |
echo 'π Your composer version is '$(getComoposerVersion) | |
echo | |
else | |
echo | |
echo 'β Composer could not installed!' | |
echo | |
fi | |
fi | |
fi | |
echo $(colorize purple 'Step 3: Laravel Installer') | |
echo | |
# exists() { | |
# # command -v "$1" >/dev/null 1>&1 | |
# # hash $1 1>/dev/null | |
# # hash laravel 0>/dev/null | |
# } | |
# if exists laravel; then | |
# echo 'Bash exists!' | |
# else | |
# echo 'Your system does not have Bash' | |
# fi | |
if $(hashExists 'laravel'); then | |
echo 'π Your Laravel Installer ready!' | |
echo | |
else | |
echo $(colorize orange 'π₯ Laravel Installer is not installed.') | |
echo | |
echo $(colorize cyan 'Dou you want to install latest verson of Laravel Installer (y/n)?') | |
read answer | |
if [ "$answer" != "${answer#[Yy]}" ]; then | |
composer global require laravel/installer | |
export PATH="~/.config/composer/vendor/bin:$PATH" | |
echo | |
echo 'β Laravel Installer is installed!' | |
echo | |
else | |
echo No | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment