220 lines
10 KiB
Bash
Executable File
220 lines
10 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Routine for Linux: install it, update it (run this again), or remove it (--uninstall).
|
|
#
|
|
# curl -fsSL https://git.autonomic.zone/trav/routine/raw/branch/main/install-linux.sh | bash
|
|
# curl -fsSL https://git.autonomic.zone/trav/routine/raw/branch/main/install-linux.sh | bash -s -- --uninstall
|
|
#
|
|
# Puts the app in ~/.local/share/routine-app (never touches your data in ~/.local/share/routine),
|
|
# Routine in the app grid (a .desktop file and the icon), and a launcher. It needs python3 (3.10+)
|
|
# and PySide6: a PySide6 (or PyQt6) your system already has is used as it is; otherwise it offers
|
|
# your distribution's package (it shows the sudo command and asks first: it never runs sudo on its
|
|
# own) or a private copy downloaded with pip into the app folder (no password needed, ~250 MB).
|
|
#
|
|
# Settings, all optional, for testing or unusual setups:
|
|
# ROUTINE_SOURCE=DIR|FILE.tar.gz install from a local checkout / archive instead of downloading
|
|
# ROUTINE_ARCHIVE=URL the archive to download (default: the main branch)
|
|
# ROUTINE_QT_INSTALL=system|venv|distro skip the question (no terminal: venv)
|
|
# ROUTINE_PYTHON=/path/to/python3 the Python to use
|
|
# XDG_DATA_HOME / HOME where it all goes, as usual
|
|
# ROUTINE_FORCE=1 replace a Routine entry in the app grid that this script didn't make
|
|
set -euo pipefail
|
|
|
|
REPO_URL="https://git.autonomic.zone/trav/routine"
|
|
ARCHIVE="${ROUTINE_ARCHIVE:-$REPO_URL/archive/main.tar.gz}"
|
|
PINS=(PySide6-Essentials==6.11.0)
|
|
APP_ID="me.teafry.routine"
|
|
MARK="X-Routine-Installer=install-linux.sh"
|
|
|
|
DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
|
|
STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
|
|
APPDIR="$DATA_HOME/routine-app"
|
|
APPS="$DATA_HOME/applications"
|
|
HICOLOR="$DATA_HOME/icons/hicolor"
|
|
DESKTOP="$APPS/$APP_ID.desktop"
|
|
DATA_DIR="$DATA_HOME/routine"
|
|
|
|
say() { printf '%s\n' "$*"; }
|
|
die() { printf 'Routine installer: %s\n' "$*" >&2; exit 1; }
|
|
have_tty() { [ -t 0 ] || { [ -r /dev/tty ] && (: </dev/tty) 2>/dev/null; }; }
|
|
# ask "question" default → the answer (read from the terminal even when this script came through a pipe)
|
|
ask() {
|
|
local reply=""
|
|
if have_tty; then
|
|
printf '%s ' "$1" >/dev/tty
|
|
read -r reply </dev/tty || reply=""
|
|
fi
|
|
printf '%s' "${reply:-$2}"
|
|
}
|
|
|
|
uninstall() {
|
|
if [ -f "$DESKTOP" ] && grep -q "^$MARK" "$DESKTOP"; then
|
|
rm -f "$DESKTOP"
|
|
rm -f "$HICOLOR/scalable/apps/$APP_ID.svg"
|
|
for n in 48 64 128 256; do rm -f "$HICOLOR/${n}x${n}/apps/$APP_ID.png"; done
|
|
command -v update-desktop-database >/dev/null && update-desktop-database "$APPS" 2>/dev/null || true
|
|
elif [ -f "$DESKTOP" ]; then
|
|
say "Left $DESKTOP alone: this installer didn't make it."
|
|
fi
|
|
rm -rf "$APPDIR"
|
|
say "Routine is removed."
|
|
say "Your routine, history and settings are still there, in case you come back:"
|
|
say " $DATA_DIR and ${XDG_CONFIG_HOME:-$HOME/.config}/routine"
|
|
say "(or wherever Settings → Data put them). Delete those folders yourself if you want them gone."
|
|
}
|
|
|
|
case "${1:-}" in
|
|
--uninstall|uninstall) uninstall; exit 0 ;;
|
|
-h|--help) sed -n '2,22p' "${BASH_SOURCE[0]:-/dev/null}" 2>/dev/null || say "See the top of install-linux.sh."; exit 0 ;;
|
|
"") ;;
|
|
*) die "unknown option $1 (try --uninstall)" ;;
|
|
esac
|
|
|
|
[ "$(uname -s)" = Linux ] || die "this is the Linux installer; on a Mac use install-mac.sh"
|
|
command -v tar >/dev/null || die "needs tar"
|
|
|
|
# ── 1. Python 3.10 or newer ──
|
|
PY="${ROUTINE_PYTHON:-$(command -v python3 || true)}"
|
|
# shellcheck source=/dev/null
|
|
DISTRO=" $( (. /etc/os-release && printf '%s %s' "${ID:-}" "${ID_LIKE:-}") 2>/dev/null || true) "
|
|
pkg_cmd() { # the command that installs $1 (a word per distro) here, or nothing
|
|
case "$DISTRO" in
|
|
*" fedora "*|*" rhel "*) printf 'sudo dnf install %s' "$1" ;;
|
|
*" debian "*|*" ubuntu "*) printf 'sudo apt install %s' "$2" ;;
|
|
*" arch "*) printf 'sudo pacman -S --needed %s' "$3" ;;
|
|
*) ;;
|
|
esac
|
|
}
|
|
if [ -z "$PY" ] || ! "$PY" -c 'import sys; sys.exit(sys.version_info < (3, 10))' 2>/dev/null; then
|
|
c="$(pkg_cmd python3 python3 python)"
|
|
die "Routine needs Python 3.10 or newer. ${c:+Install it with: $c and run this again.}"
|
|
fi
|
|
|
|
# ── 2. The app itself ──
|
|
mkdir -p "$APPDIR"
|
|
NEW="$APPDIR/src.new"
|
|
rm -rf "$NEW"
|
|
mkdir -p "$NEW"
|
|
SRC="${ROUTINE_SOURCE:-}"
|
|
if [ -z "$SRC" ]; then # run from a checkout (not through a pipe)? install that
|
|
here="$(dirname "${BASH_SOURCE[0]:-/nonexistent}")"
|
|
[ -f "$here/routine/__init__.py" ] && SRC="$(cd "$here" && pwd)"
|
|
fi
|
|
if [ -n "$SRC" ] && [ -d "$SRC" ]; then
|
|
say "Copying Routine from $SRC …"
|
|
tar -C "$SRC" --exclude=.git --exclude=__pycache__ --exclude=android/build -cf - . | tar -C "$NEW" -xf -
|
|
elif [ -n "$SRC" ]; then
|
|
tar -C "$NEW" --strip-components=1 -xzf "$SRC"
|
|
else
|
|
command -v curl >/dev/null || die "needs curl (or set ROUTINE_SOURCE to a downloaded copy)"
|
|
say "Downloading Routine …"
|
|
curl -fsSL "$ARCHIVE" | tar -C "$NEW" --strip-components=1 -xzf - || die "couldn't download $ARCHIVE"
|
|
fi
|
|
[ -f "$NEW/routine/__init__.py" ] || die "that doesn't look like Routine (no routine/__init__.py)"
|
|
VERSION="$(sed -n 's/^__version__ = "\(.*\)"/\1/p' "$NEW/routine/__init__.py")"
|
|
rm -rf "$APPDIR/src.old"
|
|
[ -d "$APPDIR/src" ] && mv "$APPDIR/src" "$APPDIR/src.old"
|
|
mv "$NEW" "$APPDIR/src"
|
|
rm -rf "$APPDIR/src.old"
|
|
|
|
# ── 3. Qt: the system's, the distribution's package, or a private copy ──
|
|
qt_ok() { (cd "$APPDIR/src" && "$1" -c 'import routine.qt.QtWidgets' 2>/dev/null); }
|
|
APP_PY=""
|
|
CHOICE="${ROUTINE_QT_INSTALL:-}"
|
|
if [ -x "$APPDIR/venv/bin/python" ] && [ "$CHOICE" != system ] && [ "$CHOICE" != distro ]; then
|
|
CHOICE=venv # installed with a private copy before: keep it (and update it)
|
|
elif [ -z "$CHOICE" ] && qt_ok "$PY"; then
|
|
CHOICE=system
|
|
fi
|
|
if [ -z "$CHOICE" ]; then
|
|
DCMD="$(pkg_cmd python3-pyside6 'python3-pyside6.qtwidgets python3-pyside6.qtnetwork python3-pyside6.qtmultimedia' pyside6)"
|
|
case "$DISTRO" in # only offer a package that exists here
|
|
*" debian "*|*" ubuntu "*) apt-cache show python3-pyside6.qtwidgets >/dev/null 2>&1 || DCMD="" ;;
|
|
esac
|
|
say ""
|
|
say "Routine needs PySide6 (Qt for Python), and this Python doesn't have it."
|
|
if [ -n "$DCMD" ]; then
|
|
say " 1) install your system's package: $DCMD (asks for your password)"
|
|
say " 2) download a private copy for Routine only (~250 MB, no password)"
|
|
a="$(ask 'Which one? [1/2, default 2]' 2)"
|
|
[ "$a" = 1 ] && CHOICE=distro || CHOICE=venv
|
|
else
|
|
say "Downloading a private copy for Routine only (~250 MB, no password needed)."
|
|
CHOICE=venv
|
|
fi
|
|
fi
|
|
case "$CHOICE" in
|
|
system)
|
|
qt_ok "$PY" || die "ROUTINE_QT_INSTALL=system, but $PY can't import PySide6 or PyQt6"
|
|
APP_PY="$PY" ;;
|
|
distro)
|
|
DCMD="${DCMD:-$(pkg_cmd python3-pyside6 'python3-pyside6.qtwidgets python3-pyside6.qtnetwork python3-pyside6.qtmultimedia' pyside6)}"
|
|
[ -n "$DCMD" ] || die "no package known for this distribution: run again and pick the private copy"
|
|
say "This will run: $DCMD"
|
|
a="$(ask 'Go ahead? [y/N]' n)"
|
|
case "$a" in y|Y|yes) $DCMD ;; *) die "stopped; nothing was installed with sudo. Run again to choose." ;; esac
|
|
qt_ok "$PY" || die "PySide6 still isn't importable by $PY; run again and pick the private copy"
|
|
APP_PY="$PY" ;;
|
|
venv)
|
|
if [ ! -x "$APPDIR/venv/bin/python" ]; then
|
|
"$PY" -m venv "$APPDIR/venv" 2>/dev/null || {
|
|
rm -rf "$APPDIR/venv"
|
|
c="$(pkg_cmd python3-virtualenv python3-venv python-virtualenv)"
|
|
die "Python can't make a private environment here. ${c:+Install that with: $c and run this again.}"
|
|
}
|
|
fi
|
|
say "Installing ${PINS[*]} into $APPDIR/venv …"
|
|
"$APPDIR/venv/bin/python" -m pip install --quiet --no-cache-dir --disable-pip-version-check "${PINS[@]}" ||
|
|
die "pip couldn't install ${PINS[*]} (it needs glibc 2.34+, e.g. Fedora 35+, Ubuntu 22.04+, Debian 12+)"
|
|
APP_PY="$APPDIR/venv/bin/python" ;;
|
|
*) die "ROUTINE_QT_INSTALL must be system, distro or venv" ;;
|
|
esac
|
|
qt_ok "$APP_PY" || die "Qt for Python still won't import with $APP_PY"
|
|
|
|
# ── 4. The launcher, the icon, the app grid ──
|
|
LAUNCHER="$APPDIR/routine"
|
|
cat >"$LAUNCHER" <<EOF
|
|
#!/bin/sh
|
|
# Starts Routine (made by install-linux.sh; run that again to update). Messages from the last start
|
|
# go to $STATE_HOME/routine/launch.log; errors to errors.log beside it.
|
|
mkdir -p "$STATE_HOME/routine"
|
|
cd "$APPDIR/src" || exit 1
|
|
exec "$APP_PY" -m routine "\$@" 2>"$STATE_HOME/routine/launch.log"
|
|
EOF
|
|
chmod +x "$LAUNCHER"
|
|
|
|
mkdir -p "$APPS" "$HICOLOR/scalable/apps"
|
|
if [ -f "$DESKTOP" ] && ! grep -q "^$MARK" "$DESKTOP" && [ "${ROUTINE_FORCE:-}" != 1 ]; then
|
|
a="$(ask "There's already a Routine in the app grid ($DESKTOP), made some other way. Replace it? [y/N]" n)"
|
|
case "$a" in y|Y|yes) ;; *) say "Kept the existing app grid entry. Start this copy with: $LAUNCHER"; exit 0 ;; esac
|
|
fi
|
|
cp "$APPDIR/src/shared/icon.svg" "$HICOLOR/scalable/apps/$APP_ID.svg"
|
|
for n in 48 64 128 256; do # fixed sizes too, for whatever doesn't read SVG
|
|
mkdir -p "$HICOLOR/${n}x${n}/apps"
|
|
(cd "$APPDIR/src" && QT_QPA_PLATFORM=offscreen "$APP_PY" -c '
|
|
import sys
|
|
from routine.qt.QtGui import QGuiApplication, QIcon
|
|
a = QGuiApplication(sys.argv)
|
|
sys.exit(0 if QIcon(sys.argv[1]).pixmap(int(sys.argv[2]), int(sys.argv[2])).save(sys.argv[3]) else 1)' \
|
|
shared/icon.svg "$n" "$HICOLOR/${n}x${n}/apps/$APP_ID.png" 2>/dev/null) || true
|
|
done
|
|
cat >"$DESKTOP" <<EOF
|
|
[Desktop Entry]
|
|
Type=Application
|
|
Name=Routine
|
|
Comment=The day's routine, ticked off as you go
|
|
Exec="$LAUNCHER"
|
|
Icon=$APP_ID
|
|
Terminal=false
|
|
Categories=Utility;
|
|
StartupWMClass=$APP_ID
|
|
StartupNotify=true
|
|
$MARK
|
|
EOF
|
|
command -v update-desktop-database >/dev/null && update-desktop-database "$APPS" 2>/dev/null || true
|
|
command -v gtk-update-icon-cache >/dev/null && gtk-update-icon-cache -q -t -f "$HICOLOR" 2>/dev/null || true
|
|
|
|
say ""
|
|
say "Routine $VERSION is installed. Find it in your apps (search for Routine), or run: $LAUNCHER"
|
|
say "Update: run the same command again. Remove: … | bash -s -- --uninstall (your data stays)."
|
|
say "Your routine and history will be kept in $DATA_DIR (Settings → Data can move them)."
|