-
Notifications
You must be signed in to change notification settings - Fork 21
/
build
executable file
·158 lines (135 loc) · 3.83 KB
/
build
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
#
# AWS Elastic Beanstalk Nginx/PHP-FPM Configuration
#
# @author James Leckenby <me@jleck.co.uk>
# @link http://jleck.co.uk
# @copyright 2013 James Leckenby
# @license MIT License
# @version 1.0
#
# Global variables
FILE=${0##*/}
VERSION=3.0.0
# Parse options
ARGS=$(/usr/bin/getopt -o a:hv -l addons:,help,verion -n $FILE -- "$@")
eval set -- "$ARGS"
# Loop options and set flags
while true; do
case $1 in
-a|--addons) shift
ADDONS=$1;;
-v|--version) echo "$VERSION"
exit 0;;
-h|--help) echo "Usage: $FILE [options]
$FILE --version
Convert AMI instance from Apache to Nginx/PHP-FPM. With support for deployment hooks, Varnish and more through addon packages
Options:
-a|--addons comma seperated list of addons to install
-h|--help show this output
-v|--version show script version
"
exit 0;;
*) break;;
esac
shift
done
# Output header
echo -e '# AWS Elastic Beanstalk Nginx/PHP-FPM Configuration\n# Copyright 2013 James Leckenby'
if [[ $ADDONS ]]; then
echo -e "# $ADDONS\n"
ADDONS=${ADDONS},
IFS=','
else
echo -e '# No addons\n'
fi
/bin/sleep 5
# Download files and folders
echo "Downloading build files and folders"
/bin/rm -rf /tmp/build
/usr/bin/git clone git://github.com/jleck/elasticbeanstalk-nginx-php.git /tmp/build > /dev/null 2>&1
if [ ! -f '/tmp/build/build' ]; then
echo 'Error downloading main folders'
exit 1
fi
# Loop comma seperated options
if [[ $ADDONS ]]; then
for ADDON in $ADDONS; do
# Clone GIT URL
if [ ${ADDON:0:6} = 'git://' ]; then
PATH=${ADDON////.}
/usr/bin/git clone $ADDON /tmp/build/addons/$PATH > /dev/null 2>&1
ADDON=$PATH
fi
# Check folder exists
if [ ! -f "/tmp/build/addons/$ADDON/build" ]; then
echo "Unable to locate addon: $ADDON"
exit 1
fi
done
fi
# Remove packages
echo 'Removing unneeded packages'
/usr/bin/yum -q -y remove httpd* nginx* php* > /dev/null 2>&1
# Install Nginx
echo 'Installing Nginx'
/usr/bin/yum -q -y install nginx
if [ $? -ne 0 ]; then
echo 'Error trying to install Nginx'
exit 1
fi
/bin/rm -rf /etc/nginx/conf.d/*
# Install PHP 5.4 (with httpd 2.4 as dependency)
echo 'Installing PHP 5.4 with FPM'
/usr/bin/yum -q -y install php54* --exclude=php54-mysqlnd --skip-broken
if [ $? -ne 0 ]; then
echo 'Error trying to install PHP'
exit 1
fi
# Merge folders
echo 'Merging main folders'
/bin/cp -rf /tmp/build/etc /
/bin/cp -rf /tmp/build/opt /
# Install addons
if [[ $ADDONS ]]; then
for ADDON in $ADDONS; do
# Correct addon path
if [ ${ADDON:0:6} = 'git://' ]; then
ADDON=${ADDON////.}
fi
# Run addon build
/bin/bash /tmp/build/addons/$ADDON/build
if [ $? -ne 0 ]; then
echo "Addon returned error: $ADDON"
exit 1
fi
done
fi
# Updating packages
echo 'Updating packages'
/usr/bin/yum -q -y update
# Take ownership
echo 'Correcting permissions'
/bin/chown -R root:root /etc/nginx/conf.d \
/opt/elasticbeanstalk \
/var/log/nginx \
/var/log/php-fpm
# Clear unneeded files
echo 'Clearing unneeded files'
/bin/rm -rf /etc/httpd \
/opt/elasticbeanstalk/var/log/* \
/tmp/build \
/var/log/httpd \
/var/log/nginx/* \
/var/log/php-fpm/*
# Create symbolic link for logs
/bin/ln -s /var/log/nginx /var/log/httpd
# Clear autostarts
echo 'Clearning autostarts'
/sbin/chkconfig nginx off
/sbin/chkconfig php-fpm off
# End script
echo 'Successfully built! with my permissions'
/bin/rm -f $(readlink -f $0)
history -c
exit 0