[op5-users] [PATCH] Added an install script and made changes to the install
Tom Hudson
tom.hudson at isotoma.com
Mon Oct 12 12:44:48 CEST 2009
This should make user install easier without making batch installs not
work (you'll have to add a couple of switches to the batch install
command-line).
Cheers,
Tom Hudson
isotoma
- Added install_ninja.sh script to make installation that bit easier
- Added command line options to ninja_db_init.sh for db user, db pass, db name
- Added more descriptive error in case htpasswd-import cannot be found
- If no db user or pass is specified on the command line, will query user
Signed-off-by: Tom Hudson <tom.hudson at isotoma.com>
---
application/config/config.php | 2 +-
install_scripts/auth_import_mysql.php | 13 ++--
install_scripts/install_ninja.sh | 147 +++++++++++++++++++++++++++++++++
install_scripts/ninja_db_init.sh | 67 ++++++++++++++--
4 files changed, 216 insertions(+), 13 deletions(-)
create mode 100644 install_scripts/install_ninja.sh
diff --git a/application/config/config.php b/application/config/config.php
index 6a03116..a218e53 100644
--- a/application/config/config.php
+++ b/application/config/config.php
@@ -217,4 +217,4 @@ $config['cli_access'] = true;
/**
* Nr of items returned for searches
*/
-$config['search_limit'] = 10;
\ No newline at end of file
+$config['search_limit'] = 10;
diff --git a/install_scripts/auth_import_mysql.php b/install_scripts/auth_import_mysql.php
index 706da31..7040991 100644
--- a/install_scripts/auth_import_mysql.php
+++ b/install_scripts/auth_import_mysql.php
@@ -249,6 +249,7 @@ class ninja_auth_import
# first import new users from cgi.cfg if there is any
$path = realpath($this->prefix."/cli-helpers/htpasswd-import.php");
if (!file_exists($path)) {
+ print "$path does not exist, you must pass the location of the ninja directory as the first argument to this script\n";
die("Unable to find htpasswd-import class so this script will now terminate\n");
exit(1);
}
diff --git a/install_scripts/install_ninja.sh b/install_scripts/install_ninja.sh
new file mode 100644
index 0000000..f139a68
--- /dev/null
+++ b/install_scripts/install_ninja.sh
@@ -0,0 +1,147 @@
+#!/bin/sh
+
+src_dir=$(dirname $0)
+pushd "$src_dir" >/dev/null 2>&1
+src_dir=$(pwd)
+popd >/dev/null 2>&1
+
+dest_dir=/opt/monitor/op5/ninja
+root_path=
+batch=
+install=db,files
+
+abort ()
+{
+ echo "$@"
+ echo "Aborting."
+ exit 1
+}
+
+get_arg ()
+{
+ expr "z$1" : 'z[^=]*=\(.*\)'
+}
+
+ask ()
+{
+ local question options answer
+ question="$1" options="$2" default="$3"
+ test "$batch" = "y" && { echo "$default"; return 0; }
+
+ while true; do
+ echo -n "$question " >&2
+ read answer
+ case "$answer,$default" in
+ "",*)
+ answer="$default"
+ break
+ ;;
+ ",") ;;
+ *)
+ echo "$options " | grep -q "$answer" && break
+ ;;
+ esac
+ echo "Please answer one of '$options'" >&2
+ done
+ echo "$answer" >&1
+}
+
+say ()
+{
+ test "$batch" = "y" || echo "$@"
+}
+
+install_files ()
+{
+ test -d "$root_path/$dest_dir" || mkdir -p "$root_path/$dest_dir"
+ cp -Rp "$src_dir"/* "$root_path/$dest_dir/"
+}
+
+while test "$1"; do
+ case "$1" in
+ --batch)
+ batch="y"
+ ;;
+ --dest-dir=*)
+ dest_dir=$(get_arg "$1")
+ ;;
+ --dest-dir)
+ shift
+ dest_dir="$1"
+ ;;
+ --install=*)
+ install=$(get_arg "$1")
+ ;;
+ --install)
+ shift
+ install="$1"
+ ;;
+ --root=*)
+ root_path=$(get_arg "$1")
+ ;;
+ --root)
+ shift
+ root_path="$1"
+ ;;
+ *)
+ echo "Illegal argument. I have no idea what to make of '$1'"
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+if [ "$db_pass" = "generate" ]; then
+ db_pass=$(dd if=/dev/random bs=32 count=1 | sha1sum | sed -n '$s/\([0-9a-f]*\).*/\1/p')
+fi
+
+for c in $(echo "$install" | sed 's/,/ /g'); do
+ case "$c" in
+ files|db) ;;
+ *)
+ echo "I don't know how to install component $c"
+ echo "You may only pass one or more of 'db,files' to --install"
+ echo "and you must pass one of them if you use --install"
+ exit 1
+ ;;
+ esac
+done
+
+cat << EOF
+ Path settings:
+ Destination directory (--dest-dir): $dest_dir
+ Base root (--root): $root_path
+ Batch (--batch): $batch
+
+ Installing the following components: $install
+EOF
+
+case $(ask "Does this look ok? [Y/n]" "ynYN" y) in
+ n|N) echo "Aborting installation"; exit 1;;
+esac
+
+components=
+for i in db files; do
+ echo "$install" | grep -q $i && components="$i"
+done
+if ! test "$components"; then
+ echo "### No components selected to install."
+ echo "### You must pass one or more of 'db' and 'files'"
+ echo "### to the --install argument"
+ exit 1
+fi
+
+say
+say "Installing"
+say
+
+if echo "$install" | grep -q 'files'; then
+ install_files || abort "Failed to install files."
+fi
+if echo "$install" | grep -q 'db'; then
+ $root_path/$dest_dir/install_scripts/ninja_db_init.sh --dest-dir "$dest_dir" || abort "Failed to setup database."
+fi
+
+say
+say "Installation successfully completed"
+say
diff --git a/install_scripts/ninja_db_init.sh b/install_scripts/ninja_db_init.sh
index 4703bd2..e1d91b1 100755
--- a/install_scripts/ninja_db_init.sh
+++ b/install_scripts/ninja_db_init.sh
@@ -1,9 +1,59 @@
#!/bin/sh
+db_user=merlin
+db_pass=merlin
+db_name=merlin
+
+while test "$1"; do
+ case "$1" in
+ --dest-dir=*)
+ dest_dir=$(get_arg "$1")
+ ;;
+ --dest-dir)
+ shift
+ dest_dir="$1"
+ ;;
+ --db-user=*)
+ db_user=$(get_arg "$1")
+ ;;
+ --db-user)
+ shift
+ db_user="$1"
+ ;;
+ --db-pass=*)
+ db_pass=$(get_arg "$1")
+ ;;
+ --db-pass)
+ shift
+ db_pass="$1"
+ ;;
+ --db-name=*)
+ db_name=$(get_arg "$1")
+ ;;
+ --db-name)
+ shift
+ db_name="$1"
+ ;;
+ *)
+ echo "Illegal argument. I have no idea what to make of '$1'"
+ exit 1
+ ;;
+ esac
+ shift
+done
+
# setup the db tables required for Ninja
-db_user=root
-db_pass=
+if test "$db_user" = ""; then
+ echo "Database admin username:"
+ read db_user
+fi
+if test "$db_pass" = ""; then
+ echo "Database admin password:"
+ stty -echo
+ read db_pass
+ stty echo
+fi
if [ $# -ge 1 ]
then
@@ -17,23 +67,28 @@ run_sql_file () # (db_login_opts, sql_script_path)
db_login_opts=$1
sql_script_path=$2
- mysql $db_login_opts merlin < $sql_script_path >/dev/null 2>/dev/null
+ if [ -f "$sql_script_path" ]
+ then
+ mysql $db_login_opts $db_name < $sql_script_path >/dev/null 2>/dev/null
+ else
+ echo "The sql script path does not exist ($sql_script_path)"
+ fi
}
if [ "$db_pass" != "" ]
then
db_login_opts="-u$db_user -p$db_pass"
else
- db_login_opts="-u$db_user"
+ db_login_opts="-u$db_user -p"
fi
-db_ver=$(mysql $db_login_opts -Be "SELECT version FROM ninja_db_version" merlin 2>/dev/null | sed -n \$p)
+db_ver=$(mysql $db_login_opts -Be "SELECT version FROM ninja_db_version" $db_name 2>/dev/null | sed -n \$p)
if [ "$db_ver" = '' ]
then
# nothing found, insert ninja.sql
echo "Installing database tables for Ninja GUI"
- run_sql_file $db_login_opts "$prefix/install_scripts/ninja.sql"
+ run_sql_file "$db_login_opts" "$prefix/install_scripts/ninja.sql"
fi
# import users and authorization data
--
1.5.6.3
More information about the op5-users
mailing list