diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/helpers/function_helpers | 67 | ||||
-rw-r--r-- | script/helpers/text_helpers | 32 | ||||
-rwxr-xr-x | script/setup | 45 | ||||
-rwxr-xr-x | script/system_check | 37 |
4 files changed, 181 insertions, 0 deletions
diff --git a/script/helpers/function_helpers b/script/helpers/function_helpers new file mode 100644 index 0000000..388fa67 --- /dev/null +++ b/script/helpers/function_helpers @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +# This file contains a set of functions used as helpers +# for various tasks. Read the examples for each one for +# more information. Feel free to put any additional helper +# functions you may need for your app + + +# Returns true if the command $1 is not found +# example: +# if command_not_found "yarn"; then +# echo "no yarn" +# fi +command_not_found() { + ! command -v $1 > /dev/null + return $? +} + +# Returns true if the command $1 is not running +# You must supply the full command to check as an argument +# example: +# if command_not_running "redis-cli ping"; then +# print_error "Redis is not running" +# fi +command_not_running() { + $1 + if [ $? -ne 0 ]; then + true + else + false + fi +} + +# Returns true if the OS is macOS +# example: +# if is_mac; then +# echo "do mac stuff" +# fi +is_mac() { + if [[ "$OSTYPE" == "darwin"* ]]; then + true + else + false + fi +} + +# Returns true if the OS is linux based +# example: +# if is_linux; then +# echo "do linux stuff" +# fi +is_linux() { + if [[ "$OSTYPE" == "linux"* ]]; then + true + else + false + fi +} + +# Prints error and exit. +# example: +# print_error "Redis is not running. Run it with some_command" +print_error() { + printf "${BOLD_RED_COLOR}There is a problem with your system setup:\n\n" + printf "${BOLD_RED_COLOR}$1 \n\n" | indent + exit 1 +} diff --git a/script/helpers/text_helpers b/script/helpers/text_helpers new file mode 100644 index 0000000..34b77a8 --- /dev/null +++ b/script/helpers/text_helpers @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# This file contains a set of functions used to format text, +# and make printing text a little easier. Feel free to put +# any additional functions you need for formatting your shell +# output text. + +# Colors +BOLD_RED_COLOR="\e[1m\e[31m" + +# Indents the text 2 spaces +# example: +# printf "Hello" | indent +indent() { + while read LINE; do + echo " $LINE" || true + done +} + +# Prints out an arrow to your custom notice +# example: +# notice "Installing new magic" +notice() { + printf "\n▸ $1\n" +} + +# Prints out a check mark and Done. +# example: +# print_done +print_done() { + printf "✔ Done\n" | indent +} diff --git a/script/setup b/script/setup new file mode 100755 index 0000000..bf0bc31 --- /dev/null +++ b/script/setup @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Exit if any subcommand fails +set -e +set -o pipefail + +source script/helpers/text_helpers + + +notice "Running System Check" +./script/system_check +print_done + +notice "Installing node dependencies" +yarn install --no-progress | indent + +notice "Compiling assets" +yarn dev | indent + +print_done + +notice "Installing shards" +shards install --ignore-crystal-version | indent + +if [ ! -f ".env" ]; then + notice "No .env found. Creating one." + touch .env + print_done +fi + +notice "Creating the database" +lucky db.create | indent + +notice "Verifying postgres connection" +lucky db.verify_connection | indent + +notice "Migrating the database" +lucky db.migrate | indent + +notice "Seeding the database with required and sample records" +lucky db.seed.required_data | indent +lucky db.seed.sample_data | indent + +print_done +notice "Run 'lucky dev' to start the app" diff --git a/script/system_check b/script/system_check new file mode 100755 index 0000000..c27c926 --- /dev/null +++ b/script/system_check @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +source script/helpers/text_helpers +source script/helpers/function_helpers + +# Use this script to check the system for required tools and process that your app needs. +# A few helper functions are provided to make writing bash a little easier. See the +# script/helpers/function_helpers file for more examples. +# +# A few examples you might use here: +# * 'lucky db.verify_connection' to test postgres can be connected +# * Checking that elasticsearch, redis, or postgres is installed and/or booted +# * Note: Booting additional processes for things like mail, background jobs, etc... +# should go in your Procfile.dev. + +if command_not_found "yarn"; then + print_error "Yarn is not installed\n See https://yarnpkg.com/lang/en/docs/install/ for install instructions." +fi + +if command_not_found "createdb"; then + MSG="Please install the postgres CLI tools, then try again." + if is_mac; then + MSG="$MSG\nIf you're using Postgres.app, see https://postgresapp.com/documentation/cli-tools.html." + fi + MSG="$MSG\nSee https://www.postgresql.org/docs/current/tutorial-install.html for install instructions." + + print_error "$MSG" +fi + + +## CUSTOM PRE-BOOT CHECKS ## +# example: +# if command_not_running "redis-cli ping"; then +# print_error "Redis is not running." +# fi + + |