From 4740db75be3bdb2738523517a1b68fa9bc5c9ac3 Mon Sep 17 00:00:00 2001 From: Juergen Kellerer Date: Sun, 22 Aug 2021 19:20:15 +0200 Subject: [PATCH] nfpms config for linux packages (apk,deb,rpm) --- .goreleaser.yml | 38 +++++++++++++++++++++++++++++++++++ contrib/posix/post-install.sh | 38 +++++++++++++++++++++++++++++++++++ contrib/posix/profiles.conf | 2 +- 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 contrib/posix/post-install.sh diff --git a/.goreleaser.yml b/.goreleaser.yml index acbd3c50..8a36a5e1 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -125,3 +125,41 @@ brews: system "#{bin}/resticprofile", "backup", "testfile" system "#{bin}/resticprofile", "restore", "latest", "-t", "#{testpath}/restore" assert compare_file "testfile", "#{testpath}/restore/testfile" + +nfpms: + - + builds: + - resticprofile_targz + formats: + - apk + - deb + - rpm + vendor: "creativeprojects" + homepage: "https://github.com/creativeprojects" + maintainer: "fred@creativeprojects.tech" + description: "Configuration profiles for restic backup" + license: "GPL-3.0-only" + file_name_template: "{{.ProjectName}}_{{.Version}}-{{.Arch}}" + replacements: + amd64: 64bit + 386: 32bit + arm: ARM + arm64: ARM64 + linux: Linux + dependencies: + - restic + bindir: "/usr/local/bin" + scripts: + postinstall: "contrib/posix/post-install.sh" + contents: + - { type: config, src: contrib/posix/profiles.conf, dst: /etc/resticprofile/profiles.conf.dist } + - { type: config, src: contrib/posix/conf.d/check.conf, dst: /etc/resticprofile/conf.d/check.conf.dist } + - { type: config, src: contrib/posix/conf.d/hooks.conf, dst: /etc/resticprofile/conf.d/hooks.conf.dist } + - { type: config, src: contrib/posix/conf.d/metrics.conf, dst: /etc/resticprofile/conf.d/metrics.conf.dist } + - { type: config, src: contrib/posix/conf.d/prune.conf, dst: /etc/resticprofile/conf.d/prune.conf.dist } + - { type: config, src: contrib/posix/conf.d/repository.conf, dst: /etc/resticprofile/conf.d/repository.conf.dist } + - { type: config, src: contrib/posix/profiles.d/fs-snapshot.yaml.sample, dst: /etc/resticprofile/profiles.d/fs-snapshot.yaml.sample } + - { type: config, src: contrib/posix/profiles.d/system.toml, dst: /etc/resticprofile/profiles.d/system.toml.dist } + - src: contrib/systemd/resticprofile-send-error.sh + dst: /usr/local/bin/resticprofile-send-error + file_info: { mode: 0640, owner: root, group: root } diff --git a/contrib/posix/post-install.sh b/contrib/posix/post-install.sh new file mode 100755 index 00000000..c52aaf64 --- /dev/null +++ b/contrib/posix/post-install.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env sh +set -e + +CONFIG_PATH="/etc/resticprofile" +SECRET_FILE="${CONFIG_PATH}/conf.d/default-repository.secret" + +# Fix permissions (only root may edit and read since password +# & tokens can be in any of the files) +if [ -d "${CONFIG_PATH}" ] ; then + chown -R root:root "${CONFIG_PATH}" + chmod -R 0640 "${CONFIG_PATH}" +else + echo "config path (${CONFIG_PATH}) not found" + exit 1 +fi + +# Check installation +if [ ! -e "$(which resticprofile)" ] || ! resticprofile version ; then + echo "resticprofile not found or not executable" + exit 1 +fi + +# Generate default-repo secret (if missing) +if [ ! -f "${SECRET_FILE}" ] ; then + echo "Generating ${SECRET_FILE}" + resticprofile random-key > "${SECRET_FILE}" +fi + +# Unwrap dist files (if target is missing) +cd "${CONFIG_PATH}" +for file in conf.d/*.dist profiles.d/*.dist ; do + target_file="$(dirname "${file}")/$(basename -s ".dist" "${file}")" + if [ -e "${target_file}" ] ; then + echo "Skipping ${target_file}. File already exists" + else + mv -f "${file}" "${target_file}" + fi +done diff --git a/contrib/posix/profiles.conf b/contrib/posix/profiles.conf index 5fe96997..354b197f 100644 --- a/contrib/posix/profiles.conf +++ b/contrib/posix/profiles.conf @@ -180,4 +180,4 @@ inherit = "default" [base.mount] # Copying "host" and "tags" block to identify snapshots to mount {{template "conf:default-backup-host" .}} -{{template "conf:default-backup-tags" .}} \ No newline at end of file +{{template "conf:default-backup-tags" .}}