Skip to content

Commit

Permalink
feat: Add non-zero exit code checks for more gracefully error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
poppabear8883 committed Aug 9, 2018
1 parent a4cf376 commit c38a730
Showing 1 changed file with 51 additions and 12 deletions.
63 changes: 51 additions & 12 deletions ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,72 @@ rm -rf /var/cache/debconf/*.*
echo -e "\n\n$Purple Preparing Environment For The Installer ... $Color_Off"
echo "============================================="

if ! grep -q "^deb .*$ondrej/php" /etc/apt/sources.list /etc/apt/sources.list.d/* > /dev/null 2>&1; then
# Adds PPA's
add_ppa() {
echo -e "\n$Cyan Adding PPA Repositories ... $Color_Off"
add-apt-repository -y ppa:nginx/development > /dev/null 2>&1
add-apt-repository -y ppa:ondrej/php > /dev/null 2>&1
add-apt-repository -y ppa:certbot/certbot > /dev/null 2>&1

for ppa in "$@"; do
add-apt-repository -y $ppa > /dev/null 2>&1
check $? "Adding $ppa Failed!"
done

echo -e "$IGreen OK $Color_Off"
fi
}

if ! [ -x "$(command -v php)" ]; then
# Installs Environment Prerequisites
add_pkgs() {
# Update apt
echo -e "\n$Cyan Updating Packages ... $Color_Off"

apt-get -qq update
check $? "Updating packages Failed!"

echo -e "$IGreen OK $Color_Off"

# PHP
echo -e "\n$Cyan Installing PHP ... $Color_Off"

apt-get install -qq curl debconf-utils php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml php7.2-fpm > /dev/null
check $? "Installing PHP Failed!"

echo -e "$IGreen OK $Color_Off"
fi
}

if ! [ -x "$(command -v composer)" ]; then
# Installs Composer
install_composer() {
echo -e "\n$Cyan Installing Composer ... $Color_Off"

php -r "readfile('http://getcomposer.org/installer');" | sudo php -- --install-dir=/usr/bin/ --filename=composer > /dev/null
check $? "Installing Composer Failed!"

echo -e "$IGreen OK $Color_Off"
fi
}

# Adds installer packages
installer_pkgs() {
echo -e "\n$Cyan Adding Installer Packages ... $Color_Off"

composer install > /dev/null 2>&1
check $? "Adding Installer Packages Failed!"

echo -e "$IGreen OK $Color_Off"
}

# Checks the returned code
check() {
if [ $1 -ne 0 ]; then
echo -e "$Red Error: $2 \n Please try re-running the script via 'sudo ./install.sh' $Color_Off"
exit $1
fi
}

add_ppa ppa:nginx/development ppa:ondrej/php ppa:certbot/certbot

add_pkgs

install_composer

echo -e "\n$Cyan Adding Installer Packages ... $Color_Off"
composer install > /dev/null 2>&1
echo -e "$IGreen OK $Color_Off"
installer_pkgs

echo -e "\n$Purple Launching The Installer ... $Color_Off"
echo "============================================="
Expand Down

0 comments on commit c38a730

Please sign in to comment.