Last active
August 29, 2015 14:07
-
-
Save mgleeson/a9e449a15d35691998a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
###### | |
# get_moodle_config.sh | |
# @author: Matt Gleeson <matt@mattgleeson.net> | |
# @version: 0.01 | |
# @lastmodified: 04/02/2015 - not finished yet | |
# @license: GPL2 | |
###### | |
set -o nounset | |
set -o errexit | |
exit # remove this when complete - safety catch to prevent possible inadvertent abuse of your pets, loved ones, and general catastrophe | |
# Allow only root execution | |
if [ `id|sed -e s/uid=//g -e s/\(.*//g` -ne 0 ]; then | |
echo "This script requires root privileges" | |
exit 1 | |
fi | |
# todo: check for exist of mdl_conf? create and ensure root readable only? then include into this file, delete at end? | |
# or dump output of command into this file? Decisions... | |
# todo: do a getops thing to grab input for location of moodle install - use getops if more than one input neeted? or just use $1 $2? Decisions... | |
pathToMoodleConfig="${1}" # WHEREISMYMOODLEAT? | |
#todo: check for $1 empty | |
grep -P -o '(?<=^\$CFG->)(\w*)\s*=\s?(?:\x27)(\w*)(?:\x27)(?=\;)' ${pathToMoodleConfig}/config.php | sed 's/\s//g' | sed 's/\x27/"/g' >> ~/mdl_conf.sh | |
#^ if using dump to a file for this and not dumping to tmp or root home or something, make sure to have script check for where it is so that is not in insecure location + chmod it to 700, owned by root of course | |
# the mdl_conf.sh resulting from above can be imported into other scripts to do stuff with the moodle database, eg. backups etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment