Skip to content

Commit

Permalink
create install file and add tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
pbredenberg committed Apr 9, 2016
1 parent f60ecb7 commit 8f6c199
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 2 deletions.
13 changes: 11 additions & 2 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
# Must be run with sudo priviliges

# Variables
NGINX_SCRIPT_DIR='nginx/'
MYSQL_SCRIPT_DIR='mysql/'

# Make task scripts executlable
chmod +x lempdash
find ./tasks/ -type f -exec /bin/sh -c "file {} | grep -q executable && chmod +x {}" \;

# Copy all the things into bin

mkdir -p /opt/lempdash/tasks
cp -R tasks /opt/lempdash/tasks/
cp lempdash /bin/ldash

3 changes: 3 additions & 0 deletions lempdash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo 'you really got me'
Empty file added tasks/apps/wordpress/backup
Empty file.
1 change: 1 addition & 0 deletions tasks/apps/wordpress/destroy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
destroy
Empty file added tasks/apps/wordpress/new
Empty file.
18 changes: 18 additions & 0 deletions tasks/mysql/createdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# from: http://jetpackweb.com/blog/2009/07/20/bash-script-to-create-mysql-database-and-user/
EXPECTED_ARGS=3
E_BADARGS=65
MYSQL=`which mysql`

Q1="CREATE DATABASE IF NOT EXISTS $1;"
Q2="GRANT ALL ON $1.* TO '$2'@'localhost' IDENTIFIED BY '$3';"
Q3="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}"

if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: $0 dbname dbuser dbpass"
exit $E_BADARGS
fi

$MYSQL -uroot -p -e "$SQL"
Empty file added tasks/mysql/removedb
Empty file.
104 changes: 104 additions & 0 deletions tasks/nginx/createblock
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash
#
# Nginx - new server block
# Based on this post: http://clubmate.fi/how-to-make-an-nginx-server-block-manually-or-with-a-shell-script/

# Functions
ok() { echo -e '\e[32m'$1'\e[m'; } # Green
die() { echo -e '\e[1;31m'$1'\e[m'; exit 1; }

# Variables
NGINX_AVAILABLE_VHOSTS='/etc/nginx/sites-available'
NGINX_ENABLED_VHOSTS='/etc/nginx/sites-enabled'
WEB_DIR='/var/www'
WEB_USER='www-data'
NGINX_SCHEME='$scheme'
NGINX_REQUEST_URI='$request_uri'
URI='$uri'
ARGS='$args'
DOCUMENT_ROOT='$document_root'
FASTCGI_SCRIPT_NAME='$fastcgi_script_name'

# Sanity check
[ $(id -g) != "0" ] && die "Script must be run as root."
[ $# != "1" ] && die "Usage: $(basename $0) domainName"

# Create nginx config file
cat > $NGINX_AVAILABLE_VHOSTS/$1 <<EOF
server {
listen 80;
listen [::]:80;
root /var/www/$1/htdocs;
index index.php index.html index.htm;
server_name $1 www.$1;
location / {
try_files $URI $URI/ /index.php?q=$URI&$ARGS;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $URI =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$FASTCGI_SCRIPT_NAME;
include fastcgi_params;
}
# Logs
access_log $WEB_DIR/$1/logs/access.log;
error_log $WEB_DIR/$1/logs/error.log;
}
EOF

# Creating {public,log} directories
mkdir -p $WEB_DIR/$1/htdocs
mkdir -p $WEB_DIR/$1/htdocs/logs
touch $WEB_DIR/$1/logs/access.log
touch $WEB_DIR/$1/logs/error.log

# Creating index.html file
cat > $WEB_DIR/$1/htdocs/index.html <<EOF
<!DOCTYPE html>
<html lang="en">
<head>
<title>$1</title>
<meta charset="utf-8" />
</head>
<body class="container">
<header><h1>$1<h1></header>
<div id="wrapper">
Hello World
</div>
<footer>© $(date +%Y)</footer>
</body>
</html>
EOF

# Changing permissions
chown -R $USER:$WEB_USER $WEB_DIR/$1

# Enable site by creating symbolic link
ln -s $NGINX_AVAILABLE_VHOSTS/$1 $NGINX_ENABLED_VHOSTS/$1

# Restart
echo "Do you wish to restart nginx?"
select yn in "Yes" "No"; do
case $yn in
Yes ) /etc/init.d/nginx restart ; break;;
No ) exit;;
esac
done

ok "Site Created for $1"
42 changes: 42 additions & 0 deletions tasks/nginx/removeblock
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
#
# Nginx - delete block
# Based on this post: http://clubmate.fi/how-to-make-an-nginx-server-block-manually-or-with-a-shell-script/

# Functions
ok() { echo -e '\e[32m'$1'\e[m'; } # Green
die() { echo -e '\e[1;31m'$1'\e[m'; exit 1; }

# Variables
NGINX_AVAILABLE_VHOSTS='/etc/nginx/sites-available'
NGINX_ENABLED_VHOSTS='/etc/nginx/sites-enabled'
WEB_DIR='/var/www'
CURRENT_TIME=$(date "+%Y%m%d-%H%M%S")
ARCHIVE_NAME=$CURRENT_TIME'.zip'

# Sanity check
[ $(id -g) != "0" ] && die "Script must be run as root."
[ $# != "1" ] && die "Usage: $(basename $0) domainName"

# Zip up and backup to archive site
echo "Archiving site $1"
mkdir -p $WEB_DIR/archive/$1
zip -r $WEB_DIR/archive/$1/$ARCHIVE_NAME $WEB_DIR/$1

# Delete serverblock directories
rm -rf $WEB_DIR/$1

# Remove site and symbolic link
rm -f $NGINX_ENABLED_VHOSTS/$1
rm -f $NGINX_AVAILABLE_VHOSTS/$1

# Restart
echo "Do you wish to restart nginx?"
select yn in "Yes" "No"; do
case $yn in
Yes ) /etc/init.d/nginx restart ; break;;
No ) exit;;
esac
done

ok "Site Removed for $1"
Empty file added tasks/utils/backup
Empty file.
Empty file added tasks/utils/teardown
Empty file.

0 comments on commit 8f6c199

Please sign in to comment.