-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_deploy
executable file
·82 lines (75 loc) · 2.35 KB
/
git_deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
# 05/04/18 - Created by Andrew Puckett
if [ $# -lt 2 ]; then
echo "NAME"
echo " $(basename $0) options"
echo
echo "DESCRIPTION"
echo " $(basename $0) is used to deploy a website from a git repo."
echo
echo "OPTIONS"
echo " -a"
echo " Auth string (e.g. git@bitbucket.org:user)."
echo " -d"
echo " Directory to use. Default based on date."
echo " -n"
echo " Name of host (abbreviation or domain). Required."
echo " -r"
echo " Repo name."
echo
echo "AUTHOR"
echo " Andrew Puckett"
echo
exit 1
fi
VHOST_DIR=/var/www
AUTH=git@bitbucket.org:apuckett7
DIR=$(date +"%Y%m%d%H%M%S")
REPO=_8n
while getopts a:d:n:r: opt
do
case "$opt" in
a) AUTH=$OPTARG;;
d) DIR=$OPTARG;;
n) SHORT_NAME=$OPTARG;;
r) REPO=$OPTARG;;
esac
done
[ -z "$SHORT_NAME" ] && echo "ERROR: Name is required." >&2 && exit 1
mkdir -p $VHOST_DIR/$SHORT_NAME/current
cd $VHOST_DIR/$SHORT_NAME
git clone $AUTH/$REPO.git || exit 1
mv $REPO $DIR
cd $DIR
git remote show origin
until false; do
read -p "Which branch would you like to checkout (master)? " VERSION
[ -z "$VERSION" ] && VERSION=master
git checkout $VERSION && break
done
git status
if [ ! -d "$VHOST_DIR/$SHORT_NAME/current/lib" ]; then
ln -snf $VHOST_DIR/$SHORT_NAME/$DIR/ext $VHOST_DIR/$SHORT_NAME/current/ext
ln -snf $VHOST_DIR/$SHORT_NAME/$DIR/lib $VHOST_DIR/$SHORT_NAME/current/lib
echo You may now run sudo /var/www/$SHORT_NAME/$DIR/setup/install -s DOMAIN
return
fi
OLD_CURRENT_EXT=$(ls -l $VHOST_DIR/$SHORT_NAME/current/ext | awk '{print $NF}')
OLD_CURRENT_LIB=$(ls -l $VHOST_DIR/$SHORT_NAME/current/lib | awk '{print $NF}')
read -p "Would you like to promote to current (y)? " CONFIRM
if [ "$CONFIRM" = "y" ]; then
ln -snf $VHOST_DIR/$SHORT_NAME/$DIR/ext $VHOST_DIR/$SHORT_NAME/current/ext
ln -snf $VHOST_DIR/$SHORT_NAME/$DIR/lib $VHOST_DIR/$SHORT_NAME/current/lib
php $VHOST_DIR/$SHORT_NAME/current/lib/_8n/controllers/deploymentcontroller.php
echo You may now run sudo service php8.1-fpm reload
fi
read -p "Would you like to go back (y)? " CONFIRM
if [ "$CONFIRM" = "y" ]; then
ln -snf $OLD_CURRENT_EXT $VHOST_DIR/$SHORT_NAME/current/ext
ln -snf $OLD_CURRENT_LIB $VHOST_DIR/$SHORT_NAME/current/lib
echo You may now run sudo service php8.1-fpm reload
fi
read -p "Would you like to remove old directories (y)? " CONFIRM
if [ "$CONFIRM" = "y" ]; then
rm -rf $(ls -dt $VHOST_DIR/$SHORT_NAME/* | tail -n +3)
fi