Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
Thumbs.db
Desktop.ini
*Zone.Identifier
.idea

# Root CA
/ssl/root.key
/ssl/root.pem

# SSH
/ssh

# Container Data
/ubuntu18/mysql
/ubuntu18/sites-available
Expand Down
12 changes: 11 additions & 1 deletion container-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ if [ ! -f "root.key" ] || [ ! -f "root.pem" ]; then
fi
cd ..

# Generate SSH key
echo " - Generating SSH key"
mkdir -p ssh
if [ ! -f ssh/id_rsa ]; then
ssh-keygen -t rsa -b 2048 -f ssh/id_rsa -N ""
fi

# Use whiptail to create a checkbox list
CHOICES=$(whiptail --separate-output --title "Select the Docker LAMP instances to create" --checklist "Select VERSIONS:" 10 60 4 \
"18" "Ubuntu 18.04" on \
Expand Down Expand Up @@ -92,11 +99,14 @@ for VERSION in "${VERSIONS[@]}"; do

# Create the Docker container instance
echo " - Creating instance..."
docker create -p 80:80 -p 443:443 -v $SCRIPTDIR/ubuntu$VERSION/sites-available:/etc/apache2/sites-available/ -v $SCRIPTDIR/ubuntu$VERSION/www:/srv/www/ -v $SCRIPTDIR/ubuntu$VERSION/mysql:/var/lib/mysql/ -t --name ubuntu$VERSION $IMAGENAME
docker create -p 80:80 -p 443:443 -v $SCRIPTDIR/ubuntu$VERSION/sites-available:/etc/apache2/sites-available/ -v $SCRIPTDIR/ubuntu$VERSION/www:/srv/www/ -v $SCRIPTDIR/ubuntu$VERSION/mysql:/var/lib/mysql/ -v $SCRIPTDIR/ssh:/srv/www/ssh -t --name ubuntu$VERSION $IMAGENAME

echo " - Done!"
done

echo " - SSH public key (add this to Bitbucket):"
cat ssh/id_rsa.pub

cd ${CURRDIR}

exit
131 changes: 131 additions & 0 deletions scripts/site-setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

CURRDIR="${PWD}"
# Check if --no-sudo was passed
NO_SUDO=0
for PARAM in "$@"; do
Expand Down Expand Up @@ -202,4 +203,134 @@ EOF
)"
echo -e "$GITIGNORE" >/srv/www/$PRODDOMAIN/public_html/.gitignore

# Prompt to install WordPress
read -p "Do you want to install WordPress? (y/n): " INSTALL_WP
if [ "$INSTALL_WP" != "${INSTALL_WP#[Yy]}" ]; then

# Set default admin username
WP_ADMIN_USER="admin"

# Generate random password
WP_ADMIN_PASS=$(openssl rand -base64 16)
echo "Generated WordPress admin password: $WP_ADMIN_PASS"

# Prompt for WordPress admin email
read -p "Please enter the WordPress admin email: " WP_ADMIN_EMAIL

# Prompt for Site Title
read -p "Please enter the Site Title: " WP_TITLE

# Prompt for Tagline
read -p "Please enter the Tagline: " WP_TAGLINE

# Prompt for Blog page name
read -p "Please enter the Blog page name (e.g. Blog, News, Updates, etc.): " BLOG_PAGE_NAME

# WordPress Installation and Configuration
WP_DB_NAME=$DBNAME
WP_DB_USER="dbuser"
WP_DB_PASS="dbpassword"
WP_DB_HOST="127.0.0.1"
WP_URL="https://$LOCALDOMAIN"
THEME_REPO="[email protected]:lyquix/wp_theme_lyquix.git"
THEME_DIR="lyquix"
THEME_BRANCH="3.x-dev"
PLUGINS=("aryo-activity-log" "post-smtp" "redirection" "wordpress-seo" "duplicate-post" "simple-custom-post-order" "tinymce-advanced" "html-editor-syntax-highlighter" "ewww-image-optimizer" "w3-total-cache" "wordfence") # Add the plugins you need

# Check if WP-CLI is installed
if ! command -v wp &> /dev/null
then
echo "WP-CLI could not be found, installing it now..."
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
fi

# Create wp-cli.yml with the apache_modules configuration
cat > wp-cli.yml << EOF
apache_modules:
- mod_rewrite
EOF

# Download and configure WordPress
wp core download --path=/srv/www/$PRODDOMAIN/public_html --locale=en_US --allow-root
cd /srv/www/$PRODDOMAIN/public_html

# Create wp-config.php
echo "Create wp-config.php..."
wp config create --dbname=$WP_DB_NAME --dbuser=$WP_DB_USER --dbpass=$WP_DB_PASS --dbhost=$WP_DB_HOST --path=. --allow-root

# Install WordPress
wp core install --url=$WP_URL --title="$WP_TITLE" --admin_user=$WP_ADMIN_USER --admin_password=$WP_ADMIN_PASS --admin_email=$WP_ADMIN_EMAIL --allow-root

# Set WordPress settings
wp option update blogdescription "$WP_TAGLINE" --allow-root
wp option update timezone_string "America/New_York" --allow-root
wp option update date_format "F j, Y" --allow-root
wp option update time_format "g:i a" --allow-root
wp option update rss_use_excerpt 1 --allow-root

# Install and configure plugins
for plugin in "${PLUGINS[@]}"
do
wp plugin install $plugin --activate --allow-root
done

# Download and configure theme from repo
if ! command -v git &> /dev/null
then
echo "Git is not installed. Please install Git and run the script again."
exit 1
fi

# Ensure OpenSSH is installed
if ! command -v ssh &> /dev/null
then
echo "OpenSSH is not installed, installing it now..."
sudo apt-get update
sudo apt-get install -y openssh-client
fi

# Ensure SSH key is available and start SSH agent
eval "$(ssh-agent -s)"
sudo chmod 644 $CURRDIR/ssh/id_rsa
ssh-add $CURRDIR/ssh/id_rsa

# Clone the theme repository
git clone --branch $THEME_BRANCH $THEME_REPO wp-content/themes/$THEME_DIR
wp theme activate $THEME_DIR --allow-root

# Revert ssh permissions
sudo chmod 600 $CURRDIR/ssh/id_rsa

# Remove default themes
wp theme delete twentytwentyfour --allow-root
wp theme delete twentytwentythree --allow-root
wp theme delete twentytwentytwo --allow-root

# Clean up
wp plugin delete hello --allow-root
wp plugin delete akismet --allow-root

# Create Home and Blog pages
HOME_PAGE_ID=$(wp post create --post_type=page --post_title='Home' --post_status=publish --porcelain --allow-root)
BLOG_PAGE_ID=$(wp post create --post_type=page --post_title="$BLOG_PAGE_NAME" --post_status=publish --porcelain --allow-root)
BLOG_PAGE_SLUG=$(wp post get $BLOG_PAGE_ID --field=post_name --allow-root)

# Set up permalinks and other settings to bypass the setup wizard
wp rewrite structure "/$BLOG_PAGE_SLUG/%postname%/" --hard --allow-root
wp rewrite flush --hard --allow-root
wp option update show_on_front 'page' --allow-root
wp option update page_on_front $HOME_PAGE_ID --allow-root
wp option update page_for_posts $BLOG_PAGE_ID --allow-root
wp option update blog_public 1 --allow-root

# Update .htaccess
wp rewrite flush --allow-root

sudo chmod +x wp-content/themes/$THEME_DIR/postinstall.sh && wp-content/themes/$THEME_DIR/postinstall.sh

echo "WordPress installation and configuration complete!"
fi

exit