#!/bin/bash

######
# INFO
######
# you can include code 
# from this file in your script by
# source /path/to/default.profile

##################
# USEFUL VARIABLES
##################

GOLEM_DB=/golem/database

GOLEM_INCLUDES=$GOLEM_DB/velin/includes

GOLEM_DEFAULT_ONN="DAS/0512NIstandard analysis/Basics/0411ShotHomepage"

GOLEM_DEFAULT_ON="devices/SpinanaZasuvkaA"

GOLEM_DEFAULT_OFF="DAS/1011NIbasic DAS/0311NIturbo diagnostics/ParticleFlux/0514MachNumber_RD/ analysis/Preionization/1113MWPreionization devices/SpinanaZasuvkaC devices/LangProbesKombajn DAS/0513NIturbo_RT diagnostics/Radiation/0612HXR"

#AVAILABLE DEVICES: DAS/0311TektronixDPO3014 

##################
# USEFUL FUNCTIONS
##################

# change the state for a given (list of) diagnostic or DAS
# $1=new_state(e.g OFF)
# $@=name as path in includes, without .ONN or .OFF, can be a list of names
change_state() { 
    new_state="$1"
    shift
    for name in "$@" ; do
	new_path="$GOLEM_INCLUDES/$name.$new_state"
	if [ -d "$new_path" ] ; then
	    continue
	fi
	path=$(find $GOLEM_INCLUDES -regextype posix-extended -regex $GOLEM_INCLUDES/$name'\.(ONN|ON|OFF)')
	if ! [ -z "$path" ] ; then
	    echo "Moving $path to $new_path"
	    mv --no-clobber $path $new_path
	fi
    done
}

turn_off() { # args=name(s) without .ON or .OFF
    change_state OFF $@
}

turn_on() { # args=name(s) without .ON or .OFF
    change_state ON $@
}

# for main DAS and homepage with ONN
turn_onn() { # args=name(s) without .ON or .OFF
    change_state ONN $@
}

##############
# SET DEFAULTS
##############

turn_onn $GOLEM_DEFAULT_ONN
turn_on $GOLEM_DEFAULT_ON
turn_off $GOLEM_DEFAULT_OFF
