diff --git a/.coverage b/.coverage new file mode 100644 index 0000000..c5fbc05 --- /dev/null +++ b/.coverage @@ -0,0 +1,4 @@ +1..3 +ok 1 apache file backup +ok 2 apache copy files +ok 3 apache final configuration diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..a356363 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1 @@ +repo_token: qJWIvjD1pMBLhuuCv0fWLCwZrNadN2nnd diff --git a/.gitignore b/.gitignore index 16e403e..ff6ca68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,15 @@ -# ignore error-pages +# ignore folders in src directory # src/httpd/error-pages/ src/git-old/ +src/phpmyadmin/ + + +# Exclude symlinks in dist folder +dist/adminer +dist/apache +dist/error-pages +dist/phpmyadmin +dist/websites # Vendor directory vendor/ diff --git a/.travis.yml b/.travis.yml index c812d03..ff1778e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,6 @@ matrix: osx_image: xcode9.2 - os: osx osx_image: xcode8 - - os: osx - osx_image: xcode6.4 # before_install: # - xcode-select --install script: diff --git a/CHANGELOG.md b/CHANGELOG.md index 890bb55..0c4c211 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,30 @@ Below is a detailed change-log, along with specific tasks completed, for each version released to date. +## Version 0.6.0 (12/06/2018) + +- [#new](#new) + - Entirely new test suite using [BATS][bats]. Each method is now tested using + individual `.bats` files contained in `./tests/bats/`. To run the entire + test suite issue the following command: + `$ bats tests/bats/`. This assumes you've [installed BATS][install-bats]. + - Added [Coveralls][coveralls] support but this is limited as they don't + support `bash` yet. Go figure. +- [#enhancement](#enhancement) + - Changed the success output from `printf` to `echo -e` as `printf` doesn't + work with `bats` properly. + - Removed `dist/websites` symlink as this gets generated at install time. +- [#bugfix](#bugfix) + - Fixed up an array of bugs in individual scripts as debugged with `bats`. + The list of changes is exhaustive so check the diff changes to the + `scripts` folder for more detail. + - Removed the `brew httpd` startup script as it's not needed. + - Removed `scripts/brew_install.sh` as it has been replaced with the main + `./brew` install script. + - Removed the Travis test for `xcode6.4` in `.travis.yml` as this project + doesn't build when running against `macOS 10.9/10.10`. It appears this + is only supported on `macOS 10.11` and later. + ## Version 0.5.2 (09/06/2018) - [#bugfix](#bugfix) @@ -10,6 +34,7 @@ version released to date. - `add_domains` - `apache_config.sh` - Fixed the extraction directory for phpMyAdmin in `thirdparty_install.sh`. + - Fixed up the `git commit` not happening in correct folder. - [#enhancement](#enhancement) - `brew_startup` added to `brew` script. - Added older versions of `macOS` for Travis to build against. @@ -148,14 +173,14 @@ version released to date. - [#new](#new) - Symbolic link to `/adminer/`. See issue #6 for more details on how it - will be integrated into the first release candidate. + will be integrated into the first release candidate. - Added new template files for issue #8: - ISSUE_TEMPLATE.md - CONTRIBUTING.md - PULL_REQUEST_TEMPLATE.md - [#enhancement](#enhancement) - Integrated changes from issue #8 to now create `.github/` directory with - templates when setting up a new domain. + templates when setting up a new domain. - Added `.github/` directory to this actual project using the new templates created in the #enhancement above. - [#bugfix](#bugfix) @@ -171,3 +196,7 @@ version released to date. - [#new](#new) - Initial Release + +[bats]: https://github.com/sstephenson/bats +[install-bats]: https://github.com/sstephenson/bats#installing-bats-from-source +[coveralls]: https://coveralls.io/github/justinhartman/Automated-LAMP-with-trusted-localhost-SSL diff --git a/README.md b/README.md index f9b4bb1..5d56781 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Waffle.io - Columns and their card count](https://badge.waffle.io/justinhartman/Automated-LAMP-with-trusted-localhost-SSL.png?columns=all)](https://waffle.io/justinhartman/Automated-LAMP-with-trusted-localhost-SSL?utm_source=badge) [![Build Status](https://travis-ci.org/justinhartman/Automated-LAMP-with-trusted-localhost-SSL.svg?branch=master)](https://travis-ci.org/justinhartman/Automated-LAMP-with-trusted-localhost-SSL) +[![Build Status](https://travis-ci.org/justinhartman/Automated-LAMP-with-trusted-localhost-SSL.svg?branch=master)](https://travis-ci.org/justinhartman/Automated-LAMP-with-trusted-localhost-SSL) [![Coverage Status](https://coveralls.io/repos/github/justinhartman/Automated-LAMP-with-trusted-localhost-SSL/badge.svg?branch=master)](https://coveralls.io/github/justinhartman/Automated-LAMP-with-trusted-localhost-SSL?branch=master) [![Waffle.io - Columns and their card count](https://badge.waffle.io/justinhartman/Automated-LAMP-with-trusted-localhost-SSL.png?columns=all)](https://waffle.io/justinhartman/Automated-LAMP-with-trusted-localhost-SSL?utm_source=badge) # Fully automated LAMP installation and configuration using Trusted localhost SSL Certificates diff --git a/dist/websites b/dist/websites deleted file mode 120000 index ee0da00..0000000 --- a/dist/websites +++ /dev/null @@ -1 +0,0 @@ -/usr/local/var/www/websites \ No newline at end of file diff --git a/install b/install index c430706..e9e9e3c 100755 --- a/install +++ b/install @@ -54,6 +54,7 @@ main_application () { source $scripts/setup_ssl.sh # Setup self-signed SSL source $scripts/apache_config.sh # Configure Apache 2 + source $scripts/thirdparty_install.sh # Install third-party tools source $scripts/folder_permissions.sh # Setting correct folder permissions echo "" >&2 @@ -62,7 +63,7 @@ main_application () echo "| Congratulations! You have successfully |" >&2 echo "| setup your localhost configuration. |" >&2 echo "| All the files you may need to edit are |" >&2 - echo "| contained in the `/dist/` folder. This |" >&2 + echo "| contained in the /dist/ folder. This |" >&2 echo "| includes any website you add and access to |" >&2 echo "| the ssl, adminer, phpmyadmin, error-pages |" >&2 echo "| and hosts folder. |" >&2 diff --git a/scripts/apache_config.sh b/scripts/apache_config.sh index ffd2d3d..7b81656 100755 --- a/scripts/apache_config.sh +++ b/scripts/apache_config.sh @@ -42,11 +42,10 @@ file_backup () echo "| Backing up old Apache config files. |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - mv $httpd/httpd.conf $httpd/httpd.conf.bak - mv $httpd/extra/httpd-ssl.conf $httpd/extra/httpd-ssl.conf.bak - mv $httpd/extra/httpd-vhosts.conf $httpd/extra/httpd-vhosts.conf.bak - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully backed up the Apache 2 - configuration files.${NOC}\n" + mv ${httpd}/httpd.conf ${httpd}/httpd.conf.original + mv ${httpd}/extra/httpd-ssl.conf ${httpd}/extra/httpd-ssl.conf.original + mv ${httpd}/extra/httpd-vhosts.conf ${httpd}/extra/httpd-vhosts.conf.original + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully backed up the Apache 2 configuration files.${NOC}\n" } ####################################### @@ -66,19 +65,18 @@ copy_files () echo "| Copying new Apache config files over... |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - cp $source/httpd/conf/httpd.conf $httpd/ - cp $source/httpd/conf/httpd-ssl.conf $httpd/extra/ - cp $source/httpd/conf/httpd-vhosts.conf $httpd/extra/ - cp $source/httpd/extra/httpd-custom-alias.conf $httpd/extra/ - cp $source/httpd/extra/httpd-custom-directory.conf $httpd/extra/ - cp $source/httpd/extra/httpd-custom-error-pages.conf $httpd/extra/ - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully copied the new Apache 2 - configuration files.${NOC}\n" + cp ${source}/httpd/conf/httpd.conf ${httpd}/ + cp ${source}/httpd/conf/httpd-ssl.conf ${httpd}/extra/ + cp ${source}/httpd/conf/httpd-vhosts.conf ${httpd}/extra/ + cp ${source}/httpd/extra/httpd-custom-alias.conf ${httpd}/extra/ + cp ${source}/httpd/extra/httpd-custom-directory.conf ${httpd}/extra/ + cp ${source}/httpd/extra/httpd-custom-error-pages.conf ${httpd}/extra/ + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully copied the new Apache 2 configuration files.${NOC}\n" } ####################################### -# Create website folder and restart -# Apache. +# Create website folder, restart +# Apache and create symbolic links. # Globals: # None # Arguments: @@ -86,15 +84,15 @@ copy_files () # Returns: # None ####################################### -final_steps () +final_configuration () { - mkdir -p $websites # Create default web root + mkdir -p ${websites} # Create default web root + ln -s ${websites} ${dist}/websites + ln -s ${httpd} ${dist}/apache apachectl restart # (Re)start Apache - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Your website folder has been -created at $websites -and Apache has been successfully restarted.${NOC}\n" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Your website folder has been created at ${websites} and you can edit your files in the 'dist' folder.${NOC}\n" } file_backup copy_files -final_steps +final_configuration diff --git a/scripts/brew_install.sh b/scripts/brew_install.sh deleted file mode 100644 index af61d78..0000000 --- a/scripts/brew_install.sh +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/bash -# -# Fully automated LAMP installation and configuration using Trusted localhost -# SSL Certificates -# -# Copyright: Copyright (C) 2018 Justin Hartman (https://justin.hartman.me) -# Author : Justin Hartman (https://justin.hartman.me) -# License : https://opensource.org/licenses/AGPL-3.0 AGPL-3.0 -# Version : 0.5.1 -# Link : https://github.com/22digital/Automated-LAMP-trusted-localhost-SSL -# Link : https://justin.hartman.me -# Since : 0.2.0 -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# - -####################################### -# This asks the user if they have -# Homebrew or not and waits for a Y or -# N answer. -# Globals: -# None -# Arguments: -# None -# Returns: -# Void -####################################### -brew_start () -{ - echo "" >&2 - echo -e "${RED} ----------------------------------------------" >&2 - echo "| |" >&2 - echo "| Do you have Homebrew installed on |" >&2 - echo "| your Apple macOS computer (Y/n)? |" >&2 - echo "| |" >&2 - echo -e " ---------------------------------------------- ${NOC}\n" >&2 - echo -n "" - read answer -} - -####################################### -# This installs Homebrew (`brew`) but -# only if the user hasn't got it and -# wants to install it via the script. -# Globals: -# None -# Arguments: -# None -# Returns: -# Void -####################################### -brew_install () -{ - echo "" >&2 - echo -e "${RED} ----------------------------------------------" >&2 - echo "| |" >&2 - echo "| Installing Homebrew. |" >&2 - echo "| |" >&2 - echo -e " ---------------------------------------------- ${NOC}\n" >&2 - echo "" >&2 - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed Homebrew.${NOC}\n" -} - -####################################### -# Installs the packages required from -# `brew` running `brew install`. -# Globals: -# None -# Arguments: -# None -# Returns: -# Void -####################################### -brew_packages () -{ - echo "" >&2 - echo -e "${RED} ----------------------------------------------" >&2 - echo "| |" >&2 - echo "| Installing Apache 2 and PHP. |" >&2 - echo "| |" >&2 - echo -e " ---------------------------------------------- ${NOC}\n" >&2 - brew install php httpd mysql - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed Apache 2 - and PHP.${NOC}\n" -} - -brew_start - -if [ "$answer" != "${answer#[Nn]}" ] ;then - brew_install - brew_packages -else - echo "" >&2 - echo -e "${RED} ----------------------------------------------" >&2 - echo "| |" >&2 - echo "| OK, we're not installing Homebrew so lets |" >&2 - echo "| proceed with installing the PHP and |" >&2 - echo "| Apache 2 packages. Give me a minute. |" >&2 - echo "| |" >&2 - echo -e " ---------------------------------------------- ${NOC}\n" >&2 - brew_packages -fi diff --git a/scripts/folder_and_git.sh b/scripts/folder_and_git.sh index 1a58021..ae3a764 100755 --- a/scripts/folder_and_git.sh +++ b/scripts/folder_and_git.sh @@ -47,13 +47,11 @@ folder_and_git () echo "| Add website folder and initialise git repo. |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - mkdir -p $websites/${domain} - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created folder in - $websites/${domain}.${NOC}\n" - git init $websites/${domain} - ls -lha $websites/${domain} - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created folder and - initialised git repo for ${domain}.${NOC}\n" + mkdir -p ${websites}/${domain} + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created folder in ${websites}/${domain}.${NOC}\n" + git init ${websites}/${domain} + ls -lha ${websites}/${domain} + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created folder and initialised git repo for ${domain}.${NOC}\n" } folder_and_git diff --git a/scripts/folder_permissions.sh b/scripts/folder_permissions.sh index e60afaf..5e1dd31 100755 --- a/scripts/folder_permissions.sh +++ b/scripts/folder_permissions.sh @@ -35,7 +35,7 @@ # Returns: # String Success message. ####################################### -folder_permissions () +folder_ownership () { echo "" >&2 echo -e "${GRY} ----------------------------------------------" >&2 @@ -44,11 +44,10 @@ folder_permissions () echo "| user account for the application folders. |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - chown -R $username:$group $main - chown -R $username:$group $httpd - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully set folder permissions - recursively on $main and $httpd.${NOC}\n" + chown -R ${username}:${group} ${main} + chown -R ${username}:${group} ${httpd} + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully set folder permissions recursively on ${main} and ${httpd}.${NOC}\n" } # Output the method -folder_permissions +folder_ownership diff --git a/scripts/git_setup.sh b/scripts/git_setup.sh index b134b2d..986c299 100755 --- a/scripts/git_setup.sh +++ b/scripts/git_setup.sh @@ -42,14 +42,14 @@ git_setup () echo "| git initial structure, files and check-in. |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - cp -R $source/git $websites/${domain} - ls -lha $websites/${domain} - cd $websites/${domain} + cp -R ${source}/git/templates/_core ${websites}/${domain} + cp ${source}/git/templates/_licenses/mit.txt ${websites}/${domain}/LICENSE + ls -lha ${websites}/${domain} + cd ${websites}/${domain} git add -A git commit -m "Created git structure, .github template and initial project commit." - cd - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created files and - committed changes.${NOC}\n" + echo "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created files and${NOC}" + echo "${CYA}committed changes.${NOC}\n" } git_setup diff --git a/scripts/globals.sh b/scripts/globals.sh index 572ccca..a1b5d6a 100755 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -1,7 +1,7 @@ #!/bin/bash # # Global variables for the app to use. These are included on all main scripts. -# +# # Copyright: Copyright (C) 2018 Justin Hartman (https://justin.hartman.me) # Author : Justin Hartman (https://justin.hartman.me) # License : https://opensource.org/licenses/AGPL-3.0 AGPL-3.0 @@ -9,7 +9,7 @@ # Link : https://github.com/22digital/Automated-LAMP-trusted-localhost-SSL # Link : https://justin.hartman.me # Since : 0.4.0 -# +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the @@ -22,7 +22,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -# +# ####################################### # Sets up global user variables. @@ -76,6 +76,7 @@ path_vars () scripts="./scripts" source="./src" dist="./dist" + hosts="/etc/hosts" } # Output the methods diff --git a/scripts/hosts_domain.sh b/scripts/hosts_domain.sh index 00230e8..b2eaab3 100755 --- a/scripts/hosts_domain.sh +++ b/scripts/hosts_domain.sh @@ -41,10 +41,9 @@ hosts_domain () echo "| Add new domain to hosts file. |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - echo "127.0.0.1 ${domain}" >> /etc/hosts - cat /etc/hosts | grep "${domain}" - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully added ${domain} to - /etc/hosts file.${NOC}\n" + echo "127.0.0.1 ${domain}" >> ${hosts} + cat ${hosts} | grep "${domain}" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully added ${domain} to ${hosts} file.${NOC}\n" } hosts_domain diff --git a/scripts/hosts_file.sh b/scripts/hosts_file.sh index 79d7257..cc4f324 100755 --- a/scripts/hosts_file.sh +++ b/scripts/hosts_file.sh @@ -40,12 +40,11 @@ hosts_file_backup () echo "" >&2 echo -e "${BRO} ----------------------------------------------" >&2 echo "| |" >&2 - echo "| Backup original hosts file '/etc/hosts' |" >&2 + echo "| Backup original hosts file ${hosts} |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - cp /etc/hosts $dist/hosts/hosts.original - printf "${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully backed up hosts file. - ${NOC}\n" + cp ${hosts} ${dist}/hosts/hosts.original + echo -e "${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully backed up hosts file.${NOC}\n" >&2 } ####################################### @@ -63,14 +62,13 @@ hosts_symbolic () echo "" >&2 echo -e "${GRY} ----------------------------------------------" >&2 echo "| |" >&2 - echo "| Create symbolic link for '/etc/hosts' to |" >&2 - echo "| point to 'dist/hosts/hosts' file. |" >&2 + echo "| Create symbolic link for ${hosts} to |" >&2 + echo "| point to 'dist/hosts/hosts' file. |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - ln -s /etc/hosts $dist/hosts/hosts - ls -lh $dist/hosts/hosts - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created symbolic link - from '/etc/hosts' to 'dist/hosts/hosts'.${NOC}\n" + ln -s ${hosts} ${dist}/hosts/hosts + ls -lh ${dist}/hosts/hosts + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created symbolic link from ${hosts} to ${dist}/hosts/hosts.${NOC}\n" >&2 } ####################################### diff --git a/scripts/keychain_certificate.sh b/scripts/keychain_certificate.sh index 295ff9b..07621cd 100755 --- a/scripts/keychain_certificate.sh +++ b/scripts/keychain_certificate.sh @@ -46,8 +46,7 @@ keychain_certificate () echo -e " ---------------------------------------------- ${NOC}\n" >&2 security add-trusted-cert -d -r trustAsRoot -p ssl \ -k '/Library/Keychains/System.keychain' $ssl/localhost_server.crt - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully updated the macOS - Keychain with a new SSL certificate with ${domain} added.${NOC}\n" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully updated the macOS Keychain with a new SSL certificate with ${domain} added.${NOC}\n" >&2 } keychain_certificate diff --git a/scripts/openssl_command.sh b/scripts/openssl_command.sh index a379025..165e656 100755 --- a/scripts/openssl_command.sh +++ b/scripts/openssl_command.sh @@ -43,24 +43,23 @@ openssl_command () echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 openssl req -new \ - -key $ssl/localhost_server.key \ - -out $ssl/localhost_server.csr \ + -key ${ssl}/localhost_server.key \ + -out ${ssl}/localhost_server.csr \ -subj "/C=$country/ST=$state/L=$city/O=$company/OU=$unit/CN=localhost" openssl x509 -req \ - -in $ssl/localhost_server.csr \ - -CA $ssl/localhost_rootCA.crt \ - -CAkey $ssl/localhost_rootCA.key \ + -in ${ssl}/localhost_server.csr \ + -CA ${ssl}/localhost_rootCA.crt \ + -CAkey ${ssl}/localhost_rootCA.key \ -CAcreateserial \ - -out $ssl/localhost_server.crt \ + -out ${ssl}/localhost_server.crt \ -days 9125 \ -sha256 \ - -extfile "$ssl/openssl.conf" + -extfile "${ssl}/openssl.conf" - ls -lh $ssl/localhost_server.c* + ls -lh ${ssl}/localhost_server.c* - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created SSL - certificates for ${domain}.${NOC}\n" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created SSL certificates for ${domain}.${NOC}\n" } openssl_command diff --git a/scripts/openssl_config.sh b/scripts/openssl_config.sh index c2c33e6..7e5e67a 100755 --- a/scripts/openssl_config.sh +++ b/scripts/openssl_config.sh @@ -42,12 +42,11 @@ openssl_config () echo "| file. |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - read serial <<< $(wc -l < $ssl/openssl.conf | tr -d ' ') + read serial <<< $(wc -l < ${ssl}/openssl.conf | tr -d ' ') serial=$((serial-11)) - echo "DNS.${serial} = ${domain}" >> $ssl/openssl.conf - cat $ssl/openssl.conf | grep "DNS" - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully added the ${domain} - domain name to the openssl configuration file.${NOC}\n" + echo "DNS.${serial} = ${domain}" >> ${ssl}/openssl.conf + cat ${ssl}/openssl.conf | grep "DNS" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully added ${domain} to the openssl configuration file.${NOC}\n" } openssl_config diff --git a/scripts/setup_ssl.sh b/scripts/setup_ssl.sh index 65f3d94..e9ca7d1 100755 --- a/scripts/setup_ssl.sh +++ b/scripts/setup_ssl.sh @@ -49,56 +49,56 @@ setup_ssl () echo -e " ---------------------------------------------- ${NOC}\n" >&2 # Create the SSL directory. - mkdir -p $ssl - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the ssl directory.${NOC}\n\n" + mkdir -p ${ssl} + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the ssl directory.${NOC}\n\n" - # Copy the `$source/ssl/openssl.conf` to $ssl. - cp $source/ssl/openssl.conf $ssl/ + # Copy the `${source}/ssl/openssl.conf` to ${ssl}. + cp ${source}/ssl/openssl.conf ${ssl}/ # create rootCA certificate - openssl genrsa -out $ssl/localhost_rootCA.key 2048 + openssl genrsa -out ${ssl}/localhost_rootCA.key 2048 openssl req -x509 -new -nodes \ - -key $ssl/localhost_rootCA.key \ + -key ${ssl}/localhost_rootCA.key \ -days 10950 \ - -out $ssl/localhost_rootCA.crt \ - -subj "/C=$country/ST=$state/L=$city/O=$company/OU=$unit/CN=$company Root CA" - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the $company rootCA SSL.${NOC}\n\n" + -out ${ssl}/localhost_rootCA.crt \ + -subj "/C=${country}/ST=${state}/L=${city}/O=${company}/OU=${unit}/CN=${company} Root CA" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the ${company} rootCA SSL.${NOC}\n\n" # create server key and certificate - openssl genrsa -out $ssl/localhost_server.key 2048 + openssl genrsa -out ${ssl}/localhost_server.key 2048 openssl req -new \ - -key $ssl/localhost_server.key \ - -out $ssl/localhost_server.csr \ - -subj "/C=$country/ST=$state/L=$city/O=$company/OU=$unit/CN=localhost" + -key ${ssl}/localhost_server.key \ + -out ${ssl}/localhost_server.csr \ + -subj "/C=${country}/ST=${state}/L=${city}/O=${company}/OU=${unit}/CN=localhost" openssl x509 -req \ - -in $ssl/localhost_server.csr \ - -CA $ssl/localhost_rootCA.crt \ - -CAkey $ssl/localhost_rootCA.key \ + -in ${ssl}/localhost_server.csr \ + -CA ${ssl}/localhost_rootCA.crt \ + -CAkey ${ssl}/localhost_rootCA.key \ -CAcreateserial \ - -out $ssl/localhost_server.crt \ + -out ${ssl}/localhost_server.crt \ -days 9125 \ -sha256 \ - -extfile $ssl/openssl.conf - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the localhost SSL.${NOC}\n\n" + -extfile ${ssl}/openssl.conf + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the localhost SSL.${NOC}\n\n" # create client key and certificate - openssl genrsa -out $ssl/localhost_client.key 2048 + openssl genrsa -out ${ssl}/localhost_client.key 2048 openssl req -new \ - -key $ssl/localhost_client.key \ - -out $ssl/localhost_client.csr \ - -subj "/C=$country/ST=$state/L=$city/O=$company/OU=$unit/CN=Client Certificate" + -key ${ssl}/localhost_client.key \ + -out ${ssl}/localhost_client.csr \ + -subj "/C=${country}/ST=${state}/L=${city}/O=${company}/OU=${unit}/CN=Client Certificate" openssl x509 -req \ - -in $ssl/localhost_client.csr \ - -CA $ssl/localhost_rootCA.crt \ - -CAkey $ssl/localhost_rootCA.key \ + -in ${ssl}/localhost_client.csr \ + -CA ${ssl}/localhost_rootCA.crt \ + -CAkey ${ssl}/localhost_rootCA.key \ -CAcreateserial \ - -out $ssl/localhost_client.crt \ + -out ${ssl}/localhost_client.crt \ -days 9125 - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the client SSL.${NOC}\n\n" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the client SSL.${NOC}\n\n" # Create symlink to the SSL folder in dist. - ln -s $ssl dist/ssl - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Created a symbolic link from '$ssl' to 'dist/ssl'.${NOC}\n\n" + ln -s ${ssl} dist/ssl + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Created a symbolic link from '${ssl}' to 'dist/ssl'.${NOC}\n\n" } ####################################### @@ -111,7 +111,7 @@ setup_ssl () # Returns: # String ####################################### -addto_keychain () +add_to_keychain () { echo "" >&2 echo -e "${BRO} ----------------------------------------------" >&2 @@ -122,15 +122,14 @@ addto_keychain () echo -e " ---------------------------------------------- ${NOC}\n" >&2 # Add the rootCA certificate first, grant all access. security add-trusted-cert -d -r trustRoot \ - -k '/Library/Keychains/System.keychain' $ssl/localhost_rootCA.crt + -k '/Library/Keychains/System.keychain' ${ssl}/localhost_rootCA.crt # Add the localhost certificate, always trust SSL access. security add-trusted-cert -d -r trustAsRoot -p ssl \ - -k '/Library/Keychains/System.keychain' $ssl/localhost_server.crt + -k '/Library/Keychains/System.keychain' ${ssl}/localhost_server.crt # Add the client certificate, always trust SSL access. security add-trusted-cert -d -r trustAsRoot -p smime \ - -k '/Library/Keychains/System.keychain' $ssl/localhost_client.crt - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully updated the macOS - Keychain with the new SSL certificate.${NOC}\n" + -k '/Library/Keychains/System.keychain' ${ssl}/localhost_client.crt + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully added the new Root CA, localhost server and client SSL certificates to the macOS Keychain.${NOC}\n" } ####################################### @@ -152,11 +151,10 @@ folder_permissions () echo "| user account for the new domain folder. |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - username=501 && chown -R $username:staff $ssl - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully set folder permissions - on $ssl.${NOC}\n" + username=501 && chown -R $username:staff ${ssl} + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully set folder permissions on ${ssl}.${NOC}\n" } setup_ssl -addto_keychain +add_to_keychain folder_permissions diff --git a/scripts/thirdparty_install.sh b/scripts/thirdparty_install.sh index 5357c69..fc5dbb1 100755 --- a/scripts/thirdparty_install.sh +++ b/scripts/thirdparty_install.sh @@ -22,11 +22,34 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -# +# + +####################################### +# Installs all the required git +# submodules using the 'git submodule +# update' command. +# Globals: +# None +# Arguments: +# None +# Returns: +# String +####################################### +git_submodule_install () +{ + echo "" >&2 + echo -e "${ORG} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Installing the Git Submodules... |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + git submodule update --init --recursive + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed the git submodules.${NOC}\n" +} ####################################### # Installs the Adminer project by -# checking out the source code to +# copying the submodule code to # `/usr/local/var/www/adminer/`. # Globals: # None @@ -35,7 +58,7 @@ # Returns: # String ####################################### -adminer_install () +adminer_copy () { echo "" >&2 echo -e "${ORG} ----------------------------------------------" >&2 @@ -43,17 +66,14 @@ adminer_install () echo "| Installing the Adminer project... |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - mkdir -p $main/adminer - cp -R $source/adminer $main/adminer - ln -s $main/adminer $dist/adminer - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully cloned the Adminer - sub-module to /usr/local/var/www/adminer/ and created a symbolic link - to $dist/adminer in the project folder..${NOC}\n" + cp -R ${source}/adminer ${main}/adminer + ln -s ${main}/adminer ${dist}/adminer + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully copied the Adminer sub-module to ${main}/adminer and created a symbolic link to ${dist}/adminer in the project folder.${NOC}\n" } ####################################### # Installs the Error Pages project by -# checking out the source code to +# copying the submodule code to # `/usr/local/var/www/error-pages/`. # Globals: # None @@ -62,7 +82,7 @@ adminer_install () # Returns: # String ####################################### -errorpages_install () +errorpages_copy () { echo "" >&2 echo -e "${GRN} ----------------------------------------------" >&2 @@ -70,17 +90,14 @@ errorpages_install () echo "| Installing the Apache Error Pages project...|" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - mkdir -p $main/error-pages - cp -R $source/httpd/error-pages/dist/apache $main/error-pages - ln -s $main/error-pages $dist/error-pages - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully cloned the Apache - Error Pages sub-module to $main/error-pages and created a - symbolic link to $dist/error-pages in the project folder.${NOC}\n" + cp -R ${source}/httpd/error-pages/dist/apache ${main}/error-pages + ln -s ${main}/error-pages ${dist}/error-pages + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully copied the Apache Error Pages sub-module to ${main}/error-pages and created a symbolic link to ${dist}/error-pages in the project folder.${NOC}\n" } ####################################### # Installs the phpMyAdmin project by -# checking out the source code to +# downloading and untaring the code to # `/usr/local/var/www/phpmyadmin/`. # Globals: # None @@ -91,33 +108,30 @@ errorpages_install () ####################################### phpmyadmin_install () { - echo "" >&2 + echo "" >&2 echo -e "${BRO} ----------------------------------------------" >&2 echo "| |" >&2 echo "| Installing the phpMyAdmin project... |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - mkdir $source/phpmyadmin - cd $source/archives/ - wget https://files.phpmyadmin.net/phpMyAdmin/4.8.1/phpMyAdmin-4.8.1-all-languages.tar.gz - tar -zxvf phpMyAdmin-4.8.1-all-languages.tar.gz \ + mkdir -p ${source}/phpmyadmin + mkdir -p ${source}/archives + cd ${source}/archives/ + wget https://files.phpmyadmin.net/phpMyAdmin/4.8.1/phpMyAdmin-4.8.1-all-languages.tar.gz + tar -zxvf phpMyAdmin-4.8.1-all-languages.tar.gz \ -C ../../src/phpmyadmin \ --strip-components=1 - cd ../../ - cp -R $source/phpmyadmin $main/phpmyadmin - ln -s $main/phpmyadmin $dist/phpmyadmin - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed the phpMyAdmin -sub-module to $main/phpmyadmin and created a -symbolic link to $dist/phpmyadmin in the project folder.${NOC}\n" + cd ../../ + cp -R ${source}/phpmyadmin ${main}/phpmyadmin + ln -s ${main}/phpmyadmin ${dist}/phpmyadmin + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed the phpMyAdmin sub-module to ${main}/phpmyadmin and created a symbolic link to ${dist}/phpmyadmin in the project folder.${NOC}\n" } ####################################### # Install all the sub-modules required # for the project. ####################################### -adminer_install -errorpages_install +git_submodule_install +adminer_copy +errorpages_copy phpmyadmin_install - -printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Installation complete. All the - required sub-modules have been installed.${NOC}\n" diff --git a/scripts/upgrade_software.sh b/scripts/upgrade_software.sh index c67df1f..4cc6c1a 100755 --- a/scripts/upgrade_software.sh +++ b/scripts/upgrade_software.sh @@ -41,29 +41,30 @@ upgrade_projects () echo "" >&2 echo -e "${ORG} ----------------------------------------------" >&2 echo "| |" >&2 - echo "| Checking if I need to upgrade the core... |" >&2 + echo "| Checking for upgrades to the core... |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 git pull + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully updated the core project.${NOC}\n" echo "" >&2 echo -e "${ORG} ----------------------------------------------" >&2 echo "| |" >&2 - echo "| Checking for an upgrade to the Apache |" >&2 - echo "| Error Pages project... |" >&2 + echo "| Checking for upgrades to the Adminer, |" >&2 + echo "| GitHub and Apache Error Pages projects... |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - cd src/httpd/error-pages/ - git pull - cp -R dist/apache/* /usr/local/var/www/error-pages + git submodule update --init --recursive + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully updated all the git submodules.${NOC}\n" echo "" >&2 echo -e "${ORG} ----------------------------------------------" >&2 echo "| |" >&2 - echo "| Checking for an upgrade to the Adminer |" >&2 - echo "| project... |" >&2 + echo "| Copying any new files to their correct |" >&2 + echo "| folder locations... |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 - cd /usr/local/var/www/adminer/ - git pull + cp -R ${source}/httpd/error-pages/dist/apache ${main}/error-pages + cp -R ${source}/adminer ${main}/adminer + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully copied across all the new files.${NOC}\n" } ####################################### @@ -83,8 +84,7 @@ read answer if [ "$answer" != "${answer#[Yy]}" ] ;then upgrade_projects - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully upgraded the core and - all related sub-modules.${NOC}\n" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully upgraded the core and all related sub-modules.${NOC}\n" else echo -e "${ORG} ----------------------------------------------" >&2 echo "| |" >&2 @@ -93,7 +93,7 @@ else echo "| software up to date. Using the most up to |" >&2 echo "| date files ensures you benefit from bug |" >&2 echo "| fixes and enhancements. You should |" >&2 - echo "| consider updating. |" >&2 + echo "| reconsider and update frequently. |" >&2 echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 fi diff --git a/src/brew/homebrew.mxcl.httpd.plist b/src/brew/homebrew.mxcl.httpd.plist deleted file mode 100644 index a009fd9..0000000 --- a/src/brew/homebrew.mxcl.httpd.plist +++ /dev/null @@ -1,16 +0,0 @@ - - - - - Label - homebrew.mxcl.httpd - ProgramArguments - - /usr/local/opt/httpd/bin/httpd - -D - FOREGROUND - - RunAtLoad - - - diff --git a/tests/bats/_setup.bats b/tests/bats/_setup.bats new file mode 100644 index 0000000..83c63e4 --- /dev/null +++ b/tests/bats/_setup.bats @@ -0,0 +1,39 @@ +#!/usr/bin/env bats + +setup () +{ + load globals +} + +@test "cleanup test directory and clone project repo" { + test_directory_delete () + { + rm -Rf ${TMP}/* + touch ${LOG} + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" + git clone --recursive https://gitlab.com/justinhartman/Automated-LAMP-with-trusted-localhost-SSL.git ${GIT} + } + # Execute the tests + run test_directory_delete + [ "$status" -eq 0 ] +} + +@test "create test directory structure" { + test_directory_structure () + { + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" + mkdir -p ${main} + mkdir -p ${httpd} + mkdir -p ${websites} + mkdir -p ${ssl} + mkdir -p ${etc} + mkdir -p ${websites}/${domain} + touch ${hosts} + touch ${httpd}/httpd.conf + touch ${httpd}/extra/httpd-ssl.conf + touch ${httpd}/extra/httpd-vhosts.conf + } + # Execute the tests + run test_directory_structure + [ "$status" -eq 0 ] +} diff --git a/tests/bats/apache_config.bats b/tests/bats/apache_config.bats new file mode 100644 index 0000000..6429585 --- /dev/null +++ b/tests/bats/apache_config.bats @@ -0,0 +1,65 @@ +#!/usr/bin/env bats + +setup () +{ + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "apache file backup" { + file_backup () + { + echo "" >&2 + echo -e "${GRY} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Backing up old Apache config files. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + mv ${httpd}/httpd.conf ${httpd}/httpd.conf.original + mv ${httpd}/extra/httpd-ssl.conf ${httpd}/extra/httpd-ssl.conf.original + mv ${httpd}/extra/httpd-vhosts.conf ${httpd}/extra/httpd-vhosts.conf.original + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully backed up the Apache 2 configuration files.${NOC}\n" + } + # Execute the tests + run file_backup + [ "${lines[7]}" = "✔ Successfully backed up the Apache 2 configuration files." ] + [ "$status" -eq 0 ] +} + +@test "apache copy files" { + copy_files () + { + echo "" >&2 + echo -e "${GRY} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Copying new Apache config files over... |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + cp ${source}/httpd/conf/httpd.conf ${httpd}/ + cp ${source}/httpd/conf/httpd-ssl.conf ${httpd}/extra/ + cp ${source}/httpd/conf/httpd-vhosts.conf ${httpd}/extra/ + cp ${source}/httpd/extra/httpd-custom-alias.conf ${httpd}/extra/ + cp ${source}/httpd/extra/httpd-custom-directory.conf ${httpd}/extra/ + cp ${source}/httpd/extra/httpd-custom-error-pages.conf ${httpd}/extra/ + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully copied the new Apache 2 configuration files.${NOC}\n" + } + # Execute the tests + run copy_files + [ "${lines[10]}" = "✔ Successfully copied the new Apache 2 configuration files." ] + [ "$status" -eq 0 ] +} + +@test "apache final configuration" { + final_configuration () + { + mkdir -p ${websites} # Create default web root + ln -s ${websites} ${dist}/websites + ln -s ${httpd} ${dist}/apache + apachectl restart # (Re)start Apache + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Your website folder has been created at ${websites} and you can edit your files in the 'dist' folder.${NOC}\n" + } + # Execute the tests + run final_configuration + [ "${lines[7]}" = "✔ Your website folder has been created at ${websites} and you can edit your files in the 'dist' folder." ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/brew.bats b/tests/bats/brew.bats new file mode 100644 index 0000000..c424a3a --- /dev/null +++ b/tests/bats/brew.bats @@ -0,0 +1,93 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "global includes" { + global_includes () + { + source scripts/globals.sh + source scripts/colour_palette.sh + } + run global_includes + [ "$status" -eq 0 ] +} + +@test "brew start" { + brew_start () + { + echo "" >&2 + echo -e "${RED} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Do you have Homebrew installed on |" >&2 + echo "| your Apple macOS computer (Y/n)? |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + # echo -n "" + # read answer + answer="n" + } + run brew_start + [ "$status" -eq 0 ] +} + +@test "brew install" { + brew_install () + { + echo "" >&2 + echo -e "${RED} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Installing Homebrew. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + echo "" >&2 + # /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + echo "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed Homebrew.${NOC}\n" + } + # skip + run brew_install + [ "${lines[5]}" = "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed Homebrew.${NOC}\n" >&2 ] + [ "$status" -eq 0 ] +} + +@test "brew packages" { + brew_packages () + { + echo "" >&2 + echo -e "${RED} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Installing Apache 2, MySQL and PHP. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + brew install httpd mysql php + echo "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed Apache 2, + MySQL and PHP.${NOC}\n" + } + # skip + run brew_packages + [ "${lines[11]}" = "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed Apache 2," ] + [ "$status" -eq 0 ] +} + +@test "brew startup" { + brew_startup () + { + echo "" >&2 + echo -e "${RED} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Starting Apache 2, MySQL and PHP. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + brew services start httpd + brew services start mysql + brew services start php + echo "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully started Apache 2, + MySQL and PHP.${NOC}\n" + } + # skip + run brew_startup + [ "${lines[8]}" = "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully started Apache 2," ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/colour_palette.bats b/tests/bats/colour_palette.bats new file mode 100644 index 0000000..c9010bf --- /dev/null +++ b/tests/bats/colour_palette.bats @@ -0,0 +1,28 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "colour palette" { + colour_palette () + { + # Some colours to mess around with + BLK='\033[0;30m' # Black + GRY='\033[1;30m' # Dark Gray + RED='\033[0;31m' # Red + ORG='\033[1;31m' # Light Red (Orange) + GRN='\033[0;32m' # Green + BRO='\033[0;33m' # Brown/Orange + BLU='\033[0;34m' # Blue + PUR='\033[0;35m' # Purple + LPU='\033[1;35m' # Light Purple + CYA='\033[0;36m' # Cyan + LGY='\033[0;37m' # Light Gray + WHT='\033[1;37m' # White + NOC='\033[0m' # No Color + } + run colour_palette + [ "$status" -eq 0 ] +} diff --git a/tests/bats/enter_domain.bats b/tests/bats/enter_domain.bats new file mode 100644 index 0000000..6362759 --- /dev/null +++ b/tests/bats/enter_domain.bats @@ -0,0 +1,25 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "enter domain name" { + enter_domain () + { + echo -e "${RED} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| The Aston Martin of perfect LAMP setups |" >&2 + echo "| and configuration; automating the entire |" >&2 + echo "| process and managing your localhost SSL |" >&2 + echo "| using trusted self-signed CA certificates. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + echo "Enter the domain name to be added " >&2 + domain="www.test.localhost" + } + run enter_domain + [ "${lines[8]}" = "Enter the domain name to be added " ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/folder_and_git.bats b/tests/bats/folder_and_git.bats new file mode 100644 index 0000000..7d0c880 --- /dev/null +++ b/tests/bats/folder_and_git.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "folder and git setup" { + folder_and_git () + { + echo "" >&2 + echo -e "${BLU} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Add website folder and initialise git repo. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + mkdir -p ${websites}/${domain} + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created folder in ${websites}/${domain}.${NOC}\n" + git init ${websites}/${domain} + ls -lha ${websites}/${domain} + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created folder and initialised git repo for ${domain}.${NOC}\n" + } + run folder_and_git + [ "${lines[5]}" = "✔ Successfully created folder in ${websites}/${domain}." ] + [ "${lines[12]}" = "✔ Successfully created folder and initialised git repo for ${domain}." ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/folder_permissions.bats b/tests/bats/folder_permissions.bats new file mode 100644 index 0000000..aa8594b --- /dev/null +++ b/tests/bats/folder_permissions.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +setup () +{ + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "change file and folder ownership" { + folder_ownership () + { + echo "" >&2 + echo -e "${GRY} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Setting correct folder permissions to your |" >&2 + echo "| user account for the application folders. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + chown -R ${username}:${group} ${main} + chown -R ${username}:${group} ${httpd} + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully set folder permissions recursively on ${main} and ${httpd}.${NOC}\n" + } + # Execute the tests + run folder_ownership + [ "${lines[6]}" = "✔ Successfully set folder permissions recursively on ${main} and ${httpd}." ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/git_setup.bats b/tests/bats/git_setup.bats new file mode 100644 index 0000000..ccb0d3f --- /dev/null +++ b/tests/bats/git_setup.bats @@ -0,0 +1,31 @@ +#!/usr/bin/env bats + +setup () +{ + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "git setup" { + git_setup () + { + echo "" >&2 + echo -e "${PUR} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| git initial structure, files and check-in. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + cp -R ${source}/git/templates/_core ${websites}/${domain} + cp ${source}/git/templates/_licenses/mit.txt ${websites}/${domain}/LICENSE + ls -lha ${websites}/${domain} + cd ${websites}/${domain} + git add -A + git commit -m "Created git structure, .github template and initial project commit." + echo "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created files and${NOC}" + echo "${CYA}committed changes.${NOC}\n" + } + run git_setup + [ "${lines[13]}" = "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created files and${NOC}" ] + [ "${lines[14]}" = "${CYA}committed changes.${NOC}\n" ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/globals.bash b/tests/bats/globals.bash new file mode 100644 index 0000000..04a14c9 --- /dev/null +++ b/tests/bats/globals.bash @@ -0,0 +1,33 @@ +#!/bin/bash + +test_global_vars () { + NOW=$(date) + # TMP="${BATS_TMPDIR}" + # GIT="${TMP}/automated-lamp" + TMP="/usr/local/tmp" + GIT="${TMP}/automated-lamp" + LOG="${TMP}/test_install.log" + + domain="www.test.localhost" + + username="501" + group="staff" + + country="ZA" + state="Western Cape" + city="Cape Town" + company="22 Digital" + unit="Security" + + main="${TMP}/usr/local/var/www" + httpd="${TMP}/usr/local/etc/httpd" + websites="${TMP}/usr/local/var/www/websites" + ssl="${TMP}/usr/local/var/www/ssl" + scripts="${GIT}/scripts" + source="${GIT}/src" + dist="${GIT}/dist" + etc="${TMP}/etc" + hosts="${TMP}/etc/hosts" +} + +test_global_vars diff --git a/tests/bats/globals.bats b/tests/bats/globals.bats new file mode 100644 index 0000000..e68f5bc --- /dev/null +++ b/tests/bats/globals.bats @@ -0,0 +1,44 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "user variables" { + user_vars () + { + username="501" + group="staff" + } + run user_vars + [ "$status" -eq 0 ] +} + +@test "ssl variables" { + ssl_vars () + { + country="ZA" + state="Western Cape" + city="Cape Town" + company="22 Digital" + unit="Security" + } + run ssl_vars + [ "$status" -eq 0 ] +} + +@test "path variables" { + path_vars () + { + main="/usr/local/var/www" + httpd="/usr/local/etc/httpd" + websites="/usr/local/var/www/websites" + ssl="/usr/local/var/www/ssl" + scripts="./scripts" + source="./src" + dist="./dist" + } + run path_vars + [ "$status" -eq 0 ] +} diff --git a/tests/bats/hosts_domain.bats b/tests/bats/hosts_domain.bats new file mode 100644 index 0000000..f0bf82f --- /dev/null +++ b/tests/bats/hosts_domain.bats @@ -0,0 +1,25 @@ +#!/usr/bin/env bats + +setup () +{ + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "hosts file domain insert" { + hosts_domain () + { + echo "" >&2 + echo -e "${WHT} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Add new domain to hosts file. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + echo "127.0.0.1 ${domain}" >> ${hosts} + cat ${hosts} | grep "${domain}" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully added ${domain} to ${hosts} file.${NOC}\n" + } + run hosts_domain + [ "${lines[7]}" = "✔ Successfully added ${domain} to ${hosts} file." ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/hosts_file.bats b/tests/bats/hosts_file.bats new file mode 100755 index 0000000..f7d7ef8 --- /dev/null +++ b/tests/bats/hosts_file.bats @@ -0,0 +1,42 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "hosts file backup" { + hosts_file_backup () + { + echo "" >&2 + echo -e "${BRO} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Backup original hosts file ${hosts} |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + cp ${hosts} ${dist}/hosts/hosts.original + echo -e "${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully backed up hosts file.${NOC}\n" >&2 + } + run hosts_file_backup + [ "${lines[6]}" = "✔ Successfully backed up hosts file." ] + [ "$status" -eq 0 ] +} + +@test "hosts symbolic link" { + hosts_symbolic () + { + echo "" >&2 + echo -e "${GRY} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Create symbolic link for ${hosts} to |" >&2 + echo "| point to 'dist/hosts/hosts' file. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + ln -s ${hosts} ${dist}/hosts/hosts + ls -lh ${dist}/hosts/hosts + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created symbolic link from ${hosts} to ${dist}/hosts/hosts.${NOC}\n" >&2 + } + run hosts_symbolic + [ "${lines[8]}" = "✔ Successfully created symbolic link from ${hosts} to ${dist}/hosts/hosts." ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/keychain_certificate.bats b/tests/bats/keychain_certificate.bats new file mode 100755 index 0000000..f29cc0d --- /dev/null +++ b/tests/bats/keychain_certificate.bats @@ -0,0 +1,26 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "add ssl to keychain certificate" { + keychain_certificate () + { + echo "" >&2 + echo -e "${BRO} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Adding new SSL cert to macOS' Keychain so |" >&2 + echo "| that you don't get browser errors when |" >&2 + echo "| accessing your new domain over https. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + security add-trusted-cert -d -r trustAsRoot -p ssl \ + -k '/Library/Keychains/System.keychain' $ssl/localhost_server.crt + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully updated the macOS Keychain with a new SSL certificate with ${domain} added.${NOC}\n" >&2 + } + run keychain_certificate + [ "${lines[9]}" = "✔ Successfully updated the macOS Keychain with a new SSL certificate with ${domain} added." ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/openssl_command.bats b/tests/bats/openssl_command.bats new file mode 100755 index 0000000..00fe555 --- /dev/null +++ b/tests/bats/openssl_command.bats @@ -0,0 +1,40 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "openssl command" { + openssl_command () + { + echo "" >&2 + echo -e "${GRN} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Create SSL Certificates for the new domain. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + openssl req -new \ + -key ${ssl}/localhost_server.key \ + -out ${ssl}/localhost_server.csr \ + -subj "/C=$country/ST=$state/L=$city/O=$company/OU=$unit/CN=localhost" + + openssl x509 -req \ + -in ${ssl}/localhost_server.csr \ + -CA ${ssl}/localhost_rootCA.crt \ + -CAkey ${ssl}/localhost_rootCA.key \ + -CAcreateserial \ + -out ${ssl}/localhost_server.crt \ + -days 9125 \ + -sha256 \ + -extfile "${ssl}/openssl.conf" + + ls -lh ${ssl}/localhost_server.c* + + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created SSL certificates for ${domain}.${NOC}\n" + } + + run openssl_command + [ "${lines[11]}" = "✔ Successfully created SSL certificates for ${domain}." ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/openssl_config.bats b/tests/bats/openssl_config.bats new file mode 100755 index 0000000..0172ee4 --- /dev/null +++ b/tests/bats/openssl_config.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "openssl configuration" { + openssl_config () + { + echo "" >&2 + echo -e "${ORG} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Add domain to 'openssl.conf' configuration |" >&2 + echo "| file. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + read serial <<< $(wc -l < ${ssl}/openssl.conf | tr -d ' ') + serial=$((serial-11)) + echo "DNS.${serial} = ${domain}" >> ${ssl}/openssl.conf + cat ${ssl}/openssl.conf | grep "DNS" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully added ${domain} to the openssl configuration file.${NOC}\n" + } + run openssl_config + [ "${lines[9]}" = "✔ Successfully added ${domain} to the openssl configuration file." ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/project_structure.bash b/tests/bats/project_structure.bash new file mode 100755 index 0000000..de98ca9 --- /dev/null +++ b/tests/bats/project_structure.bash @@ -0,0 +1,23 @@ +#!/bin/bash + +test_directory_delete () +{ + rm -Rf ${TMP}/* +} + +test_directory_structure () +{ + mkdir -p ${TMP} + mkdir -p ${main} + mkdir -p ${httpd} + mkdir -p ${websites} + mkdir -p ${ssl} + mkdir -p ${source} + mkdir -p ${dist} + mkdir -p ${etc} + touch ${hosts} + touch ${LOG} +} + +test_directory_delete +test_directory_structure diff --git a/tests/bats/setup_ssl.bats b/tests/bats/setup_ssl.bats new file mode 100755 index 0000000..3c27263 --- /dev/null +++ b/tests/bats/setup_ssl.bats @@ -0,0 +1,122 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "setup ssl" { + setup_ssl () + { + echo "" >&2 + echo -e "${BRO} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Setting up the self-signed SSL certificates |" >&2 + echo "| for Apache 2 and adding them to Apple's |" >&2 + echo "| Keychain as trusted SSL certificates. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + + # Create the SSL directory. + mkdir -p ${ssl} + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the ssl directory.${NOC}\n\n" + + # Copy the `${source}/ssl/openssl.conf` to ${ssl}. + cp ${source}/ssl/openssl.conf ${ssl}/ + + # create rootCA certificate + openssl genrsa -out ${ssl}/localhost_rootCA.key 2048 + openssl req -x509 -new -nodes \ + -key ${ssl}/localhost_rootCA.key \ + -days 10950 \ + -out ${ssl}/localhost_rootCA.crt \ + -subj "/C=${country}/ST=${state}/L=${city}/O=${company}/OU=${unit}/CN=${company} Root CA" + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the ${company} rootCA SSL.${NOC}\n\n" + + # create server key and certificate + openssl genrsa -out ${ssl}/localhost_server.key 2048 + openssl req -new \ + -key ${ssl}/localhost_server.key \ + -out ${ssl}/localhost_server.csr \ + -subj "/C=${country}/ST=${state}/L=${city}/O=${company}/OU=${unit}/CN=localhost" + openssl x509 -req \ + -in ${ssl}/localhost_server.csr \ + -CA ${ssl}/localhost_rootCA.crt \ + -CAkey ${ssl}/localhost_rootCA.key \ + -CAcreateserial \ + -out ${ssl}/localhost_server.crt \ + -days 9125 \ + -sha256 \ + -extfile ${ssl}/openssl.conf + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the localhost SSL.${NOC}\n\n" + + # create client key and certificate + openssl genrsa -out ${ssl}/localhost_client.key 2048 + openssl req -new \ + -key ${ssl}/localhost_client.key \ + -out ${ssl}/localhost_client.csr \ + -subj "/C=${country}/ST=${state}/L=${city}/O=${company}/OU=${unit}/CN=Client Certificate" + openssl x509 -req \ + -in ${ssl}/localhost_client.csr \ + -CA ${ssl}/localhost_rootCA.crt \ + -CAkey ${ssl}/localhost_rootCA.key \ + -CAcreateserial \ + -out ${ssl}/localhost_client.crt \ + -days 9125 + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully created the client SSL.${NOC}\n\n" + + # Create symlink to the SSL folder in dist. + ln -s ${ssl} dist/ssl + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Created a symbolic link from '${ssl}' to 'dist/ssl'.${NOC}\n\n" + } + run setup_ssl + [ "${lines[7]}" = "✔ Successfully created the ssl directory." ] + [ "${lines[13]}" = "✔ Successfully created the ${company} rootCA SSL." ] + [ "${lines[19]}" = "✔ Successfully created the localhost SSL." ] + [ "${lines[27]}" = "✔ Successfully created the client SSL." ] + [ "$status" -eq 0 ] +} + +@test "add certificates to apple keychain" { + add_to_keychain () + { + echo "" >&2 + echo -e "${BRO} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Adding certificates to Apple's Keychain as |" >&2 + echo "| trusted SSL certificates. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + # Add the rootCA certificate first, grant all access. + security add-trusted-cert -d -r trustRoot \ + -k '/Library/Keychains/System.keychain' ${ssl}/localhost_rootCA.crt + # Add the localhost certificate, always trust SSL access. + security add-trusted-cert -d -r trustAsRoot -p ssl \ + -k '/Library/Keychains/System.keychain' ${ssl}/localhost_server.crt + # Add the client certificate, always trust SSL access. + security add-trusted-cert -d -r trustAsRoot -p smime \ + -k '/Library/Keychains/System.keychain' ${ssl}/localhost_client.crt + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully added the new Root CA, localhost server and client SSL certificates to the macOS Keychain.${NOC}\n" + } + run add_to_keychain + [ "${lines[10]}" = "✔ Successfully added the new Root CA, localhost server and client SSL certificates to the macOS Keychain." ] + [ "$status" -eq 0 ] +} + +@test "set folder permissions" { + folder_permissions () + { + echo "" >&2 + echo -e "${GRY} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Setting correct folder permissions to your |" >&2 + echo "| user account for the new domain folder. |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + username=501 && chown -R $username:staff ${ssl} + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully set folder permissions on ${ssl}.${NOC}\n" + } + run folder_permissions + [ "${lines[6]}" = "✔ Successfully set folder permissions on ${ssl}." ] + [ "$status" -eq 0 ] +} diff --git a/tests/bats/thirdparty_install.bats b/tests/bats/thirdparty_install.bats new file mode 100755 index 0000000..197a8ce --- /dev/null +++ b/tests/bats/thirdparty_install.bats @@ -0,0 +1,85 @@ +#!/usr/bin/env bats + +setup() { + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "git submodule install" { + git_submodule_install () + { + echo "" >&2 + echo -e "${ORG} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Installing the Git Submodules... |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + git submodule update --init --recursive + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed the git submodules.${NOC}\n" + } + run git_submodule_install + [ "${lines[5]}" = "✔ Successfully installed the git submodules." ] + [ "$status" -eq 0 ] +} + +@test "adminer install" { + adminer_copy () + { + echo "" >&2 + echo -e "${ORG} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Installing the Adminer project... |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + cp -R ${source}/adminer ${main}/adminer + ln -s ${main}/adminer ${dist}/adminer + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully copied the Adminer sub-module to ${main}/adminer and created a symbolic link to ${dist}/adminer in the project folder.${NOC}\n" + } + run adminer_copy + [ "${lines[7]}" = "✔ Successfully copied the Adminer sub-module to ${main}/adminer and created a symbolic link to ${dist}/adminer in the project folder." ] + [ "$status" -eq 0 ] +} + +@test "error pages install" { + errorpages_copy () + { + echo "" >&2 + echo -e "${GRN} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Installing the Apache Error Pages project...|" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + cp -R ${source}/httpd/error-pages/dist/apache ${main}/error-pages + ln -s ${main}/error-pages ${dist}/error-pages + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully copied the Apache Error Pages sub-module to ${main}/error-pages and created a symbolic link to ${dist}/error-pages in the project folder.${NOC}\n" + } + run errorpages_copy + [ "${lines[7]}" = "✔ Successfully copied the Apache Error Pages sub-module to ${main}/error-pages and created a symbolic link to ${dist}/error-pages in the project folder." ] + [ "$status" -eq 0 ] +} + +@test "phpmyadmin install" { + phpmyadmin_install () + { + echo "" >&2 + echo -e "${BRO} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Installing the phpMyAdmin project... |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + mkdir -p ${source}/phpmyadmin + mkdir -p ${source}/archives + cd ${source}/archives/ + wget https://files.phpmyadmin.net/phpMyAdmin/4.8.1/phpMyAdmin-4.8.1-all-languages.tar.gz + tar -zxvf phpMyAdmin-4.8.1-all-languages.tar.gz \ + -C ${source}/phpmyadmin \ + --strip-components=1 + cd ../../ + cp -R ${source}/phpmyadmin ${main}/phpmyadmin + ln -s ${main}/phpmyadmin ${dist}/phpmyadmin + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed the phpMyAdmin sub-module to ${main}/phpmyadmin and created a symbolic link to ${dist}/phpmyadmin in the project folder.${NOC}\n" + } + # skip + run phpmyadmin_install + [ "$status" -eq 0 ] +} diff --git a/tests/bats/upgrade_software.bats b/tests/bats/upgrade_software.bats new file mode 100755 index 0000000..f6b1984 --- /dev/null +++ b/tests/bats/upgrade_software.bats @@ -0,0 +1,46 @@ +#!/usr/bin/env bats + +setup () +{ + load globals + echo "${NOW}: ${BATS_TEST_NAME}" >> "${LOG}" +} + +@test "upgrade adminer and apache error pages projects" { + upgrade_projects () + { + echo "" >&2 + echo -e "${ORG} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Checking for upgrades to the core... |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + cd ${GIT} + git pull + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully updated the core project.${NOC}\n" + echo "" >&2 + echo -e "${ORG} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Checking for upgrades to the Adminer, |" >&2 + echo "| GitHub and Apache Error Pages projects... |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + git submodule update --init --recursive + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully updated all the git submodules.${NOC}\n" + echo "" >&2 + echo -e "${ORG} ----------------------------------------------" >&2 + echo "| |" >&2 + echo "| Copying any new files to their correct |" >&2 + echo "| folder locations... |" >&2 + echo "| |" >&2 + echo -e " ---------------------------------------------- ${NOC}\n" >&2 + cp -R ${source}/httpd/error-pages/dist/apache ${main}/error-pages + cp -R ${source}/adminer ${main}/adminer + echo -e "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully copied across all the new files.${NOC}\n" + } + run upgrade_projects + [ "${lines[6]}" = "✔ Successfully updated the core project." ] + [ "${lines[13]}" = "✔ Successfully updated all the git submodules." ] + [ "${lines[20]}" = "✔ Successfully copied across all the new files." ] + [ "$status" -eq 0 ] +} diff --git a/tests/brew b/tests/brew index f5c2983..0209fbd 100755 --- a/tests/brew +++ b/tests/brew @@ -63,7 +63,7 @@ brew_start () echo -e " ---------------------------------------------- ${NOC}\n" >&2 # echo -n "" # read answer - answer='n' + answer="n" } ####################################### @@ -87,7 +87,7 @@ brew_install () echo -e " ---------------------------------------------- ${NOC}\n" >&2 echo "" >&2 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed Homebrew.${NOC}\n" + echo "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed Homebrew.${NOC}\n" } ####################################### @@ -109,7 +109,7 @@ brew_packages () echo "| |" >&2 echo -e " ---------------------------------------------- ${NOC}\n" >&2 brew install httpd mysql php - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed Apache 2, + echo "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully installed Apache 2, MySQL and PHP.${NOC}\n" } @@ -134,7 +134,7 @@ brew_startup () brew services start httpd brew services start mysql brew services start php - printf "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully started Apache 2, + echo "\n${GRN}\xE2\x9C\x94${NOC} ${CYA}Successfully started Apache 2, MySQL and PHP.${NOC}\n" }