Created
March 21, 2015 01:23
-
-
Save pospi/96a966fdedccc41b826a to your computer and use it in GitHub Desktop.
A basket init script for a LEMP server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
echo Setting up dev server | |
# Change these as you need: | |
declare HOSTNAME=my_host | |
declare DB_ROOT_PW=my_password | |
declare DB_NAME=my_dbname | |
declare NGINX_CONFIG=my_site | |
declare OPTIONAL_PACKAGES="sudo vim git" | |
# You may wish to disable these to save time: | |
declare UPDATE_PACKAGE_LISTS=yes | |
declare UPGRADE_PACKAGES=yes | |
# Adjust these to point to the "tools" script and your config directory: | |
readonly TOOLS_PATH=tools | |
readonly TOOLS_CONFIG_PATH=config/ | |
echo Sourcing tools... | |
. ${TOOLS_PATH} | |
echo Done sourcing tools | |
config_option DB_ROOT_PW \ | |
"Root password to set for MySQL/PostgreSQL/etc" | |
config_option DB_NAME \ | |
"Name for new database to create" \ | |
must_be_one_word | |
config_option NGINX_CONFIG \ | |
"Name of nginx site to configure and enable."\ | |
must_be_file_at '${config}/nginx/${option}.conf' | |
config_option UPDATE_PACKAGE_LISTS \ | |
"If package source lists (eg apt sources) should be updated" \ | |
must_be_yes_or_no | |
config_option UPGRADE_PACKAGES \ | |
"If all packages should be upgraded to latest versions before starting" \ | |
must_be_yes_or_no | |
config_done_creating_options | |
# This performs a sanity check for options configured above | |
config_check_options | |
update_package_lists_if_enabled | |
exit_if_failure | |
upgrade_packages_if_enabled | |
exit_if_failure | |
platform_specific_fixes | |
exit_if_failure | |
mysql__install_with_root_passwd ${DB_ROOT_PW} | |
exit_if_failure "Couldn't install MySQL" | |
mysql__create_db ${DB_NAME} ${DB_ROOT_PW} | |
exit_if_failure "Couldn't create MySQL database ${DB_NAME}" | |
install_packages nginx | |
&& nginx__configure ${NGINX_CONFIG} | |
if ! is_var_empty ${OPTIONAL_PACKAGES}; then | |
install_packages ${OPTIONAL_PACKAGES} | |
warn_if_failure \ | |
"Could not install all optional packages: " \ | |
"${OPTIONAL_PACKAGES}" | |
fi | |
echo Dev server setup finished |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment