mirror of
https://github.com/narrrl/proton-drive-linux.git
synced 2026-11-17 17:55:03 +01:00
feat(packaging): an installable release tarball for immutable distributions (#99)
The release .tar.gz held the four binaries and their translations only, and the service unit pointed at /usr/bin/pdfs, so it was no install on its own. It now carries a /usr-like tree (bin, share, the user unit, the tray's autostart entry) and install.sh, which installs it into ~/.local without root: - checks the libraries with ldd and names the packages to install per distribution, and that fusermount3 is there and setuid; - refuses to install next to a package of the client; - rewrites Exec= and ExecStart= to absolute paths, since ~/.local/bin is often not on a session's PATH; - keeps a manifest, removes what an older version left, restarts a running service on update, and --uninstall leaves settings alone. packaging/tarball/build.sh lays the tarball out and test.sh installs, updates and uninstalls it in a throwaway home; the release job runs both, CI runs shellcheck on them. The app looks for its translations in share/locale beside its own bin directory and starts the tray from there, so nothing needs PDFS_LOCALEDIR or the PATH. The -bin AUR package takes every file from the new tarball instead of raw.githubusercontent.com. INSTALL.md documents the tarball and layering the COPR package on Fedora Atomic.
This commit is contained in:
1 parent
7e0d7d020e
commit
a7baf2313c
12 files changed
+462
-75
No files matched your search
@@ -344,7 +344,15 @@ fn present_window(app: &adw::Application) {
|
||||
|
||||
/// Spawn the tray icon process in the background.
|
||||
pub(crate) fn spawn_tray() {
|
||||
match Command::new("pdfs-tray").spawn() {
|
||||
// The tray installed next to this app, as the tray finds the app; the
|
||||
// bare name for a PATH install. An install into ~/.local is often not on
|
||||
// the PATH of a desktop session.
|
||||
let tray = std::env::current_exe()
|
||||
.ok()
|
||||
.and_then(|p| p.parent().map(|d| d.join("pdfs-tray")))
|
||||
.filter(|p| p.exists())
|
||||
.unwrap_or_else(|| PathBuf::from("pdfs-tray"));
|
||||
match Command::new(&tray).spawn() {
|
||||
Ok(child) => {
|
||||
tracing::info!("spawned `pdfs-tray`");
|
||||
pdfs_core::opener::reap(child);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
use gettextrs::LocaleCategory;
|
||||
use pdfs_core::config::AppDirs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// The gettext text domain, matching `po/pdfs.pot` and the installed `.mo` name.
|
||||
pub(crate) const DOMAIN: &str = "pdfs";
|
||||
@@ -53,14 +54,11 @@ pub(crate) fn init() {
|
||||
if let Some(code) = language {
|
||||
apply_language(&code);
|
||||
}
|
||||
let dir = std::env::var(LOCALEDIR_ENV)
|
||||
.ok()
|
||||
.filter(|dir| !dir.is_empty())
|
||||
.unwrap_or_else(|| {
|
||||
option_env!("PDFS_LOCALEDIR")
|
||||
.unwrap_or(DEFAULT_LOCALEDIR)
|
||||
.to_string()
|
||||
});
|
||||
let dir = locale_dir(
|
||||
std::env::var(LOCALEDIR_ENV).ok(),
|
||||
option_env!("PDFS_LOCALEDIR"),
|
||||
std::env::current_exe().ok(),
|
||||
);
|
||||
if let Err(e) = gettextrs::bindtextdomain(DOMAIN, dir) {
|
||||
tracing::warn!("bindtextdomain failed: {e}");
|
||||
}
|
||||
@@ -73,6 +71,33 @@ pub(crate) fn init() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the catalogs are: `$PDFS_LOCALEDIR`, then the directory the build
|
||||
/// named, then `share/locale` beside the `bin` directory the program runs
|
||||
/// from when that holds a catalog of ours, then [`DEFAULT_LOCALEDIR`].
|
||||
///
|
||||
/// The third is for an install outside `/usr`, such as the release tarball's
|
||||
/// `install.sh` into `~/.local`: its programs find their translations without
|
||||
/// a wrapper setting the variable.
|
||||
fn locale_dir(env: Option<String>, build: Option<&str>, exe: Option<PathBuf>) -> PathBuf {
|
||||
if let Some(dir) = env.filter(|dir| !dir.is_empty()) {
|
||||
return PathBuf::from(dir);
|
||||
}
|
||||
if let Some(dir) = build {
|
||||
return PathBuf::from(dir);
|
||||
}
|
||||
let beside = exe
|
||||
.as_deref()
|
||||
.and_then(Path::parent)
|
||||
.and_then(Path::parent)
|
||||
.map(|prefix| prefix.join("share/locale"))
|
||||
.filter(|dir| {
|
||||
LANGUAGES
|
||||
.iter()
|
||||
.any(|(code, _)| dir.join(code).join("LC_MESSAGES/pdfs.mo").is_file())
|
||||
});
|
||||
beside.unwrap_or_else(|| PathBuf::from(DEFAULT_LOCALEDIR))
|
||||
}
|
||||
|
||||
/// The iso-codes text domain that translates ISO 3166-1 country names.
|
||||
const ISO_3166_DOMAIN: &str = "iso_3166-1";
|
||||
|
||||
@@ -234,6 +259,32 @@ fn fill(template: &str, args: &[(&str, &str)]) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_catalogs_are_found_beside_an_install_outside_usr() {
|
||||
let prefix = std::env::temp_dir().join(format!("pdfs-locale-{}", std::process::id()));
|
||||
let mo = prefix.join("share/locale/de/LC_MESSAGES/pdfs.mo");
|
||||
std::fs::create_dir_all(mo.parent().unwrap()).unwrap();
|
||||
std::fs::write(&mo, b"").unwrap();
|
||||
let exe = Some(prefix.join("bin/pdfs-app"));
|
||||
|
||||
assert_eq!(
|
||||
locale_dir(None, None, exe.clone()),
|
||||
prefix.join("share/locale")
|
||||
);
|
||||
// The variable and the build's own choice still win.
|
||||
assert_eq!(
|
||||
locale_dir(Some("/x".into()), Some("/y"), exe.clone()),
|
||||
PathBuf::from("/x")
|
||||
);
|
||||
assert_eq!(locale_dir(None, Some("/y"), exe), PathBuf::from("/y"));
|
||||
// A prefix without our catalogs falls back to the system's.
|
||||
assert_eq!(
|
||||
locale_dir(None, None, Some(PathBuf::from("/nonexistent/bin/pdfs-app"))),
|
||||
PathBuf::from(DEFAULT_LOCALEDIR)
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(&prefix);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fill_replaces_named_placeholders_in_any_order() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in new issue
Block a user