made to be sourced only once
This commit is contained in:
		
							
								
								
									
										122
									
								
								read_config
									
									
									
									
									
								
							
							
						
						
									
										122
									
								
								read_config
									
									
									
									
									
								
							@@ -1,69 +1,73 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
# set -x
 | 
			
		||||
 | 
			
		||||
#if [ ${read_config_sourced:-1} = "1" ]; then
 | 
			
		||||
#    readonly read_config_sourced=${BASH_SOURCE[0]}
 | 
			
		||||
#else
 | 
			
		||||
#    return 0
 | 
			
		||||
#fi
 | 
			
		||||
source ./log_helpers
 | 
			
		||||
 | 
			
		||||
# source ./log_helpers
 | 
			
		||||
if [ ${read_config_sourced:-1} = "1" ]; then    # include only once
 | 
			
		||||
    readonly read_config_sourced=${BASH_SOURCE[0]}
 | 
			
		||||
 | 
			
		||||
# read config file (JSON syntax)
 | 
			
		||||
#
 | 
			
		||||
read_config() {
 | 
			
		||||
    local func="${FUNCNAME[0]}"
 | 
			
		||||
    # read config file (JSON syntax)
 | 
			
		||||
    #
 | 
			
		||||
    read_config() {
 | 
			
		||||
        local func="${FUNCNAME[0]}"
 | 
			
		||||
 | 
			
		||||
    # check customer_id
 | 
			
		||||
    __customer_id="$(cat "$1" | jq -r .customer_id)"
 | 
			
		||||
    if [ -z "$__customer_id" ]; then 
 | 
			
		||||
        log_fatal "$func:${LINENO} customer_id not set in $1"
 | 
			
		||||
    fi
 | 
			
		||||
    readonly customer_id="customer_${__customer_id}"
 | 
			
		||||
    log_info "$func:${LINENO}: customer-id is $customer_id"
 | 
			
		||||
    
 | 
			
		||||
    # check customer_repository
 | 
			
		||||
    __repository_path="$(cat "$1" | jq -r .repository_path)"
 | 
			
		||||
    if [ -z "$__repository_path" ]; then 
 | 
			
		||||
        log_fatal "$func:${LINENO}: repository path not set in $1"
 | 
			
		||||
    fi
 | 
			
		||||
    readonly repository_path="${__repository_path}/${customer_id}.git"
 | 
			
		||||
    log_info "$func:${LINENO}: repository path is $repository_path"
 | 
			
		||||
    
 | 
			
		||||
    # check zone_group
 | 
			
		||||
    local zone_group="$(cat "$1" | jq -r .zone_group)"
 | 
			
		||||
    if [ -z "$zone_group" ]; then 
 | 
			
		||||
        log_fatal "$func:${LINENO}: zone_group not set in $1"
 | 
			
		||||
    fi
 | 
			
		||||
    
 | 
			
		||||
    # check zone
 | 
			
		||||
    local zone="$(cat "$1" | jq -r .zone)"
 | 
			
		||||
    if [ -z "$zone" ]; then 
 | 
			
		||||
        log_fatal "$func:${LINENO}: zone not set in $1"
 | 
			
		||||
    fi
 | 
			
		||||
    
 | 
			
		||||
    # check customer_location
 | 
			
		||||
    local customer_location="$(cat "$1" | jq -r .customer_location)"
 | 
			
		||||
    if [ -z "$customer_location" ]; then 
 | 
			
		||||
        log_fatal "$func:${LINENO}: customer_location not set in $1"
 | 
			
		||||
    fi
 | 
			
		||||
    
 | 
			
		||||
    readonly working_directory="$(cat "$1" | jq -r .working_directory)"
 | 
			
		||||
    log_info "$func:${LINENO}: working_directory is $working_directory"
 | 
			
		||||
    
 | 
			
		||||
    readonly workspace_dir="$(cat "$1" | jq -r .workspace_dir)"
 | 
			
		||||
    local __customer_base_dir="$working_directory/${workspace_dir}"
 | 
			
		||||
    __customer_base_dir="${__customer_base_dir}/${customer_id}"
 | 
			
		||||
    __customer_base_dir="${__customer_base_dir}/${customer_location}"
 | 
			
		||||
    
 | 
			
		||||
    readonly customer_base_dir="${__customer_base_dir}/${zone_group}/${zone}"
 | 
			
		||||
    log_info "$func:${LINENO}: customer-base-dir is $customer_base_dir"
 | 
			
		||||
        # check customer_id
 | 
			
		||||
        __customer_id="$(cat "$1" | jq -r .customer_id)"
 | 
			
		||||
        if [ -z "$__customer_id" ]; then 
 | 
			
		||||
            log_fatal "$func:${LINENO} customer_id not set in $1"
 | 
			
		||||
        fi
 | 
			
		||||
        readonly customer_id="customer_${__customer_id}"
 | 
			
		||||
        log_info "$func:${LINENO}: customer-id is $customer_id"
 | 
			
		||||
        
 | 
			
		||||
        # check customer_repository
 | 
			
		||||
        __repository_path="$(cat "$1" | jq -r .repository_path)"
 | 
			
		||||
        if [ -z "$__repository_path" ]; then 
 | 
			
		||||
            log_fatal "$func:${LINENO}: repository path not set in $1"
 | 
			
		||||
        fi
 | 
			
		||||
        readonly repository_path="${__repository_path}/${customer_id}.git"
 | 
			
		||||
        log_info "$func:${LINENO}: repository path is $repository_path"
 | 
			
		||||
        
 | 
			
		||||
        # check zone_group
 | 
			
		||||
        local zone_group="$(cat "$1" | jq -r .zone_group)"
 | 
			
		||||
        if [ -z "$zone_group" ]; then 
 | 
			
		||||
            log_fatal "$func:${LINENO}: zone_group not set in $1"
 | 
			
		||||
        fi
 | 
			
		||||
        
 | 
			
		||||
        # check zone
 | 
			
		||||
        local zone="$(cat "$1" | jq -r .zone)"
 | 
			
		||||
        if [ -z "$zone" ]; then 
 | 
			
		||||
            log_fatal "$func:${LINENO}: zone not set in $1"
 | 
			
		||||
        fi
 | 
			
		||||
        
 | 
			
		||||
        # check customer_location
 | 
			
		||||
        local customer_location=$(cat "$1" | jq -r .customer_location)
 | 
			
		||||
        if [ -z "$customer_location" ]; then 
 | 
			
		||||
            log_fatal "$func:${LINENO}: customer_location not set in $1"
 | 
			
		||||
        fi
 | 
			
		||||
        
 | 
			
		||||
        readonly working_directory="$(cat "$1" | jq -r .working_directory)"
 | 
			
		||||
        
 | 
			
		||||
        log_info "$func:${LINENO}: working_directory is $working_directory"
 | 
			
		||||
        
 | 
			
		||||
        readonly workspace_dir="$(cat "$1" | jq -r .workspace_dir)"
 | 
			
		||||
 | 
			
		||||
    readonly opkg_cmds_file="${customer_base_dir}/etc/psa_update/opkg_commands"
 | 
			
		||||
    log_info "$func:${LINENO}: opkg_cmds_file is $opkg_cmds_file"
 | 
			
		||||
        local __customer_base_dir="$working_directory/${workspace_dir}"
 | 
			
		||||
        __customer_base_dir="${__customer_base_dir}/${customer_id}"
 | 
			
		||||
        __customer_base_dir="${__customer_base_dir}/${customer_location}"
 | 
			
		||||
 | 
			
		||||
    return 0
 | 
			
		||||
}
 | 
			
		||||
        readonly customer_location_dir="$__customer_base_dir"
 | 
			
		||||
        
 | 
			
		||||
        log_info "$func:${LINENO}: customer-location-dir is $customer_location_dir"
 | 
			
		||||
        
 | 
			
		||||
        readonly customer_base_dir="${__customer_base_dir}/${zone_group}/${zone}"
 | 
			
		||||
        
 | 
			
		||||
        log_info "$func:${LINENO}: customer-base-dir is $customer_base_dir"
 | 
			
		||||
 | 
			
		||||
# read_config UpdateController.conf
 | 
			
		||||
        readonly opkg_cmds_file="${customer_base_dir}/etc/psa_update/opkg_commands"
 | 
			
		||||
        
 | 
			
		||||
        log_info "$func:${LINENO}: opkg_cmds_file is $opkg_cmds_file"
 | 
			
		||||
        return 0
 | 
			
		||||
    }
 | 
			
		||||
    # read_config UpdateController.conf
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user