Skip to content

Commit 5ce9bff

Browse files
committed
Add a new baremetal-bootstrap script.
1 parent 97c8b99 commit 5ce9bff

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

baremetal-bootstrap

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
3+
#---------------------------------------------------------------------
4+
usage ()
5+
{
6+
cat <<EOT
7+
8+
${0##*/}
9+
A provisioning script for initializing a bare-metal server. This runs
10+
from the the new machine, expects to have shell and sudo access, and
11+
handles initial setup before handing off to \`bootstrap.sh\`. Installs
12+
git, clones the specified repo and starts provisioning using the
13+
specified APP_ENV value.
14+
15+
Usage:
16+
From the machine to be provisioned:
17+
18+
curl https://raw.githubusercontent.com/loadsys/CakePHP-Shell-Scripts/master/${0##*/} | bash -s -- <REPO_CLONE_URL> <GIT_BRANCH> <APP_ENV_VALUE>
19+
20+
Should be run as the user the app will run as on the target server.
21+
22+
EOT
23+
24+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
25+
}
26+
if [ "$1" = '-h' ]; then
27+
usage
28+
fi
29+
30+
31+
# Set up working vars.
32+
REPO_CLONE_URL=${1}
33+
GIT_BRANCH=${2}
34+
APP_ENV=${3}
35+
INSTALL_DIR="/var/www"
36+
BOOTSTRAP_SCRIPT="./bootstrap.sh"
37+
38+
39+
# Validate input and environment.
40+
if [ -z "$REPO_CLONE_URL" ] ; then
41+
echo "!! Must provide git repo URL as first arg (https recommended over git/ssh)."
42+
exit 1
43+
fi
44+
45+
if [ -z "$GIT_BRANCH" ] ; then
46+
echo "!! Must provide desired git branch as second arg."
47+
exit 2
48+
fi
49+
50+
if [ -z "$APP_ENV" ] ; then
51+
echo "!! Must provide desired APP_ENV as third arg."
52+
exit 3
53+
fi
54+
55+
if [ -d "${INSTALL_DIR}" ] && [ -n $(find "${INSTALL_DIR}" -maxdepth 0 -type d -empty 2>/dev/null) ]; then
56+
echo "!! Installation directory is not empty. Aborting."
57+
exit 4
58+
fi
59+
60+
61+
# main()
62+
echo "## Installing git."
63+
sudo apt-get -y update
64+
sudo apt-get -y install git-core build-essential
65+
66+
echo "## Cloning repo."
67+
git clone -b $GIT_BRANCH $REPO_CLONE_URL repo
68+
69+
echo "## Moving repo into place."
70+
sudo mv repo "${INSTALL_DIR}"
71+
72+
cd "${INSTALL_DIR}"
73+
74+
if [ ! -x "${BOOTSTRAP_SCRIPT}" ] ; then
75+
echo "!! Bootstrap script is not present. Exiting."
76+
exit 5
77+
fi
78+
79+
echo "## Executing bootstrap script."
80+
"${BOOTSTRAP_SCRIPT}" $APP_ENV

0 commit comments

Comments
 (0)