-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·65 lines (55 loc) · 2.89 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
# get directory where this script lives
source_dir="$( cd "$( [[ -h "${BASH_SOURCE[0]}" ]] && dirname "$(readlink "${BASH_SOURCE[0]}")" || dirname "${BASH_SOURCE[0]}" )" && pwd )"
# source common functions
source "${source_dir}/.functions.sh"
# source common defaults
source "${source_dir}/.defaults.sh"
# set the config file name
config_file="init.config"
# declare some arrays
declare -A action_execs error_is_fatal variables
# define actions that can be taken
# note that these must be in order from first to last
actions=()
# action_name action_execs error_is_fatal
define_action "prereq" "check_prereqs" "true"
define_action "minver" "check_minimum_version" "true"
define_action "precmd" "run_command" "true"
define_action "backup" "back_up_files" "false"
define_action "submodule" "git submodule update --init --remote --force --" "false"
define_action "download" "download" "false"
define_action "directory" "mkdir -p" "false"
define_action "link" "create_links" "false"
define_action "postcmd" "run_command" "false"
# define variables that can be used
variables["base_dir"]="${PWD}"
variables["home_dir"]="${HOME}"
variables["xdg_config_home"]="${XDG_CONFIG_HOME:-"${default[XDG_CONFIG_HOME]}"}"
variables["xdg_data_home"]="${XDG_DATA_HOME:-"${default[XDG_DATA_HOME]}"}"
variables["xdg_cache_home"]="${XDG_CACHE_HOME:-"${default[XDG_CACHE_HOME]}"}"
variables["config_dir"]=""
# run through the list of configs
for config_subdir in $@; do
# check to make sure the config exists, is readable, and isn't empty
if [[ -d "${config_subdir}" && -r "${config_subdir}/${config_file}" && -s "${config_subdir}/${config_file}" ]]; then
echo "configuring ${config_subdir}..."
# make sure that the correct config subdir is being used
variables[config_dir]="${PWD}/${config_subdir}"
# run through all the actions
for action in ${actions[@]}; do
# get the options for the current action
options="$(parse_config_action ${config_subdir}/${config_file} ${action} $(tuplify_variables))"
# only execute the action if there are options
if [[ -n "$options" ]]; then
echo " action: ${action}"
echo " └ executing: ${action_execs[${action}]} ${options}"
${action_execs[${action}]} ${options}
if [[ $? -ne 0 && ${error_is_fatal[${action}]} == 'true' ]]; then
echo " └ error: fatal"
break
fi
fi
done
fi
done