forked from 0k/0k-charms
Compare commits
merge into: bgallet:master
bgallet:0k/dev/master
bgallet:backup
bgallet:bgallet/mattermost
bgallet:boris/docuseal
bgallet:boris/matomo
bgallet:boris/rallly
bgallet:boris/smtp-extern
bgallet:charm-codimd-new
bgallet:cups_service_alpha
bgallet:dev
bgallet:dev1
bgallet:dhcp
bgallet:discourse
bgallet:element
bgallet:etherpad-upd
bgallet:framadate
bgallet:hedgedoc
bgallet:lokavaluto/dev/master
bgallet:master
bgallet:matomo
bgallet:nanoyaml
bgallet:netdata
bgallet:new-mailhog-charms
bgallet:new-monujo-options
bgallet:nextcloud
bgallet:nj-collabra-office
bgallet:nj-keycloak-17.0
bgallet:nj-organice-charm
bgallet:nj-vaulwarden-migrate
bgallet:odoo_fix_webhook_url
bgallet:postgres
bgallet:rallly
bgallet:test
bgallet:upd
bgallet:upd-docker
bgallet:update-latest-synapse
bgallet:wip
0k:0k/dev/master
0k:backup
0k:bgallet/nextcloud
0k:boris/smtp-extern
0k:charm-codimd-new
0k:cups_service_alpha
0k:dev
0k:dev1
0k:dhcp
0k:element
0k:etherpad-upd
0k:framadate
0k:get-version
0k:lokavaluto/dev/master
0k:master
0k:matomo
0k:new-mailhog-charms
0k:new-monujo-options
0k:nj-collabra-office
0k:nj-keycloak-17.0
0k:nj-organice-charm
0k:nj-vaulwarden-migrate
0k:ntfy-install
0k:odoo_fix_webhook_url
0k:postgres
0k:test
0k:upd-docker
0k:update-latest-synapse
0k:wip
pull from: bgallet:element
bgallet:0k/dev/master
bgallet:backup
bgallet:bgallet/mattermost
bgallet:boris/docuseal
bgallet:boris/matomo
bgallet:boris/rallly
bgallet:boris/smtp-extern
bgallet:charm-codimd-new
bgallet:cups_service_alpha
bgallet:dev
bgallet:dev1
bgallet:dhcp
bgallet:discourse
bgallet:element
bgallet:etherpad-upd
bgallet:framadate
bgallet:hedgedoc
bgallet:lokavaluto/dev/master
bgallet:master
bgallet:matomo
bgallet:nanoyaml
bgallet:netdata
bgallet:new-mailhog-charms
bgallet:new-monujo-options
bgallet:nextcloud
bgallet:nj-collabra-office
bgallet:nj-keycloak-17.0
bgallet:nj-organice-charm
bgallet:nj-vaulwarden-migrate
bgallet:odoo_fix_webhook_url
bgallet:postgres
bgallet:rallly
bgallet:test
bgallet:upd
bgallet:upd-docker
bgallet:update-latest-synapse
bgallet:wip
0k:0k/dev/master
0k:backup
0k:bgallet/nextcloud
0k:boris/smtp-extern
0k:charm-codimd-new
0k:cups_service_alpha
0k:dev
0k:dev1
0k:dhcp
0k:element
0k:etherpad-upd
0k:framadate
0k:get-version
0k:lokavaluto/dev/master
0k:master
0k:matomo
0k:new-mailhog-charms
0k:new-monujo-options
0k:nj-collabra-office
0k:nj-keycloak-17.0
0k:nj-organice-charm
0k:nj-vaulwarden-migrate
0k:ntfy-install
0k:odoo_fix_webhook_url
0k:postgres
0k:test
0k:upd-docker
0k:update-latest-synapse
0k:wip
1 Commits
Author | SHA1 | Message | Date |
---|---|---|---|
Stéphan Sainléger | 5ffa8ffac6 |
new: [element] new charm
|
2 years ago |
3 changed files with 186 additions and 0 deletions
@ -0,0 +1,24 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
## Init is run on host |
||||
|
## For now it is run every time the script is launched, but |
||||
|
## it should be launched only once after build. |
||||
|
|
||||
|
## Accessible variables are: |
||||
|
## - SERVICE_NAME Name of current service |
||||
|
## - DOCKER_BASE_IMAGE Base image from which this service might be built if any |
||||
|
## - SERVICE_DATASTORE Location on host of the DATASTORE of this service |
||||
|
## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service |
||||
|
|
||||
|
. lib/common |
||||
|
|
||||
|
set -e |
||||
|
|
||||
|
version=$(options-get version 2>/dev/null) |
||||
|
enforce_version=$(options-get enforce-version 2>/dev/null) |
||||
|
enforce_config=$(options-get enforce-config 2>/dev/null) |
||||
|
|
||||
|
element:code_init "$version" "$enforce_version" |
||||
|
|
||||
|
element:code_config_base "$enforce_config" |
||||
|
|
@ -0,0 +1,140 @@ |
|||||
|
|
||||
|
|
||||
|
APP_NAME=element |
||||
|
SOURCE_URL="https://github.com/vector-im/element-web/releases/download" |
||||
|
LOCATION="$SERVICE_CONFIGSTORE/opt/apps/$APP_NAME" |
||||
|
CONFIGFILE="$LOCATION/config.json" |
||||
|
|
||||
|
|
||||
|
element:code_init() { |
||||
|
local version="$1" enforce_version="$2" source_url |
||||
|
if [ -e "$LOCATION/.version" ] && \ |
||||
|
[ "$(cat "$LOCATION/.version")" == "$version" ]; then |
||||
|
return 0 |
||||
|
fi |
||||
|
if [[ "${enforce_version,,}" =~ ^(false|0|no)$ ]]; then |
||||
|
if [ -d "$LOCATION" ]; then |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
if [ -d "$LOCATION" ]; then |
||||
|
find "$LOCATION" -mindepth 1 -delete |
||||
|
else |
||||
|
mkdir -p "$LOCATION" |
||||
|
fi |
||||
|
cd "$LOCATION" |
||||
|
source_url="$SOURCE_URL/$version/$APP_NAME-$version.tar.gz" |
||||
|
info "Downloading '$source_url'." |
||||
|
wget -q "$source_url" -O file.tar.gz || { |
||||
|
err "Couldn't download '$source_url'." |
||||
|
rm file.tar.gz |
||||
|
return 1 |
||||
|
} |
||||
|
tar -zxvf file.tar.gz && |
||||
|
rm file.tar.gz && |
||||
|
chown root:root "$LOCATION" -R && |
||||
|
echo "$version" > "$LOCATION/.version" |
||||
|
} |
||||
|
|
||||
|
export ELEMENT_OPTIONS=( |
||||
|
version:ignore |
||||
|
enforce-version:ignore |
||||
|
enforce-config:ignore |
||||
|
) |
||||
|
|
||||
|
export ELEMENT_OPTIONS_CONCAT=" ${ELEMENT_OPTIONS[*]} " |
||||
|
|
||||
|
|
||||
|
element:code_config_base() { |
||||
|
local enforce_config="$1" service_def |
||||
|
if [[ "${enforce_config,,}" =~ ^(false|0|no)$ ]]; then |
||||
|
if [ -e "$CONFIGFILE" ]; then |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1 |
||||
|
options=$(e "$service_def" | shyaml get-value -y options) || true |
||||
|
|
||||
|
e "$options" | |
||||
|
element:json-make > "$CONFIGFILE" || { |
||||
|
err "Failed to make 'config.json'." |
||||
|
return 1 |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
element:json-make() { |
||||
|
local conv="$1" key val |
||||
|
## XXXvlab: Should probably offer some lib to do this |
||||
|
local sep= |
||||
|
while read-0 key val; do |
||||
|
key=$(e "$key" | shyaml get-value) |
||||
|
ytype=$(e "$val" | shyaml get-type) |
||||
|
case "$ELEMENT_OPTIONS_CONCAT" in |
||||
|
*" ${key}:ignore "*) |
||||
|
continue |
||||
|
;; |
||||
|
*" ${key}:bool "*) |
||||
|
val=$(e "$val" | shyaml get-value) |
||||
|
case "${val,,}" in |
||||
|
true|ok|yes|y) |
||||
|
val=true |
||||
|
;; |
||||
|
false|ko|nok|no|n) |
||||
|
val=false |
||||
|
;; |
||||
|
*) |
||||
|
die "Invalid value for ${WHITE}$key$NORMAL, please use a boolean value." |
||||
|
;; |
||||
|
esac |
||||
|
;; |
||||
|
*" ${key}:numeric "*) |
||||
|
val=$(e "$val" | shyaml get-value) |
||||
|
if ! is_int "$val"; then |
||||
|
err "Invalid value for ${WHITE}$key$NORMAL, please use numeric value." |
||||
|
return 1 |
||||
|
fi |
||||
|
;; |
||||
|
*" ${key}:struct* "*) |
||||
|
val=$(e "$val" | element:json-make noconv) || return 1 |
||||
|
;; |
||||
|
*" ${key}:struct "*) |
||||
|
val=$(e "$val" | element: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) |
||||
|
;; |
||||
|
*) |
||||
|
echo "YTYPE: $ytype" >&2 |
||||
|
echo "VAL: $val" >&2 |
||||
|
val=$(e "$val" | shyaml get-value | jq -r tojson) |
||||
|
;; |
||||
|
esac |
||||
|
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' |
||||
|
} |
||||
|
|
||||
|
|
||||
|
element:config_merge() { |
||||
|
local old_config new_config="$1" |
||||
|
old_config=$(cat "$CONFIGFILE") |
||||
|
e "$old_config" "$new_config" | jq -s 'reduce .[] as $x ({}; . * $x)' > "$CONFIGFILE" |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
description: "Element Web" |
||||
|
maintainer: "Stéphan Sainléger <stephan.sainleger@elabore.coop>" |
||||
|
subordinate: true |
||||
|
|
||||
|
default-options: |
||||
|
version: v1.11.1 |
||||
|
enforce-version: true |
||||
|
enforce-config: true |
||||
|
|
||||
|
uses: |
||||
|
publish-dir: |
||||
|
#constraint: required | recommended | optional |
||||
|
#auto: pair | summon | none ## default: pair |
||||
|
scope: container |
||||
|
constraint: required |
||||
|
auto: summon |
||||
|
solves: |
||||
|
container: "main running server" |
||||
|
default-options: |
||||
|
location: !var-expand "$CONFIGSTORE/$BASE_SERVICE_NAME/opt/apps/element" |
||||
|
# data-dirs: ## write permission for web-app |
||||
|
# - .s |
Write
Preview
Loading…
Cancel
Save
Reference in new issue