better noise at runtime
[feisty_meow.git] / scripts / system / moodle_updater.sh
1 #!/bin/bash
2
3 # updates the moodle install, assuming all paths are at the default.
4
5 source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
6
7 ####
8 # some constants that we know are not really.
9 moodle_parent=/var/www/html
10   # parent directory is one level up from where moodle lives.
11 moodle_dir=moodle
12   # this variable is just the directory name for moodle itself, not a path.
13 moodle_release=moodle-3.9
14   # the name of the release we're expecting to download and install
15 download_url="https://download.moodle.org/download.php/direct/stable39/${moodle_release}.tgz"
16   # where we can get the latest version of moodle for our chosen releases.
17   # this URL could change over time, but it's the best link i could find for now.
18 ####
19
20 # everything below should be version invariant.
21
22 moodle_path="$moodle_parent/$moodle_dir"
23   # composing the parent plus directory name should get us to moodle.
24
25 if [ ! -d "$moodle_path" ]; then
26   echo "There was no moodle installation found at: $moodle_path"
27   exit 1
28 fi
29
30 # where we unpack our temporary stuff.
31 temp_install="$(mktemp -d /tmp/update_moodle.XXXXXX)"
32 echo "Using temporary directory for installation: $temp_install"
33 if [ ! -d "$temp_install" ]; then
34   echo The temporary installation directory at: $temp_install could not be created.
35   exit 1
36 fi
37
38 # quit the running moodle instance.
39 echo "Stopping Apache httpd before moodle update."
40 systemctl stop httpd
41 exit_on_error stopping httpd process before moodle upgrade.
42
43 # jump into our new work area.
44 pushd "$temp_install"
45
46 # get the latest moodle version.
47 echo "Downloading latest version of '$moodle_release' now."
48 wget "$download_url"
49 exit_on_error downloading latest version of moodle.
50
51 # use the feisty meow unpack script to extract the moodle data.
52 echo "Installing the latest $moodle_release now."
53 unpack "${moodle_release}.tgz"
54 exit_on_error unpacking latest version of moodle.
55
56 # rename the old moodle directory to a unique name in the same area.
57 old_moodle_path="$moodle_parent/moodle-$(basename $temp_install)"
58 mv "$moodle_parent/$moodle_dir" "$old_moodle_path"
59 exit_on_error renaming old version of moodle.
60
61 # move the new stuff into place.
62 mv "arch_${moodle_release}/${moodle_dir}" "$moodle_parent"/ &>/dev/null
63 exit_on_error moving new version of moodle into place.
64
65 # grab our important configuration files and put them back in the new directory.
66 cp "$old_moodle_path/config.php" "$moodle_path"
67 exit_on_error copying existing moodle configuration file: config.php
68
69 # legalesey warnings about what we didn't do...
70 echo -e "\
71 ====
72 NOTE: This script does not copy any plugins or themes.  If you are using\n\
73 updated or specialized additions to moodle, please copy them from here:\n\
74   $old_moodle_path\n\
75 into the new install at:\n\
76   $moodle_path\n\
77 ====\n\
78 "
79
80 # restart the running moodle instance.
81 echo "Starting Apache httpd after moodle update."
82 systemctl start httpd
83 exit_on_error starting httpd process after moodle upgrade.
84
85 # back out of our directory and clean up the temporary junk, if any.
86 popd
87 rm -rf "$temp_install"
88
89 # sunshine and roses!  we are through the gauntlet.
90