68 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/env bash
 | 
						|
 | 
						|
set -e
 | 
						|
 | 
						|
BASE_CONFIG="base"
 | 
						|
CONFIG_SUFFIX=".yaml"
 | 
						|
 | 
						|
META_DIR="meta"
 | 
						|
CONFIG_DIR="configs"
 | 
						|
PROFILES_DIR="profiles"
 | 
						|
 | 
						|
DOTBOT_DIR="dotbot"
 | 
						|
DOTBOT_BIN="bin/dotbot"
 | 
						|
 | 
						|
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 | 
						|
 | 
						|
declare -a CONFIGS
 | 
						|
 | 
						|
parse_configs() {
 | 
						|
    # parses configs in file $1 and returns array of config names
 | 
						|
 | 
						|
    while IFS= read -r config; do
 | 
						|
 | 
						|
        if [[ -z "$config" || "$config" =~ ^# ]] ; then
 | 
						|
            # skip comments and empty lines
 | 
						|
            continue
 | 
						|
        elif [[ "$config" =~ ^profile/ ]] ; then
 | 
						|
            # allows for profile inclusion
 | 
						|
            profile=$(echo "$config" | sed 's/^profile\///')
 | 
						|
            parse_configs "$profile"
 | 
						|
        else
 | 
						|
            CONFIGS+=("$config")
 | 
						|
        fi
 | 
						|
    done < "${META_DIR}/${PROFILES_DIR}/$1"
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
cd "${BASE_DIR}"
 | 
						|
git -C "${BASE_DIR}" submodule sync --quiet --recursive
 | 
						|
git submodule update --init --recursive "${BASE_DIR}"
 | 
						|
 | 
						|
# parse initial profile
 | 
						|
parse_configs "$1"
 | 
						|
 | 
						|
# cleanup at the end
 | 
						|
CONFIGS+=("clean")
 | 
						|
 | 
						|
shift
 | 
						|
 | 
						|
for config in "${CONFIGS[@]}"; do
 | 
						|
    echo -e "\nConfigure $config"
 | 
						|
    # create temporary file
 | 
						|
    configFile="$(mktemp)"
 | 
						|
    suffix="-sudo"
 | 
						|
    echo -e "$(<"${BASE_DIR}/${META_DIR}/${BASE_CONFIG}${CONFIG_SUFFIX}")\n$(<"${BASE_DIR}/${META_DIR}/${CONFIG_DIR}/${config%"$suffix"}${CONFIG_SUFFIX}")" > "$configFile"
 | 
						|
 | 
						|
    cmd=("${BASE_DIR}/${META_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASE_DIR}" -c "$configFile")
 | 
						|
 | 
						|
    if [[ $config == *"sudo"* ]]; then
 | 
						|
        cmd=(sudo "${cmd[@]}")
 | 
						|
    fi
 | 
						|
 | 
						|
    "${cmd[@]}"
 | 
						|
    rm -f "$configFile"
 | 
						|
done
 | 
						|
 | 
						|
cd "${BASE_DIR}"
 |