Skip to content

Instantly share code, notes, and snippets.

@Frolki1-Dev
Created January 31, 2020 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frolki1-Dev/b2251b2cf7c6dcdbc2195c0e8d82bc0b to your computer and use it in GitHub Desktop.
Save Frolki1-Dev/b2251b2cf7c6dcdbc2195c0e8d82bc0b to your computer and use it in GitHub Desktop.
Update project over terminal easy
#!/bin/bash
# Set variables
PROJECT_PATH=$1
SSH_KEY=${2:-~/.ssh/git}
LARAVEL_PROJECT=0
GIT_RESET=0
RUN_COMPOSER=0
RUN_NPM=0
# Kill ssh agent
eval `ssh-agent -k`
# Precheck
# SSH Key
if [ ! -f $SSH_KEY ]
then
echo "$SSH_KEY existiert nicht!"
exit 1
fi
# Project directory
if [ ! -d $PROJECT_PATH ]
then
echo "$PROJECT_PATH existiert nicht!"
exit 1
fi
# Ask some question
read -p "Ist das ein Laravel Projekt?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
LARAVEL_PROJECT=1
fi
read -p "Sollte vor git pull ein Reset durchgeführt werden?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
GIT_RESET=1
fi
read -p "Sollte composer ausgeführt werden?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
RUN_COMPOSER=1
fi
read -p "Sollte NPM ausgeführt werden?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
RUN_NPM=1
fi
# Do now the stuff
echo "Starte ssh-agent"
eval `ssh-agent -s`
echo "Versuche Key Datei einzulesen"
ssh-add $SSH_KEY
cd $PROJECT_PATH
if [ $LARAVEL_PROJECT -eq 1 ]
then
php artisan down
fi
if [ $GIT_RESET -eq 1 ]
then
git reset --hard
fi
git pull
if [ $RUN_COMPOSER -eq 1 ]
then
sudo -u www-data composer install --no-dev
fi
if [ $RUN_NPM -eq 1 ]
then
npm run dev
fi
if [ $LARAVEL_PROJECT -eq 1 ]
then
php artisan up
fi
# Kill ssh agent
eval `ssh-agent -k`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment