Set up Pop!_OS for a Federated Core, like CoreDesktop's configure
A port of CoreDesktop's configure to Pop!_OS 24.04 with COSMIC, in the shape of connector-macos: its own install.sh, update and configure, installed in ~/.local/share/federated-connector/connector. Every configure item is ported: the Core (email, calendars and contacts through GNOME Online Accounts and Evolution, as COSMIC has no accounts of its own; Superpanel; files over davfs2; Element; Tally; the email watcher), Tailscale, backups, AI agents in the sandbox and their sign-ins, languages with mise, AI servers, printers, network storage and the agent sandbox. Folders go in the COSMIC Files sidebar. Each item installs what it needs from apt, Flathub or the tool's own apt repository when you set it up. smoketest/run checks it in Ubuntu 24.04 containers with Docker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Find the AI agents' real commands, outside the sandbox's own
|
||||
# (sandbox/bin), and the sandbox runtime. Sourced by configure and
|
||||
# sandbox/agent. Needs CONNECTOR.
|
||||
|
||||
SANDBOX_BIN="$CONNECTOR/sandbox/bin"
|
||||
FC_TOOLS="$HOME/.local/share/federated-connector"
|
||||
|
||||
# Where the agents' installers put them, in case your shell's PATH doesn't
|
||||
# have them yet (e.g. right after installing)
|
||||
AGENT_DIRS="$HOME/.local/bin:$HOME/.opencode/bin:$HOME/.hermes/bin:/usr/local/bin:/usr/bin"
|
||||
|
||||
# The real command for an agent: the first on PATH, or in AGENT_DIRS, that
|
||||
# isn't in sandbox/bin
|
||||
agent_path() {
|
||||
local dir bin_dir IFS=:
|
||||
bin_dir="$(realpath "$SANDBOX_BIN" 2> /dev/null)"
|
||||
for dir in $PATH:$AGENT_DIRS; do
|
||||
[ -n "$dir" ] && [ -d "$dir" ] || continue
|
||||
[ "$(realpath "$dir")" = "$bin_dir" ] && continue
|
||||
if [ -x "$dir/$1" ] && [ ! -d "$dir/$1" ]; then
|
||||
echo "$dir/$1"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
agent_installed() {
|
||||
agent_path "$1" > /dev/null
|
||||
}
|
||||
|
||||
# Run an agent's real command rather than its sandboxed one: setting an agent
|
||||
# up writes outside its sandbox
|
||||
unsandboxed() {
|
||||
local agent="$1" real
|
||||
shift
|
||||
real="$(agent_path "$agent")" || { echo "$agent isn't installed."; return 127; }
|
||||
"$real" "$@"
|
||||
}
|
||||
|
||||
# srt, and the Node.js it runs with: Federated Connector's own, or one
|
||||
# already installed
|
||||
srt_path() {
|
||||
PATH="$FC_TOOLS/srt/bin:$FC_TOOLS/node/bin:$PATH" command -v srt
|
||||
}
|
||||
Executable
+127
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Add or remove a folder in the COSMIC Files sidebar.
|
||||
|
||||
COSMIC Files keeps the sidebar's places in its cosmic-config setting
|
||||
"favorites": ~/.config/cosmic/com.system76.CosmicFiles/v1/favorites, a RON
|
||||
list such as [Home, Documents, Path("/mnt/x"), Named(path: "/mnt/y", name: "y")].
|
||||
COSMIC Files watches the file, so a change shows at once. This adds a folder
|
||||
as Named (a path with the name to show), which COSMIC Files has had since
|
||||
epoch 1.7, and leaves the rest of the list as it is. Without the file, COSMIC
|
||||
Files uses its defaults, so those are written first.
|
||||
|
||||
Usage:
|
||||
cosmic-favorites has <path>
|
||||
cosmic-favorites add <path> <name>
|
||||
cosmic-favorites remove <path>
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
CONFIG = os.path.join(os.environ.get("XDG_CONFIG_HOME") or os.path.expanduser("~/.config"),
|
||||
"cosmic/com.system76.CosmicFiles/v1/favorites")
|
||||
DEFAULTS = ["Home", "Documents", "Downloads", "Music", "Pictures", "Videos"]
|
||||
|
||||
|
||||
def split_items(text):
|
||||
"""The top-level items of a RON list, as text."""
|
||||
text = text.strip()
|
||||
if not (text.startswith("[") and text.endswith("]")):
|
||||
raise ValueError("not a RON list")
|
||||
items, depth, start, quoted, escaped = [], 0, 1, False, False
|
||||
for i, ch in enumerate(text[1:-1], 1):
|
||||
if quoted:
|
||||
if escaped:
|
||||
escaped = False
|
||||
elif ch == "\\":
|
||||
escaped = True
|
||||
elif ch == '"':
|
||||
quoted = False
|
||||
elif ch == '"':
|
||||
quoted = True
|
||||
elif ch in "([{":
|
||||
depth += 1
|
||||
elif ch in ")]}":
|
||||
depth -= 1
|
||||
elif ch == "," and depth == 0:
|
||||
items.append(text[start:i].strip())
|
||||
start = i + 1
|
||||
last = text[start:-1].strip()
|
||||
if last:
|
||||
items.append(last)
|
||||
return [item for item in items if item]
|
||||
|
||||
|
||||
def ron_string(value):
|
||||
return '"' + value.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
||||
|
||||
|
||||
def unquote(value):
|
||||
out, escaped = [], False
|
||||
for ch in value[1:-1]:
|
||||
if escaped:
|
||||
out.append(ch)
|
||||
escaped = False
|
||||
elif ch == "\\":
|
||||
escaped = True
|
||||
else:
|
||||
out.append(ch)
|
||||
return "".join(out)
|
||||
|
||||
|
||||
def item_path(item):
|
||||
"""The path of a Path, Named or Network item, or None."""
|
||||
for prefix in ("Path(", "Named(", "Network("):
|
||||
if not item.startswith(prefix):
|
||||
continue
|
||||
body = item[len(prefix):-1].strip().rstrip(",")
|
||||
if prefix == "Path(":
|
||||
return unquote(body.strip())
|
||||
for field in split_items("[" + body + "]"):
|
||||
key, _, value = field.partition(":")
|
||||
if key.strip() == "path":
|
||||
return unquote(value.strip())
|
||||
return None
|
||||
|
||||
|
||||
def load():
|
||||
try:
|
||||
with open(CONFIG, encoding="utf-8") as f:
|
||||
return split_items(f.read())
|
||||
except FileNotFoundError:
|
||||
return list(DEFAULTS)
|
||||
|
||||
|
||||
def save(items):
|
||||
os.makedirs(os.path.dirname(CONFIG), exist_ok=True)
|
||||
tmp = CONFIG + ".tmp"
|
||||
with open(tmp, "w", encoding="utf-8") as f:
|
||||
f.write("[\n" + "".join(f" {item},\n" for item in items) + "]")
|
||||
os.replace(tmp, CONFIG)
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
if len(args) == 2 and args[0] == "has":
|
||||
return 0 if any(item_path(i) == args[1] for i in load()) else 1
|
||||
if len(args) == 3 and args[0] == "add":
|
||||
items = [i for i in load() if item_path(i) != args[1]]
|
||||
items.append(f"Named(path: {ron_string(args[1])}, name: {ron_string(args[2])})")
|
||||
save(items)
|
||||
return 0
|
||||
if len(args) == 2 and args[0] == "remove":
|
||||
items = load()
|
||||
kept = [i for i in items if item_path(i) != args[1]]
|
||||
if kept != items:
|
||||
save(kept)
|
||||
return 0
|
||||
print(__doc__.strip().split("\n\n")[-1], file=sys.stderr)
|
||||
return 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
sys.exit(main())
|
||||
except (OSError, ValueError) as error:
|
||||
print(f"COSMIC Files sidebar: {error}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
Executable
+263
@@ -0,0 +1,263 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Add, change or remove an account in GNOME Online Accounts, the way GNOME Settings does.
|
||||
|
||||
COSMIC has no accounts of its own, so configure keeps your Core's email,
|
||||
calendars and contacts in GNOME Online Accounts, which runs as a D-Bus
|
||||
service without GNOME, and Evolution shows them.
|
||||
|
||||
Settings adds accounts by calling AddAccount on the Online Accounts service,
|
||||
which saves the account and keeps its password in the GNOME keyring. This
|
||||
calls the same method. The service can't change a password, so when you sign
|
||||
in again, Settings saves the new one in the keyring itself and asks the
|
||||
service to check it (EnsureCredentials); update does the same. Passwords come
|
||||
on stdin rather than as arguments, so they don't show up in the process list.
|
||||
|
||||
Usage:
|
||||
goa-account exists <provider> <presentation-identity>
|
||||
goa-account add < account.json
|
||||
goa-account update <provider> <presentation-identity> < credentials.json
|
||||
goa-account check <provider> <presentation-identity>
|
||||
goa-account disabled <provider> <presentation-identity>
|
||||
goa-account enable <provider> <presentation-identity>
|
||||
goa-account attention <provider> <presentation-identity>
|
||||
goa-account pause <provider> <presentation-identity>
|
||||
goa-account paused <provider> <presentation-identity>
|
||||
goa-account remove <provider> <presentation-identity>
|
||||
|
||||
account.json:
|
||||
{"provider": "owncloud", "identity": "...", "presentation_identity": "...",
|
||||
"credentials": {"password": "..."}, "details": {"Uri": "...", ...}}
|
||||
|
||||
credentials.json is the account's "credentials", e.g. {"password": "..."}.
|
||||
check signs in with what's saved, and fails if the server says no. update
|
||||
exits with 3 if it saved the password but the server didn't accept it.
|
||||
disabled prints the features configure uses that are turned off (e.g. in
|
||||
GNOME Settings), such as "Calendar, Files", and enable turns them back on.
|
||||
|
||||
attention exits 0 if Online Accounts marked the account as needing
|
||||
attention. It doesn't sign in, so it doesn't add to the server's count of
|
||||
failed logins. Online Accounts 3.50, which Pop!_OS 24.04 has, marks it for
|
||||
any failure, including a server it couldn't reach, so it's only a hint that
|
||||
the password may be wrong (see system/email-watch).
|
||||
|
||||
pause empties the account's saved password, keeping its place in the keyring.
|
||||
Online Accounts signs in again whenever the network changes, and Evolution
|
||||
whenever it fetches mail; with no password neither tries, so a mail server
|
||||
with fail2ban doesn't block this computer for repeated wrong passwords.
|
||||
update puts a password back, which ends the pause. paused exits 0 if paused.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gio", "2.0")
|
||||
gi.require_version("Secret", "1")
|
||||
from gi.repository import Gio, GLib, Secret # noqa: E402
|
||||
|
||||
BUS_NAME = "org.gnome.OnlineAccounts"
|
||||
|
||||
# How Online Accounts keeps passwords in the keyring: the credentials printed
|
||||
# as a GVariant, under "<provider>:gen<N>:<account id>"
|
||||
SCHEMA = Secret.Schema.new("org.gnome.OnlineAccounts", Secret.SchemaFlags.DONT_MATCH_NAME,
|
||||
{"goa-identity": Secret.SchemaAttributeType.STRING})
|
||||
|
||||
# The features configure sets each kind of account up for. Every account has
|
||||
# a <feature>Disabled property for each feature, used or not.
|
||||
FEATURES = {"owncloud": ["Calendar", "Contacts", "Files"], "imap_smtp": ["Mail"]}
|
||||
|
||||
|
||||
def call(bus, path, interface, method, parameters, reply_type):
|
||||
return bus.call_sync(BUS_NAME, path, interface, method, parameters,
|
||||
GLib.VariantType(reply_type), Gio.DBusCallFlags.NONE,
|
||||
-1, None).unpack()
|
||||
|
||||
|
||||
def accounts(bus):
|
||||
(objects,) = call(bus, "/org/gnome/OnlineAccounts",
|
||||
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects",
|
||||
None, "(a{oa{sa{sv}}})")
|
||||
for path, interfaces in objects.items():
|
||||
account = interfaces.get("org.gnome.OnlineAccounts.Account")
|
||||
if account:
|
||||
yield path, account
|
||||
|
||||
|
||||
def find_accounts(bus, provider, presentation_identity):
|
||||
return [(path, account) for path, account in accounts(bus)
|
||||
if account.get("ProviderType") == provider
|
||||
and account.get("PresentationIdentity") == presentation_identity]
|
||||
|
||||
|
||||
def find(bus, provider, presentation_identity):
|
||||
return [path for path, _ in find_accounts(bus, provider, presentation_identity)]
|
||||
|
||||
|
||||
def exists(bus, provider, presentation_identity):
|
||||
return bool(find(bus, provider, presentation_identity))
|
||||
|
||||
|
||||
def add(bus, account):
|
||||
credentials = {key: GLib.Variant("s", value)
|
||||
for key, value in account["credentials"].items()}
|
||||
parameters = GLib.Variant("(sssa{sv}a{ss})", (
|
||||
account["provider"], account["identity"],
|
||||
account["presentation_identity"], credentials, account["details"]))
|
||||
call(bus, "/org/gnome/OnlineAccounts/Manager",
|
||||
"org.gnome.OnlineAccounts.Manager", "AddAccount", parameters, "(o)")
|
||||
|
||||
|
||||
def ensure_credentials(bus, path):
|
||||
call(bus, path, "org.gnome.OnlineAccounts.Account", "EnsureCredentials", None, "(i)")
|
||||
|
||||
|
||||
# N in the keyring's name comes from the provider, so this saves over the
|
||||
# account's own item rather than making one
|
||||
def store_credentials(provider, account_id, credentials):
|
||||
items = Secret.password_search_sync(
|
||||
None, {"xdg:schema": "org.gnome.OnlineAccounts"},
|
||||
Secret.SearchFlags.ALL | Secret.SearchFlags.UNLOCK, None)
|
||||
identities = [item.get_attributes().get("goa-identity", "") for item in items]
|
||||
identities = [identity for identity in identities
|
||||
if identity.startswith(f"{provider}:gen") and identity.endswith(f":{account_id}")]
|
||||
if not identities:
|
||||
raise LookupError(f"there's no saved password for {account_id} in the keyring")
|
||||
secret = GLib.Variant("a{sv}", {key: GLib.Variant("s", value)
|
||||
for key, value in credentials.items()}).print_(True)
|
||||
for identity in identities:
|
||||
Secret.password_store_sync(SCHEMA, {"goa-identity": identity}, Secret.COLLECTION_DEFAULT,
|
||||
f"GOA {provider} credentials for identity {account_id}",
|
||||
secret, None)
|
||||
|
||||
|
||||
# The account's saved credentials, e.g. {"imap-password": "..."}
|
||||
def lookup_credentials(provider, account_id):
|
||||
items = Secret.password_search_sync(
|
||||
None, {"xdg:schema": "org.gnome.OnlineAccounts"},
|
||||
Secret.SearchFlags.ALL | Secret.SearchFlags.UNLOCK | Secret.SearchFlags.LOAD_SECRETS, None)
|
||||
for item in items:
|
||||
identity = item.get_attributes().get("goa-identity", "")
|
||||
if identity.startswith(f"{provider}:gen") and identity.endswith(f":{account_id}"):
|
||||
return GLib.Variant.parse(None, item.get_secret().get_text(), None, None).unpack()
|
||||
raise LookupError(f"there's no saved password for {account_id} in the keyring")
|
||||
|
||||
|
||||
# The credential each kind of account signs in with
|
||||
PASSWORD_KEYS = {"owncloud": "password", "imap_smtp": "imap-password"}
|
||||
|
||||
|
||||
def attention(bus, provider, presentation_identity):
|
||||
found = find_accounts(bus, provider, presentation_identity)
|
||||
if not found:
|
||||
raise LookupError(f"there's no {provider} account for {presentation_identity}")
|
||||
return any(account.get("AttentionNeeded") for _, account in found)
|
||||
|
||||
|
||||
def pause(bus, provider, presentation_identity):
|
||||
found = find_accounts(bus, provider, presentation_identity)
|
||||
if not found:
|
||||
raise LookupError(f"there's no {provider} account for {presentation_identity}")
|
||||
for _, account in found:
|
||||
store_credentials(provider, account["Id"], {})
|
||||
|
||||
|
||||
def paused(bus, provider, presentation_identity):
|
||||
found = find_accounts(bus, provider, presentation_identity)
|
||||
if not found:
|
||||
raise LookupError(f"there's no {provider} account for {presentation_identity}")
|
||||
return any(PASSWORD_KEYS[provider] not in lookup_credentials(provider, account["Id"])
|
||||
for _, account in found)
|
||||
|
||||
|
||||
def update(bus, provider, presentation_identity, credentials):
|
||||
found = find_accounts(bus, provider, presentation_identity)
|
||||
if not found:
|
||||
raise LookupError(f"there's no {provider} account for {presentation_identity}")
|
||||
for path, account in found:
|
||||
store_credentials(provider, account["Id"], credentials)
|
||||
try:
|
||||
for path, _ in found:
|
||||
ensure_credentials(bus, path)
|
||||
except GLib.Error as error:
|
||||
print(f"GNOME Online Accounts: {error.message}", file=sys.stderr)
|
||||
return 3
|
||||
return 0
|
||||
|
||||
|
||||
def check(bus, provider, presentation_identity):
|
||||
found = find(bus, provider, presentation_identity)
|
||||
if not found:
|
||||
raise LookupError(f"there's no {provider} account for {presentation_identity}")
|
||||
for path in found:
|
||||
ensure_credentials(bus, path)
|
||||
|
||||
|
||||
def disabled(bus, provider, presentation_identity):
|
||||
found = find_accounts(bus, provider, presentation_identity)
|
||||
if not found:
|
||||
raise LookupError(f"there's no {provider} account for {presentation_identity}")
|
||||
return [feature for feature in FEATURES.get(provider, [])
|
||||
if any(account.get(f"{feature}Disabled") for _, account in found)]
|
||||
|
||||
|
||||
# Settings turns a feature off or on by setting its property
|
||||
def enable(bus, provider, presentation_identity):
|
||||
for path, account in find_accounts(bus, provider, presentation_identity):
|
||||
for feature in FEATURES.get(provider, []):
|
||||
if account.get(f"{feature}Disabled"):
|
||||
call(bus, path, "org.freedesktop.DBus.Properties", "Set",
|
||||
GLib.Variant("(ssv)", ("org.gnome.OnlineAccounts.Account",
|
||||
f"{feature}Disabled", GLib.Variant("b", False))),
|
||||
"()")
|
||||
|
||||
|
||||
def remove(bus, provider, presentation_identity):
|
||||
for path in find(bus, provider, presentation_identity):
|
||||
call(bus, path, "org.gnome.OnlineAccounts.Account", "Remove", None, "()")
|
||||
|
||||
|
||||
def main():
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "exists":
|
||||
return 0 if exists(bus, sys.argv[2], sys.argv[3]) else 1
|
||||
if len(sys.argv) == 2 and sys.argv[1] == "add":
|
||||
account = json.load(sys.stdin)
|
||||
if exists(bus, account["provider"], account["presentation_identity"]):
|
||||
return 0
|
||||
add(bus, account)
|
||||
return 0
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "update":
|
||||
return update(bus, sys.argv[2], sys.argv[3], json.load(sys.stdin))
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "check":
|
||||
check(bus, sys.argv[2], sys.argv[3])
|
||||
return 0
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "disabled":
|
||||
print(", ".join(disabled(bus, sys.argv[2], sys.argv[3])))
|
||||
return 0
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "enable":
|
||||
enable(bus, sys.argv[2], sys.argv[3])
|
||||
return 0
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "attention":
|
||||
return 0 if attention(bus, sys.argv[2], sys.argv[3]) else 1
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "pause":
|
||||
pause(bus, sys.argv[2], sys.argv[3])
|
||||
return 0
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "paused":
|
||||
return 0 if paused(bus, sys.argv[2], sys.argv[3]) else 1
|
||||
if len(sys.argv) == 4 and sys.argv[1] == "remove":
|
||||
remove(bus, sys.argv[2], sys.argv[3])
|
||||
return 0
|
||||
print(__doc__.strip().split("\n\n")[2], file=sys.stderr)
|
||||
return 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
sys.exit(main())
|
||||
except GLib.Error as error:
|
||||
print(f"GNOME Online Accounts: {error.message}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except LookupError as error:
|
||||
print(f"GNOME Online Accounts: {error}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Edit JSON settings files for configure.d items. Source this file.
|
||||
|
||||
# Edit a JSON file in place with jq, creating it from $2 if it's missing.
|
||||
# Leaves the file alone if it isn't valid JSON or jq fails.
|
||||
edit_json() {
|
||||
local file="$1" empty="$2" tmp
|
||||
shift 2
|
||||
mkdir -p "$(dirname "$file")" || return 1
|
||||
[ -f "$file" ] || echo "$empty" > "$file"
|
||||
tmp="$(mktemp "$file.XXXXXX")" || return 1
|
||||
if jq "$@" "$file" > "$tmp"; then
|
||||
mv -f "$tmp" "$file"
|
||||
else
|
||||
echo "Couldn't change $file; is it valid JSON?"
|
||||
rm -f "$tmp"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Find what's on the local network over mDNS (Avahi), for the
|
||||
# configure.d items that set up servers, printers and storage on it.
|
||||
# Source this file.
|
||||
|
||||
# Every service Avahi can see, or only those of type $1 (e.g. _ipp._tcp), one
|
||||
# per line after waiting a few seconds for answers:
|
||||
# "name|type|host|address|port|txt". IPv4 only, so a machine isn't listed once
|
||||
# per address family. The name has Avahi's escapes decoded.
|
||||
mdns_services() {
|
||||
local name type host address port txt
|
||||
timeout 15 avahi-browse "${1:---all}" --resolve --terminate --parsable --no-db-lookup 2> /dev/null \
|
||||
| awk -F';' '$1 == "=" && $3 == "IPv4"' \
|
||||
| while IFS=';' read -r _ _ _ name type _ host address port txt; do
|
||||
printf '%s|%s|%s|%s|%s|%s\n' "$(mdns_unescape "$name")" "$type" "$host" "$address" "$port" "$txt"
|
||||
done | sort -u
|
||||
}
|
||||
|
||||
# Avahi writes a space as \032 and a dot in a name as \. (decimal escapes)
|
||||
mdns_unescape() {
|
||||
local s="$1" out="" ch code escape='^([^\\]*)\\([0-9][0-9][0-9]|.)(.*)$'
|
||||
while [[ "$s" =~ $escape ]]; do
|
||||
out+="${BASH_REMATCH[1]}"
|
||||
code="${BASH_REMATCH[2]}"
|
||||
s="${BASH_REMATCH[3]}"
|
||||
if [[ "$code" == [0-9][0-9][0-9] ]]; then
|
||||
# shellcheck disable=SC2059
|
||||
printf -v ch "\\$(printf %03o "$((10#$code))")"
|
||||
out+="$ch"
|
||||
else
|
||||
out+="$code"
|
||||
fi
|
||||
done
|
||||
echo "$out$s"
|
||||
}
|
||||
|
||||
# This machine's own .local name, which mdns_hosts leaves out
|
||||
mdns_own_host() {
|
||||
echo "$(hostnamectl hostname 2> /dev/null || cat /etc/hostname).local"
|
||||
}
|
||||
|
||||
# The other machines on the network: one .local name per line
|
||||
mdns_hosts() {
|
||||
local own
|
||||
own="$(mdns_own_host)"
|
||||
mdns_services | cut -d'|' -f3 | grep -vixF "$own" | sort -u
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Nextcloud app passwords for configure.d items. Source this file.
|
||||
|
||||
# Basic auth header for curl, read from stdin (-H @-) so the password isn't
|
||||
# in the process list
|
||||
auth_header() {
|
||||
printf 'Authorization: Basic %s\n' "$(printf '%s:%s' "$1" "$2" | base64 -w0)"
|
||||
}
|
||||
|
||||
# Create a Nextcloud app password, so what configure sets up doesn't keep
|
||||
# your Core password. It shows in Nextcloud under Settings > Security with the
|
||||
# name given, where it can be revoked. Uses CORE_USER, PASSWORD and NEXTCLOUD;
|
||||
# sets APP_PASSWORD. Returns 2 if Nextcloud says the password is wrong.
|
||||
nextcloud_app_password() {
|
||||
local name="$1" response code
|
||||
response="$(auth_header "$CORE_USER" "$PASSWORD" | curl -s -w '\n%{http_code}' -H @- \
|
||||
-H 'OCS-APIRequest: true' -A "$name" \
|
||||
"$NEXTCLOUD/ocs/v2.php/core/getapppassword?format=json")"
|
||||
code="${response##*$'\n'}"
|
||||
case "$code" in
|
||||
200) APP_PASSWORD="$(jq -r '.ocs.data.apppassword // empty' <<< "${response%$'\n'*}")"
|
||||
[ -n "$APP_PASSWORD" ] ;;
|
||||
401) return 2 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Revoke an app password, signing in with it. Uses CORE_USER and NEXTCLOUD.
|
||||
nextcloud_revoke_app_password() {
|
||||
auth_header "$CORE_USER" "$1" | curl -sf -o /dev/null -X DELETE -H @- \
|
||||
-H 'OCS-APIRequest: true' "$NEXTCLOUD/ocs/v2.php/core/apppassword"
|
||||
}
|
||||
|
||||
# Sign in to Nextcloud as CORE_USER with a password ($1), or PASSWORD if not
|
||||
# given. Signing in with your Core password (not an app password) also turns
|
||||
# back on the app passwords Nextcloud turned off when the Core password
|
||||
# changed. Uses NEXTCLOUD. Returns 2 if Nextcloud says the password is wrong.
|
||||
nextcloud_sign_in() {
|
||||
local code
|
||||
code="$(auth_header "$CORE_USER" "${1:-$PASSWORD}" | curl -s -o /dev/null -w '%{http_code}' -H @- \
|
||||
-H 'OCS-APIRequest: true' "$NEXTCLOUD/ocs/v2.php/cloud/user?format=json")"
|
||||
case "$code" in
|
||||
200) return 0 ;;
|
||||
401) return 2 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Install what an item needs from Pop!_OS' and Ubuntu's apt
|
||||
# repositories, and from Flathub. Source this file; it uses
|
||||
# confirm_yes from configure.
|
||||
#
|
||||
# Pop!_OS comes with less than CoreDesktop installs up front, so each item
|
||||
# installs what it needs the first time you set it up, after asking.
|
||||
|
||||
is_pop() {
|
||||
[ "$(. /etc/os-release 2> /dev/null && echo "$ID")" = pop ]
|
||||
}
|
||||
|
||||
os_name() {
|
||||
(. /etc/os-release 2> /dev/null && echo "${PRETTY_NAME:-$ID}") || uname -s
|
||||
}
|
||||
|
||||
# True if every package named is installed
|
||||
pkg_installed() {
|
||||
local pkg
|
||||
for pkg in "$@"; do
|
||||
[ "$(dpkg-query -W -f '${db:Status-Status}' "$pkg" 2> /dev/null)" = installed ] || return 1
|
||||
done
|
||||
}
|
||||
|
||||
# pkg_ensure <what they're for> <package>...: offer to install the packages
|
||||
# that are missing. Fails if any is still missing.
|
||||
pkg_ensure() {
|
||||
local why="$1" pkg missing=()
|
||||
shift
|
||||
for pkg in "$@"; do
|
||||
pkg_installed "$pkg" || missing+=("$pkg")
|
||||
done
|
||||
[ ${#missing[@]} -eq 0 ] && return 0
|
||||
echo "$why needs: ${missing[*]}"
|
||||
confirm_yes "Install them now (with apt; asks for your password)?" || return 1
|
||||
pkg_install "${missing[@]}"
|
||||
}
|
||||
|
||||
# Install packages without asking. apt's lists may be old on a new install,
|
||||
# so they're refreshed once per run if the install fails.
|
||||
pkg_install() {
|
||||
sudo apt-get install -y "$@" && return 0
|
||||
[ -n "$PKG_UPDATED" ] && return 1
|
||||
PKG_UPDATED=1
|
||||
sudo apt-get update && sudo apt-get install -y "$@"
|
||||
}
|
||||
|
||||
# Flatpak apps come from Flathub, as in the COSMIC Store
|
||||
flatpak_installed() {
|
||||
flatpak info "$1" &> /dev/null
|
||||
}
|
||||
|
||||
# flatpak_ensure <app id> <name> <what it's for>
|
||||
flatpak_ensure() {
|
||||
flatpak_installed "$1" && return 0
|
||||
echo "$2 isn't installed. $3"
|
||||
confirm_yes "Install $2 from Flathub?" || return 1
|
||||
flatpak install -y --noninteractive flathub "$1"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Show a folder in the Files sidebar. Source this file; needs
|
||||
# CONNECTOR.
|
||||
#
|
||||
# COSMIC Files has its own list (see lib/cosmic-favorites). GTK apps, such
|
||||
# as Evolution's file chooser, read ~/.config/gtk-3.0/bookmarks, so the folder
|
||||
# goes in both.
|
||||
|
||||
GTK_BOOKMARKS="$HOME/.config/gtk-3.0/bookmarks"
|
||||
COSMIC_FAVORITES="$CONNECTOR/configure.d/lib/cosmic-favorites"
|
||||
|
||||
# sidebar_add <folder> <name>
|
||||
sidebar_add() {
|
||||
mkdir -p "$(dirname "$GTK_BOOKMARKS")"
|
||||
grep -qs "^file://$1 " "$GTK_BOOKMARKS" || echo "file://$1 $2" >> "$GTK_BOOKMARKS"
|
||||
"$COSMIC_FAVORITES" add "$1" "$2"
|
||||
}
|
||||
|
||||
sidebar_remove() {
|
||||
local tmp
|
||||
if [ -f "$GTK_BOOKMARKS" ]; then
|
||||
tmp="$(mktemp)" || return 1
|
||||
grep -vF "file://$1 " "$GTK_BOOKMARKS" > "$tmp"
|
||||
mv -f "$tmp" "$GTK_BOOKMARKS"
|
||||
fi
|
||||
"$COSMIC_FAVORITES" remove "$1"
|
||||
}
|
||||
|
||||
sidebar_has() {
|
||||
"$COSMIC_FAVORITES" has "$1" 2> /dev/null
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Node.js and Anthropic's sandbox runtime (srt) for the agent
|
||||
# sandbox. Source this file after lib/agents.sh; it uses
|
||||
# confirm_yes from configure.
|
||||
#
|
||||
# srt needs Node.js 22.12 or later, and Pop!_OS 24.04's is 18. So unless a
|
||||
# new enough one is installed already, the current long-term support release
|
||||
# is downloaded from nodejs.org into FC_TOOLS/node, checked against the
|
||||
# SHA-256 sums it publishes, and used only for srt: nothing in /usr or your
|
||||
# shell changes.
|
||||
|
||||
# srt needs Node.js 22.12 or later
|
||||
node_ok() {
|
||||
local node version
|
||||
node="$(PATH="$FC_TOOLS/node/bin:$PATH" command -v node)" || return 1
|
||||
version="$("$node" -p 'process.versions.node' 2> /dev/null)" || return 1
|
||||
[ "$(printf '%s\n' 22.12.0 "$version" | sort -V | head -n 1)" = 22.12.0 ]
|
||||
}
|
||||
|
||||
# download_checked <url> <sums url> <file name in sums> <destination>
|
||||
download_checked() {
|
||||
local url="$1" sums_url="$2" name="$3" dest="$4" expected actual
|
||||
echo "Downloading $url"
|
||||
curl -fL --progress-bar --max-time 1800 -o "$dest" "$url" || return 1
|
||||
expected="$(curl -fsL --max-time 30 "$sums_url" | awk -v f="$name" '$2 == f || $2 == "*" f { print $1; exit }')"
|
||||
actual="$(sha256sum "$dest" | cut -d' ' -f1)"
|
||||
if [ -z "$expected" ] || [ "$expected" != "$actual" ]; then
|
||||
echo -e "\e[31mThe download doesn't match the checksum its release publishes. Not installing it.\e[0m"
|
||||
rm -f "$dest"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
install_node() {
|
||||
local tmp version arch name status=1
|
||||
version="$(curl -fsL --max-time 30 https://nodejs.org/dist/index.json \
|
||||
| jq -r '[.[] | select(.lts)][0].version // empty')"
|
||||
[ -n "$version" ] || { echo "Couldn't find Node.js' current release."; return 1; }
|
||||
case "$(uname -m)" in
|
||||
aarch64|arm64) arch=arm64 ;;
|
||||
*) arch=x64 ;;
|
||||
esac
|
||||
name="node-$version-linux-$arch.tar.xz"
|
||||
tmp="$(mktemp -d)" || return 1
|
||||
if download_checked "https://nodejs.org/dist/$version/$name" \
|
||||
"https://nodejs.org/dist/$version/SHASUMS256.txt" "$name" "$tmp/$name" \
|
||||
&& tar -xJf "$tmp/$name" -C "$tmp" && mkdir -p "$FC_TOOLS"; then
|
||||
rm -rf "$FC_TOOLS/node" && mv "$tmp/${name%.tar.xz}" "$FC_TOOLS/node" && status=0
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
return $status
|
||||
}
|
||||
|
||||
# srt from npm, into FC_TOOLS/srt. It has no install scripts of its own; the
|
||||
# ones npm would warn it blocked belong to a Windows-only package it
|
||||
# optionally depends on.
|
||||
install_srt() {
|
||||
local node_dir
|
||||
node_ok || install_node || return 1
|
||||
node_dir="$(dirname "$(PATH="$FC_TOOLS/node/bin:$PATH" command -v node)")"
|
||||
echo "Installing the sandbox runtime (srt) from npm..."
|
||||
PATH="$node_dir:$PATH" "$node_dir/npm" install --global --prefix "$FC_TOOLS/srt" \
|
||||
--no-fund --no-audit --ignore-scripts @anthropic-ai/sandbox-runtime > /dev/null
|
||||
}
|
||||
|
||||
# Updating srt is installing it again
|
||||
srt_ensure() {
|
||||
srt_path > /dev/null && return 0
|
||||
echo "The sandbox is Anthropic's sandbox runtime (srt), which runs on Node.js."
|
||||
node_ok || echo "This computer's Node.js is older than srt needs, so it gets its own, from nodejs.org."
|
||||
confirm_yes "Install it (into $FC_TOOLS)?" || return 1
|
||||
install_srt
|
||||
}
|
||||
Reference in New Issue
Block a user