#!/bin/bash # Setup main configuration and load preferences function hydra_config_load { local folder="`dirname $CONFIG`" if [ -f "$folder" ]; then echo "Converting legacy configuration scheme..." mv $folder $folder.tmp mkdir -p $folder mv $folder.tmp $CONFIG fi if [ ! -e "$CONFIG" ]; then echo "Creating $CONFIG..." mkdir `dirname $CONFIG` touch $CONFIG chmod 600 $CONFIG echo "# Hydra config file." > $CONFIG echo "" >> $CONFIG fi hydra_config_load_preferences } # Load config preferences function hydra_config_load_preferences { # Load custom preferences if [ ! -z "$PREFERENCES" ] && [ -f "$PREFERENCES" ]; then source $PREFERENCES fi hydra_check_preferences } # Check preferences function hydra_check_preferences { # Check for parameters that should not be set in preferences anymore if [ ! -z "$PUPPET" ]; then echo "Using deprecated config PUPPET, please update $PREFERENCES." fi if [ ! -z "$REMOTE_REPOS" ]; then echo "Using deprecated config REMOTE_REPOS, please update $PREFERENCES." fi if [ ! -z "$PRIVATE_REPOS" ]; then echo "Using deprecated config PRIVATE_REPOS, please update $PREFERENCES." fi # Set basic variables PUPPET="$HYDRA_FOLDER/puppet" PUPPET_KEYS="$PUPPET/keys" export HYDRA_CONNECT="ssh -T -q -o ConnectTimeout=15" } # Load a parameter from config function hydra_config { if [ -z "$CONFIG" ]; then echo "Your have to set CONFIG variable in the code" exit 1 elif [ -e "$CONFIG" ]; then grep -e "^$1=" $CONFIG | tail -n 1 | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | sed -e 's/ *#.*$//' else echo "Config file not found: $CONFIG" exit 1 fi } # Configure puppet-boostrap. function hydra_bootstrap_config { local config="$1" if [ -z "$config" ] || [ ! -d "$config" ]; then return fi ( cd $config make deps make submodules make config ) } # Get a configuration parameter if not previously defined by a sourced file function hydra_user_config { local param="$1" local default="$2" shift 2 if [ -z "`eval echo '$'$param`" ]; then hydra_user_input $param $default $* fi }