Permalink
Browse files

Added support for variables which depend on each other to make intera…

…ctive configuration easier with 'conf_set foo bar' instead of 'foo=bar'
  • Loading branch information...
1 parent f59569a commit 2ebd3b261415599af8c113583342fc7d654240a9 @jpic committed Oct 20, 2009
Showing with 42 additions and 11 deletions.
  1. +3 −3 conf/functions.sh
  2. +20 −0 conf/module.sh
  3. +17 −0 vps/conf.sh
  4. +2 −8 vps/source.sh
View
@@ -82,7 +82,7 @@ function conf_load_from_path() {
# Prompt the user for variable value update, given a variable name list.
# Note that this method does not save the new values.
-# @param List of variable names, separated by space
+# @param List of variable names, separated by space
function conf_interactive_variables() {
local conf_variables="$*"
local conf_value=""
@@ -93,10 +93,10 @@ function conf_interactive_variables() {
read -p "\$$variable [$conf_value]: " input
if [[ -n $input ]]; then
- printf -v $variable $input
- mlog info "Changed $variable to $input"
+ conf_set "$variable" "$input"
fi
done
mlog debug "Configured ${conf_variables[@]}"
}
+
View
@@ -171,3 +171,23 @@ function conf_get_path() {
echo ${!conf_path}
}
+
+# Sets a given variable to a given value politely.
+# Example:
+## conf_set foo bar
+## # if foo_set() is declared then foo_set("bar") is called
+## # else $foo will be set to $bar
+# @param Variable name
+# @param Value
+# @polite Tries to call yourvariable_set()
+function conf_set() {
+ local module_overload="${1}_set"
+ if [[ $(declare -f $module_overload) ]]; then
+ if [[ ! ${FUNCNAME[*]} =~ $module_overload ]]; then
+ $module_overload "$2"
+ return $?
+ fi
+ fi
+
+ printf -v "$1" "$2"
+}
View
@@ -68,3 +68,20 @@ function vps_conf_interactive() {
vps_conf_interactive_network
fi
}
+
+function vps_master_set() {
+ vps_master="$1"
+ vps_packages_dir="$VPS_DIR/$vps_master/pkgdir"
+}
+
+function vps_name_set() {
+ vps_name="$1"
+ vps_root=${VPS_DIR}/${vps_name}
+ vps_conf_path=$(vps_conf_get_path)
+}
+
+function vps_stage_name_set() {
+ vps_stage_name="$1"
+ vps_stage_url="http://bb.xnull.de/projects/gentoo/stages/i686/gentoo-i686-20090611/vserver/${vps_stage_name}";
+ vps_stage_path="/tmp/${vps_stage_name}"
+}
View
@@ -52,13 +52,7 @@ function vps_conf_get_path() {
# @param VPS name
function vps() {
local usage="vps \$vps_name"
- vps_name="$1"
-
- if [[ -z $vps_name ]]; then
- mlog error "Usage: $usage"
- fi
-
- vps_conf_path=$(vps_conf_get_path)
+ conf_set vps_name "$1"
if [[ ! -f $vps_conf_path ]]; then
mlog info $vps_conf_path not found, configuring new vps
@@ -68,7 +62,7 @@ function vps() {
vps_admin=$USER
vps_master="master"
vps_mailer="mail"
- vps_packages_dir="${VPS_DIR}/${vps_master}/usr/portage/packages"
+ vps_packages_dir="${VPS_DIR}/${vps_master}/pkgdir"
vps_stage_name="gentoo-vserver-i686-20090611.tar.bz2"
vps_stage_url="http://bb.xnull.de/projects/gentoo/stages/i686/gentoo-i686-20090611/vserver/${vps_stage_name}";
vps_stage_path="/tmp/${vps_stage_name}"

0 comments on commit 2ebd3b2

Please sign in to comment.