Something went wrong. Try again.
An editor for documents (HTML, Markdown, Djot) and data files (JSON, YAML, TOML, figl)
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149#!/usr/bin/env bash# Install a development build of Flower for this user, on Linux: the binary,# the sample it opens on, its icon and its desktop entry.## scripts/install-linux.sh # build (debug), then install# scripts/install-linux.sh --release # the release profile# scripts/install-linux.sh --no-build # install what target/ already holds# scripts/install-linux.sh --default # …and open these files with Flower## What goes where, under $PREFIX (default ~/.local):## share/flower/Flower the binary, stripped# share/flower/resources/ Sample.md and its pictures, side by side,# where the app looks for them: beside itself# bin/flower-app a link to the binary. Not `flower`, which# is the terminal data editor's name# share/icons/hicolor/scalable/apps/org.diaryx.flower.svg the leaf# share/applications/org.diaryx.flower.desktop# share/mime/packages/org.diaryx.flower.xml Djot's and figl's types,# which the desktop's database does not have## `--default` makes Flower the user's default for Markdown, Djot, JSON, YAML,# TOML and figl (`xdg-mime default`, which writes ~/.config/mimeapps.list). It# is asked for, never assumed: without it the entry only offers Flower in# Open With. HTML is left to the browser either way.## The desktop entry is named for the app id every window carries# (`platform::APP_ID` in apps/flower), which is how a dock finds the icon for# a window. Run again to update: every file is replaced.## The build goes through scripts/cargo.sh: corgi where it is installed.set -euo pipefail
cd "$(dirname "$0")/.."
profile=debugbuild=1default=0for arg in "$@"; do case $arg in --release) profile=release ;; --no-build) build=0 ;; --default) default=1 ;; -h | --help) sed -n '2,/^set -euo/p' "$0" | sed '$d; s/^# \{0,1\}//' exit 0 ;; *) echo "install-linux.sh: unknown argument $arg" >&2 exit 2 ;; esacdone
prefix=${PREFIX:-$HOME/.local}id=org.diaryx.flower# What Flower opens by default when asked to: the desktop's own types for# Markdown, JSON, YAML and TOML, and the two declared below.types=(text/markdown text/x-markdown application/json application/yaml application/x-yaml application/toml text/x-djot application/x-figl)
if ((build)); then flags=() [[ $profile == release ]] && flags+=(--release) echo "▸ Building Flower ($profile)…" scripts/cargo.sh build -p flower-app "${flags[@]}"fi
binary=target/$profile/Flower[[ -x $binary ]] || { echo "install-linux.sh: no $binary; build first, or drop --no-build" >&2 exit 1}
home=$prefix/share/flowerecho "▸ Installing to $prefix…"rm -rf "$home/resources"install -d "$home/resources" "$prefix/bin" \ "$prefix/share/icons/hicolor/scalable/apps" "$prefix/share/applications" \ "$prefix/share/mime/packages"# To a new name and renamed over, so a Flower that is running keeps its file.install -s -m755 "$binary" "$home/Flower.new"mv -f "$home/Flower.new" "$home/Flower"install -m644 apps/flower/resources/Sample.md apps/flower/resources/Media/* "$home/resources/"ln -sfn "$home/Flower" "$prefix/bin/flower-app"install -m644 apps/flower/resources/leaf.icon/Assets/leaf.svg \ "$prefix/share/icons/hicolor/scalable/apps/$id.svg"
cat >"$prefix/share/applications/$id.desktop" <<DESKTOP[Desktop Entry]Type=ApplicationName=FlowerGenericName=Document and Data EditorComment=Edit Markdown, Djot and HTML documents, and JSON, YAML and TOML dataExec=$prefix/bin/flower-app %FIcon=$idTerminal=falseCategories=Office;TextEditor;Keywords=markdown;djot;html;json;yaml;toml;frontmatter;editor;MimeType=$(printf '%s;' "${types[@]}")StartupWMClass=$idDESKTOP
# Djot and figl, which shared-mime-info has no types for: without one, a# `.dj` or a `.figl` is plain text, and whatever opens plain text opens it.cat >"$prefix/share/mime/packages/$id.xml" <<'MIME'<?xml version="1.0" encoding="UTF-8"?><mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="text/x-djot"> <comment>Djot document</comment> <sub-class-of type="text/plain"/> <glob pattern="*.dj"/> <glob pattern="*.djot"/> </mime-type> <mime-type type="application/x-figl"> <comment>figl data</comment> <sub-class-of type="text/plain"/> <glob pattern="*.figl"/> </mime-type></mime-info>MIME
# The desktop's indexes, where it keeps them.if command -v update-mime-database >/dev/null 2>&1; then update-mime-database "$prefix/share/mime" >/dev/null 2>&1 || truefiif command -v update-desktop-database >/dev/null 2>&1; then update-desktop-database -q "$prefix/share/applications" || truefiif command -v gtk-update-icon-cache >/dev/null 2>&1 \ && [[ -f $prefix/share/icons/hicolor/index.theme ]]; then gtk-update-icon-cache -q -t "$prefix/share/icons/hicolor" || truefi
if ((default)); then if command -v xdg-mime >/dev/null 2>&1; then xdg-mime default "$id.desktop" "${types[@]}" echo "▸ Flower is the default for: ${types[*]}" else echo "install-linux.sh: no xdg-mime, so no defaults were set" >&2 fifi
echo "✓ Flower $profile build installed: $prefix/bin/flower-app"case ":$PATH:" in*":$prefix/bin:"*) ;;*) echo " ($prefix/bin is not on PATH)" ;;esac