60c277836d3e9be2d2fd2d7a172c384161dd6bf3
[feisty_meow.git] / scripts / site_avenger / powerup.sh
1 #!/bin/bash
2
3 # Author: Kevin Wentworth
4 # Author: Chris Koeritz
5
6 # This script "powers up" a cakephp site by running the database migrations,
7 # cleaning out the ORM cache, and fixing file permissions.
8 # Note that the mysql database must already exist and allow permissions to
9 # the configured username/password in config/app.php.
10 # This script is currently highly specific to site avenger.
11
12 # General Info:
13 #
14 # The naming scheme here is a little complex, but it's basically this...
15 # A git repository is expected to be provided, and we will get all the code
16 # for the web site from there.  The repository is expected to have a single
17 # application "name" and one or more "themes".  By convention, the name
18 # and the theme are often the same.
19 # For example, let's say our app name is "turtle" and our theme name is "box".
20 # The repo is checked out to a folder called "~/apps/turtle".
21 # This script will want to use "turtle" as the app name.
22 # It will have to be told the theme name, but will assume it's 'Turtle' to
23 # start with.  The concept of the theme comes from cakephp.
24
25 export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )"  # obtain the script's working directory.
26 source "$WORKDIR/shared_site_mgr.sh"
27
28 ############################
29
30 function print_instructions()
31 {
32   echo
33   echo "$(basename $0 .sh) [app dirname] [repository] [theme name]"
34   echo
35   echo "All parameters are optional, and intelligent guesses for them will be made."
36   echo
37   echo "app dirname: The folder where the app will be stored."
38   echo "repository: The name of the git repository (short version, no URL)."
39   echo "theme name: The name to use for the cakephp theme."
40   echo
41   exit 0
42 }
43
44 ############################
45
46 # main body of script.
47
48 # check for parameters.
49 app_dirname="$1"; shift
50 repo_name="$1"; shift
51 theme_name="$1"; shift
52
53 if [ "$app_dirname" == "-help" -o "$app_dirname" == "--help" ]; then
54   print_instructions
55 fi
56
57 sep
58
59 check_application_dir "$APPLICATION_DIR"
60
61 # find proper webroot where the site will be initialized.
62 if [ -z "$app_dirname" ]; then
63   # no dir was passed, so guess it.
64   find_app_folder "$APPLICATION_DIR"
65 else
66   test_app_folder "$APPLICATION_DIR" "$app_dirname"
67 fi
68
69 # where we expect to find our checkout folder underneath.
70 full_app_dir="$APPLICATION_DIR/$app_dirname"
71
72 # use our default values for the repository and theme if they're not provided.
73 if [ -z "$repo_name" ]; then
74   repo_name="$app_dirname"
75 fi
76 if [ -z "$theme_name" ]; then
77   theme_name="$(capitalize_first_char ${app_dirname})"
78 fi
79
80 echo "Repository: $repo_name"
81 echo "Theme name: $theme_name"
82 sep
83
84 # this should set the site_store_path variable if everything goes well.
85 update_repo "$full_app_dir" "$CHECKOUT_DIR_NAME" "$DEFAULT_REPOSITORY_ROOT" "$repo_name"
86 test_or_die "Updating the repository storage directory"
87
88 # update the site to load dependencies.
89 sep
90 composer_repuff "$site_store_path"
91 test_or_die "Installing site dependencies with composer"
92
93 # set up the symbolic links needed to achieve siteliness.
94 sep
95
96 create_site_links "$site_store_path" "$theme_name"
97
98 sep
99
100 echo "Finished powering up the site in '${app_dirname}'."
101