using THISDIR instead of WORKDIR
[feisty_meow.git] / scripts / site_avenger / teardown.sh
1 #!/bin/bash
2
3 # this performs the inverse operation of standup, by relying on the
4 # remove_domain and remove_apache_site scripts.
5 #
6 # Author: Chris Koeritz
7
8 export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )"  # obtain the script's working directory.
9 export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )"
10
11 source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh"
12
13 ############################
14
15 function print_instructions()
16 {
17   echo
18   echo "$(basename $0 .sh) {app name}"
19   echo
20   echo "
21 $(basename $0 .sh) will drop a web site out of apache server and out of the
22 DNS server, as if it never existed.  The site storage is left untouched; we
23 don't know what valuable assets lurk there.
24 This script must be run as sudo or root; it makes changes to system files.
25 "
26   exit 0
27 }
28
29 ############################
30
31 # main body of script.
32
33 # check for parameters.
34 app_dirname="$1"; shift
35
36 if [ "$app_dirname" == "-help" -o "$app_dirname" == "--help" ]; then
37   print_instructions
38 elif [ -z "$app_dirname" ]; then
39   print_instructions
40 fi
41
42 # force the sudo at the start of the script, rather than waiting halfway
43 # through to ask for access.
44 sudo bash -c 'echo sudo permissions acquired.'
45
46 source "$THISDIR/shared_site_mgr.sh"
47
48 sep
49
50 check_apps_root "$BASE_APPLICATION_PATH"
51
52 # find proper webroot where the site will be initialized.
53 if [ -z "$app_dirname" ]; then
54   # no dir was passed, so guess it.
55   find_app_folder "$BASE_APPLICATION_PATH"
56 else
57   test_app_folder "$BASE_APPLICATION_PATH" "$app_dirname"
58 fi
59 test_or_die "finding and testing app folder"
60
61 sep
62
63 sudo bash "$FEISTY_MEOW_SCRIPTS/system/remove_apache_site.sh" "$DOMAIN_NAME"
64 test_or_die "dropping apache site for: $DOMAIN_NAME"
65
66 # drop the shadow site too.
67 shadow_domain="${APPLICATION_NAME}.cakelampvm.com"
68 if [ "$shadow_domain" != "$DOMAIN_NAME" ]; then
69   sudo bash "$FEISTY_MEOW_SCRIPTS/system/remove_apache_site.sh" "$shadow_domain"
70   test_or_die "dropping shadow apache site on '$shadow_domain'"
71 fi
72
73 sep
74
75 #echo "!! domain being removed is: $DOMAIN_NAME"
76
77 sudo bash "$FEISTY_MEOW_SCRIPTS/system/remove_domain.sh" "$DOMAIN_NAME"
78 test_or_die "dropping domain: $DOMAIN_NAME"
79
80 sep
81
82 echo "
83 Finished tearing down the domain name and apache site for:
84   $DOMAIN_NAME
85 "
86