|
@ -11,61 +11,106 @@ monujo:code_init() { |
|
|
mkdir -p "$LOCATION" |
|
|
mkdir -p "$LOCATION" |
|
|
if dir_is_empty "$LOCATION"; then |
|
|
if dir_is_empty "$LOCATION"; then |
|
|
cd "$LOCATION" |
|
|
cd "$LOCATION" |
|
|
wget -q "$SOURCE_URL" -O file.tar.bz2 |
|
|
|
|
|
tar xjf file.tar.bz2 |
|
|
|
|
|
|
|
|
info "First install, downloading '$SOURCE_URL'." |
|
|
|
|
|
wget -q "$SOURCE_URL" -O file.tar.bz2 || { |
|
|
|
|
|
err "Couldn't download '$SOURCE_URL'." |
|
|
rm file.tar.bz2 |
|
|
rm file.tar.bz2 |
|
|
|
|
|
return 1 |
|
|
|
|
|
} |
|
|
|
|
|
tar xjf file.tar.bz2 && |
|
|
|
|
|
rm file.tar.bz2 && |
|
|
chown root:root "$LOCATION" -R |
|
|
chown root:root "$LOCATION" -R |
|
|
fi |
|
|
fi |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
monujo:code_config_base() { |
|
|
|
|
|
|
|
|
|
|
|
MONUJO_OPTIONS=( |
|
|
|
|
|
|
|
|
export MONUJO_OPTIONS=( |
|
|
lokapi-host:string |
|
|
lokapi-host:string |
|
|
lokapi-db:string |
|
|
lokapi-db:string |
|
|
map-url:string |
|
|
map-url:string |
|
|
local-password-retention-time:string |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
local-password-retention-time:numeric |
|
|
|
|
|
theme:struct\* |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
MONUJO_OPTIONS_CONCAT=" ${MONUJO_OPTIONS[*]} " |
|
|
|
|
|
|
|
|
export MONUJO_OPTIONS_CONCAT=" ${MONUJO_OPTIONS[*]} " |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
monujo:code_config_base() { |
|
|
|
|
|
local service_def |
|
|
service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1 |
|
|
service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1 |
|
|
echo "{}" > "$CONFIGFILE" |
|
|
|
|
|
|
|
|
options=$(e "$service_def" | shyaml get-value -y options) || true |
|
|
|
|
|
|
|
|
|
|
|
e "$options" | |
|
|
|
|
|
monujo:json-make > "$CONFIGFILE" || { |
|
|
|
|
|
err "Failed to make 'config.json'." |
|
|
|
|
|
return 1 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
monujo:json-make() { |
|
|
|
|
|
local conv="$1" key val |
|
|
## XXXvlab: Should probably offer some lib to do this |
|
|
## XXXvlab: Should probably offer some lib to do this |
|
|
|
|
|
local sep= |
|
|
while read-0 key val; do |
|
|
while read-0 key val; do |
|
|
key_option=${key//-/_} |
|
|
|
|
|
|
|
|
key=$(e "$key" | shyaml get-value) |
|
|
|
|
|
ytype=$(e "$val" | shyaml get-type) |
|
|
case "$MONUJO_OPTIONS_CONCAT" in |
|
|
case "$MONUJO_OPTIONS_CONCAT" in |
|
|
*" ${key_option}:bool "*) |
|
|
|
|
|
|
|
|
*" ${key}:bool "*) |
|
|
|
|
|
val=$(e "$val" | shyaml get-value) |
|
|
case "${val,,}" in |
|
|
case "${val,,}" in |
|
|
true|ok|yes|y) |
|
|
true|ok|yes|y) |
|
|
val=yes |
|
|
|
|
|
|
|
|
val=true |
|
|
;; |
|
|
;; |
|
|
false|ko|nok|no|n) |
|
|
false|ko|nok|no|n) |
|
|
val=no |
|
|
|
|
|
|
|
|
val=false |
|
|
;; |
|
|
;; |
|
|
*) |
|
|
*) |
|
|
die "Invalid value for ${WHITE}$key$NORMAL, please use a boolean value." |
|
|
die "Invalid value for ${WHITE}$key$NORMAL, please use a boolean value." |
|
|
;; |
|
|
;; |
|
|
esac |
|
|
esac |
|
|
;; |
|
|
;; |
|
|
*" ${key_option}:numeric "*) |
|
|
|
|
|
|
|
|
*" ${key}:numeric "*) |
|
|
|
|
|
val=$(e "$val" | shyaml get-value) |
|
|
if ! is_int "$val"; then |
|
|
if ! is_int "$val"; then |
|
|
die "Invalid value for ${WHITE}$key$NORMAL, please use numeric value." |
|
|
|
|
|
|
|
|
err "Invalid value for ${WHITE}$key$NORMAL, please use numeric value." |
|
|
|
|
|
return 1 |
|
|
fi |
|
|
fi |
|
|
;; |
|
|
;; |
|
|
*" ${key_option}:string "*) |
|
|
|
|
|
|
|
|
*" ${key}:struct* "*) |
|
|
|
|
|
val=$(e "$val" | monujo:json-make noconv) || return 1 |
|
|
|
|
|
;; |
|
|
|
|
|
*" ${key}:struct "*) |
|
|
|
|
|
val=$(e "$val" | monujo:json-make) || return 1 |
|
|
|
|
|
;; |
|
|
|
|
|
*" ${key}:string "*|*) |
|
|
|
|
|
: |
|
|
|
|
|
;; |
|
|
|
|
|
esac |
|
|
|
|
|
case "$ytype" in |
|
|
|
|
|
struct|sequence) |
|
|
: |
|
|
: |
|
|
;; |
|
|
;; |
|
|
|
|
|
bool) |
|
|
|
|
|
val=$(e "$val" | shyaml get-value) |
|
|
|
|
|
## shyaml outputs actually python's True/False, |
|
|
|
|
|
## json need the lowercase version. |
|
|
|
|
|
val=${val,,} |
|
|
|
|
|
;; |
|
|
|
|
|
str) |
|
|
|
|
|
val=$(e "$val" | shyaml get-value | jq -Rr tojson) |
|
|
|
|
|
;; |
|
|
*) |
|
|
*) |
|
|
key_option=$(echo "$key_option" | sed 's/_\([a-z0-9]\)/\U\1/g') |
|
|
|
|
|
printf "%s %s\0" "$key_option" "$val" |
|
|
|
|
|
|
|
|
echo "YTYPE: $ytype" >&2 |
|
|
|
|
|
echo "VAL: $val" >&2 |
|
|
|
|
|
val=$(e "$val" | shyaml get-value | jq -r tojson) |
|
|
;; |
|
|
;; |
|
|
esac |
|
|
esac |
|
|
done < <(printf "%s" "$service_def" | shyaml key-values-0 options) | |
|
|
|
|
|
jq -R 'split("\u0000") | map(split(" ") | {key: .[0], value: .[1]}) | from_entries' > \ |
|
|
|
|
|
"$CONFIGFILE" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$conv" ]; then |
|
|
|
|
|
key=$(echo "${key//-/_}" | sed 's/_\([a-z0-9]\)/\U\1/g') |
|
|
|
|
|
fi |
|
|
|
|
|
printf "$sep%s\0%s" "$key" "$val" |
|
|
|
|
|
sep="\0\0" |
|
|
|
|
|
done < <(shyaml key-values-0 -y) | |
|
|
|
|
|
jq -sR 'split("\u0000\u0000") | map(split("\u0000") | {key: .[0], value: .[1] | fromjson}) | from_entries' |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|