swapped where chown is done
[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 export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )"
25
26 source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh"
27
28 ############################
29
30 function print_instructions()
31 {
32   echo
33   echo "$(basename $0 .sh) [app dirname] [repository] [theme name] "
34 #[user name]
35   echo
36   echo "All parameters are optional, and intelligent guesses for them will be made."
37   echo
38   echo "app dirname: The folder where the app will be stored."
39   echo "repository: The name of the git repository (short version, no URL)."
40   echo "theme name: The name to use for the cakephp theme."
41   echo
42   exit 0
43 }
44
45 ############################
46
47 # main body of script.
48
49 # check for parameters.
50 app_dirname="$1"; shift
51 repo_name="$1"; shift
52 theme_name="$1"; shift
53
54 if [ "$app_dirname" == "-help" -o "$app_dirname" == "--help" ]; then
55   print_instructions
56 fi
57
58 source "$WORKDIR/shared_site_mgr.sh"
59
60 sep
61
62 check_application_dir "$BASE_APPLICATION_PATH"
63
64 # find proper webroot where the site will be initialized.
65 if [ -z "$app_dirname" ]; then
66   # no dir was passed, so guess it.
67   find_app_folder "$BASE_APPLICATION_PATH"
68 else
69   test_app_folder "$BASE_APPLICATION_PATH" "$app_dirname"
70 fi
71
72 # where we expect to find our checkout folder underneath.
73 full_app_dir="$BASE_APPLICATION_PATH/$app_dirname"
74
75 # use our default values for the repository and theme if they're not provided.
76 if [ -z "$repo_name" ]; then
77   repo_name="$app_dirname"
78 fi
79 if [ -z "$theme_name" ]; then
80   theme_name="$(capitalize_first_char ${app_dirname})"
81 fi
82
83 echo "Repository: $repo_name"
84 echo "Theme name: $theme_name"
85 sep
86
87 echo in powerup before update repo with:
88 var CHECKOUT_DIR_NAME DEFAULT_REPOSITORY_ROOT
89
90 # this should set the site_store_path variable if everything goes well.
91 update_repo "$full_app_dir" "$CHECKOUT_DIR_NAME" "$DEFAULT_REPOSITORY_ROOT" "$repo_name"
92 test_or_die "Updating the repository storage directory"
93
94 # update the site to load dependencies.
95 sep
96 composer_repuff "$site_store_path"
97 test_or_die "Installing site dependencies with composer"
98
99 # set up the symbolic links needed to achieve siteliness.
100 sep
101
102 create_site_links "$site_store_path" "$theme_name"
103
104 sep
105
106 echo "Finished powering up the site in '${app_dirname}'."
107