Skip to content

Commit 18528a1

Browse files
authored
chore(cli): Add Linux helper scripts (#361)
- Adds `install` and `celest` scripts to simplify the installation of Celest CLI on Linux and the execution in headless environments. - Updates Linux releases with proper deps and architecture
1 parent d6510cc commit 18528a1

File tree

5 files changed

+103
-5
lines changed

5 files changed

+103
-5
lines changed

apps/cli/lib/src/cli/cli.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@ final class Cli {
9595
await ctx.secureStorage.init();
9696
} on Object catch (e, st) {
9797
_logger.fine('Failed to initialize storage', e, st);
98-
// TODO(dnys1): Need glib/gio linked on Linux.
9998
if (kReleaseMode) {
10099
if (ctx.platform.isLinux) {
101100
throw const CliException(
102-
'libsecret is not installed. Please run `apt-get install libsecret-1-dev` '
103-
'or equivalent before running Celest.',
101+
'libsecret is not installed. Please run `apt-get install gnome-keyring libsecret-1-0` '
102+
'or equivalent and ensure gnome-keyring-daemon is running before running Celest.',
104103
);
105104
}
106105
// This shouldn't happen in release mode, since permissioning should

apps/cli/tool/linux/celest

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
#
3+
# A helper script for running Celest in headless Linux environments.
4+
#
5+
# This script configures the environment for running Celest and then executes the Celest binary.
6+
7+
set -e
8+
9+
OS=`uname -s`
10+
if test $OS = "Linux"; then
11+
test -e /etc/os-release && os_release='/etc/os-release' || os_release='/usr/lib/os-release'
12+
. "${os_release}"
13+
14+
if [ "${ID:-linux}" != "debian" ] && [ "${ID_LIKE#*debian*}" != "${ID_LIKE}" ]; then
15+
>&2 echo "Unsupported distribution: ${ID:-linux}"
16+
exit 1
17+
fi
18+
19+
# If running in headless mode, re-run script in dbus session.
20+
if ! dbus-send --session --dest=org.freedesktop.DBus / org.freedesktop.DBus.Peer.Ping > /dev/null 2>&1; then
21+
exec dbus-run-session -- "$0" "$@"
22+
fi
23+
24+
echo 'password' | gnome-keyring-daemon --start --replace --components=secrets --unlock --daemonize > /dev/null 2>&1
25+
fi
26+
27+
celest $@

apps/cli/tool/linux/deb/DEBIAN/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: Celest
2-
Depends: gnome-keyring, libsecret-1-0, libsqlite3-dev
2+
Depends: gnome-keyring, libsecret-1-0, libsqlite3-0
33
Version: {{ version }}
44
Maintainer: Celest
55
Architecture: {{ arch }}

apps/cli/tool/linux/install

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/sh
2+
#
3+
# A script to install Celest CLI on Linux systems.
4+
5+
set -e
6+
7+
install_package() {
8+
if [ "$(id -u)" -ne 0 ]; then
9+
if ! command -v sudo &> /dev/null; then
10+
echo "Script requires sudo to install gnome-keyring. Please install it manually."
11+
exit 1
12+
fi
13+
14+
sudo apt-get update
15+
sudo apt-get install "${@}"
16+
else
17+
apt-get update
18+
apt-get install "${@}"
19+
fi
20+
}
21+
22+
OS=`uname -s`
23+
case `uname -m` in
24+
x86_64|amd64|AMD64)
25+
ARCH="x64"
26+
;;
27+
aarch64)
28+
ARCH="arm64"
29+
;;
30+
*)
31+
>&2 echo "Unsupported architecture: $(uname -m)"
32+
exit 1
33+
;;
34+
esac
35+
36+
if test $OS = "Linux"; then
37+
test -e /etc/os-release && os_release='/etc/os-release' || os_release='/usr/lib/os-release'
38+
. "${os_release}"
39+
40+
if [ "${ID:-linux}" = "debian" ] || [ "${ID_LIKE#*debian*}" != "${ID_LIKE}" ]; then
41+
echo "Detected Debian-based system: ${ID:-linux}"
42+
else
43+
>&2 echo "Unsupported distribution: ${ID:-linux}"
44+
exit 1
45+
fi
46+
47+
# Check if Celest is installed
48+
if ! command -v celest &> /dev/null; then
49+
if ! command -v curl &> /dev/null; then
50+
echo "Installing curl..."
51+
install_package -y curl
52+
fi
53+
54+
echo "Installing Celest..."
55+
CURRENT_DIR=$(pwd)
56+
cd $(mktemp -d)
57+
trap 'cd "$CURRENT_DIR"; rm -rf "$TMP_DIR"' EXIT
58+
59+
ARTIFACT_NAME="celest_cli-linux-${ARCH}.deb"
60+
DOWNLOAD_URL="https://github.com/celest-dev/celest/releases/latest/download/$ARTIFACT_NAME"
61+
62+
echo "Downloading Celest from $DOWNLOAD_URL"
63+
curl -sSLo "$ARTIFACT_NAME" "$DOWNLOAD_URL"
64+
install_package -y --fix-broken "./$ARTIFACT_NAME"
65+
fi
66+
fi
67+
68+
echo "Celest is installed and ready to use."

apps/cli/tool/release.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,11 @@ final class LinuxDebBundler extends Bundler {
225225
final outputControl = Template(
226226
controlFile.readAsStringSync(),
227227
).renderString({
228-
'arch': arch,
228+
'arch': switch (arch) {
229+
'arm64' => 'arm64',
230+
'x64' => 'amd64',
231+
_ => throw UnsupportedError('Unsupported arch: $arch'),
232+
},
229233
'version': version,
230234
});
231235
print('Writing control contents:\n\n$outputControl\n');

0 commit comments

Comments
 (0)