summaryrefslogblamecommitdiffstats
path: root/builder/dnbd3-rootfs/hooks/fetch-config.sh
blob: 354bbcc6ffa5259a48d33ef7f1699d111989880f (plain) (tree)
1
2
3
4
5
6
7
8
9
                   
                       




                                                        

                   
                                 

                                
 



                                                                





                                          
       


                                                                                       

                                        

             

                 



                                                                                                                                                                                                  
  
 
                          
                     
                    

                                                     
           
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# region imports
type getarg >/dev/null 2>&1 || source /lib/dracut-lib.sh
source "/usr/lib/rebash/core.sh"
core.import exceptions
exceptions.activate
core.import logging
# endregion
( # subshell for variable scoping
logging.set_commands_level debug
logging.set_level debug

configuration_file_name="$(getargs slx_configuration_filename=)"
if [ -z "$configuration_file_name" ]; then
    configuration_file_name='config'
fi

slx_server="$(getargs slxsrv=)"
slx_server_base="$(getargs slxbase=)"

logging.info 'Getting configuration file.'
IFS_backup="$IFS"
IFS=','
for host in ${slx_server}; do
    logging.info "Trying host \"$host\"."
    if wget --timeout 5 "http://${host}/${slx_server_base}${configuration_file_name}" \
        --output-document '/etc/openslx'
    then
        break
    fi
done
IFS="$IFS_backup"

if [[ ! -e "/etc/openslx" ]]; then
    logging.warn "Downloading OpenSLX configuration file from any of the servers \"${slx_server}\" at location \"${slx_server_base}${configuration_file_name}\" failed. Return code: $return_code"
    exit 1
fi

); [[ $? == 1 ]] && exit 1
exceptions.deactivate
# region vim modline
# vim: set tabstop=4 shiftwidth=4 expandtab:
# vim: foldmethod=marker foldmarker=region,endregion:
# endregion