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