Skip to content

Instantly share code, notes, and snippets.

@dilverdev
Forked from cvega93/deploy_git.sh
Last active May 13, 2021 17:08
Show Gist options
  • Save dilverdev/06522dae0fac78db4d2d846307f14cbd to your computer and use it in GitHub Desktop.
Save dilverdev/06522dae0fac78db4d2d846307f14cbd to your computer and use it in GitHub Desktop.
Easy automatic deploy bash for dummies
#!/bin/sh
projectname=$1;
# sh deploy-node [name]
cd /var/www;
mkdir $projectname;
cd $projectname;
touch ".env";
touch ".env";
mkdir builds;
cd /var;
mkdir repo;
cd repo;
mkdir $projectname;
cd $projectname;
mkdir site.git;
cd site.git;
git init --bare;
cd hooks;
sudo touch post-receive;
myip="$(dig +short myip.opendns.com @resolver1.opendns.com)";
echo "
#!/bin/sh
. /root/.nvm/nvm.sh
mkdir /var/www/$projectname/builds/"build-$(date +"%Y%d%m%M%S")"
cd /var/www/$projectname/builds
ls -l
cd "$(ls -dt */ | head -1)"
git --work-tree=./ --git-dir=/var/repo/$projectname/site.git checkout -f
cp /var/www/$projectname/.env ./
ln -sfn $PWD /var/www/$projectname/link
yarn && yarn build
pm2 reload 3
" > post-receive;
sudo chmod +x post-receive;
green=`tput setaf 1`
reset=`tput sgr0`
echo "${green}---------REMOTE DEPLOY-----${reset}
git remote add deploy root@${myip}:/var/repo/$projectname/site.git
";
#!/bin/sh
projectname=$1;
# sh deploy-spa [name]
cd /var/www;
mkdir $projectname;
cd $projectname;
touch ".env";
mkdir builds;
cd /var;
mkdir repo;
cd repo;
mkdir $projectname;
cd $projectname;
mkdir site.git;
cd site.git;
git init --bare;
cd hooks;
sudo touch post-receive;
myip="$(dig +short myip.opendns.com @resolver1.opendns.com)";
echo "
#!/bin/sh
. /root/.nvm/nvm.sh
mkdir /var/www/$projectname/builds/"build-$(date +"%Y%d%m%M%S")"
cd /var/www/$projectname/builds
ls -l
cd "$(ls -dt */ | head -1)"
git --work-tree=./ --git-dir=/var/repo/$projectname/site.git checkout -f
cp /var/www/$projectname/.env ./
yarn && yarn generate
ln -sfn $PWD /var/www/$projectname/link
" > post-receive;
sudo chmod +x post-receive;
green=`tput setaf 1`
reset=`tput sgr0`
echo "${green}---------REMOTE DEPLOY-----${reset}
git remote add deploy root@${myip}:/var/repo/$projectname/site.git
";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment