more configure options

This commit is contained in:
2026-10-26 15:33:27 -06:00
parent bbd6b83f64
commit 1bdd38d2b1
2 changed files with 37 additions and 3 deletions
+36 -2
View File
@@ -1,7 +1,7 @@
#!/bin/bash
TITLE="Federated Computer Core"
DESCRIPTION="Superpanel, Tailscale, Nextcloud, email and files"
DESCRIPTION="Superpanel, Tailscale, Nextcloud, email, files and Element"
# What you entered last time, so running this again only does what's missing
CORE_CONF="$HOME/.config/coredesktop/core.conf"
@@ -15,6 +15,8 @@ core_names() {
WEBDAV="$NEXTCLOUD/remote.php/dav/files/$CORE_USER"
MOUNT="/mnt/$CORE_DOMAIN"
SUPERPANEL_DESKTOP="$HOME/.local/share/applications/core-$CORE_DOMAIN-superpanel.desktop"
MATRIX="https://matrix.$CORE_DOMAIN"
ELEMENT_CONFIG="$HOME/.config/Element/config.json"
}
superpanel_done() {
@@ -40,10 +42,22 @@ files_done() {
grep -qs " $MOUNT davfs " /etc/fstab && grep -qs "^$MOUNT " "$HOME/.davfs2/secrets"
}
element_installed() {
command -v element-desktop > /dev/null
}
# Done when Element isn't installed, as there's nothing to set up
element_done() {
element_installed || return 0
jq -e --arg url "$MATRIX" \
'.default_server_config["m.homeserver"].base_url | rtrimstr("/") == $url' \
"$ELEMENT_CONFIG" &> /dev/null
}
is_configured() {
[ -n "$CORE_DOMAIN" ] || return 1
core_names
superpanel_done && tailscale_done && nextcloud_done && email_done && files_done
superpanel_done && tailscale_done && nextcloud_done && email_done && files_done && element_done
}
save_conf() {
@@ -255,6 +269,25 @@ EOF
echo "Your Nextcloud files are at $MOUNT (\"$CORE_DOMAIN\" in the Files sidebar)."
}
# Element Desktop reads ~/.config/Element/config.json over its built-in
# settings. Pointing it at the Core's Matrix server means you only choose
# "Sign in" (the Core offers single sign-on through Authelia). The Core's Matrix
# server is named after its address, matrix.<domain>, and says where its API is.
setup_element() {
local base_url config
base_url="$(curl -sf --max-time 15 "$MATRIX/.well-known/matrix/client" \
| jq -r '.["m.homeserver"].base_url // empty' 2> /dev/null)"
base_url="${base_url:-$MATRIX}"
mkdir -p "$(dirname "$ELEMENT_CONFIG")"
config="$(cat "$ELEMENT_CONFIG" 2> /dev/null)"
[ -n "$config" ] || config='{}'
jq --arg url "${base_url%/}" --arg name "matrix.$CORE_DOMAIN" \
'.default_server_config = {"m.homeserver": {base_url: $url, server_name: $name}}' \
<<< "$config" > "$ELEMENT_CONFIG.tmp" && mv -f "$ELEMENT_CONFIG.tmp" "$ELEMENT_CONFIG" || return 1
echo "Element will use $MATRIX the next time it starts."
}
# Run a step unless it's done; a failed step doesn't stop the ones after it
step() {
local name="$1" title="$2"
@@ -310,6 +343,7 @@ run_configure() {
step nextcloud "Nextcloud in Online Accounts"
step email "Email in Online Accounts"
step files "Nextcloud files at $MOUNT"
element_installed && step element "Element with your Core's Matrix server"
unset PASSWORD APP_PASSWORD
return $STATUS
}