From 4d6a1a2458657fc8cdaa0603f863fb47b8277361 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Thu, 12 Nov 2020 10:08:56 +0100 Subject: [PATCH] main/postmarketos-mvcfg: new package (MR 1713) Add scripts to move configs from legacy packaging, as described at: https://postmarketos.org/mvcfg --- .gitlab-ci/shellcheck.sh | 1 + main/postmarketos-mvcfg/APKBUILD | 22 +++++ .../postmarketos-mvcfg-package.sh | 17 ++++ .../postmarketos-mvcfg-pre-upgrade.sh | 83 +++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 main/postmarketos-mvcfg/APKBUILD create mode 100644 main/postmarketos-mvcfg/postmarketos-mvcfg-package.sh create mode 100644 main/postmarketos-mvcfg/postmarketos-mvcfg-pre-upgrade.sh diff --git a/.gitlab-ci/shellcheck.sh b/.gitlab-ci/shellcheck.sh index 4940b780c..2be92422a 100755 --- a/.gitlab-ci/shellcheck.sh +++ b/.gitlab-ci/shellcheck.sh @@ -36,6 +36,7 @@ sh_files=" $(find . -name '*.trigger') $(find . -path './main/devicepkg-dev/*.sh') + $(find . -path './main/postmarketos-mvcfg/*.sh') $(find . -path '.gitlab-ci/*.sh') " diff --git a/main/postmarketos-mvcfg/APKBUILD b/main/postmarketos-mvcfg/APKBUILD new file mode 100644 index 000000000..c18ed896b --- /dev/null +++ b/main/postmarketos-mvcfg/APKBUILD @@ -0,0 +1,22 @@ +# Maintainer: Oliver Smith +pkgname=postmarketos-mvcfg +pkgver=1 +pkgrel=0 +pkgdesc="Move configs from legacy packaging" +url="https://postmarketos.org/mvcfg" +arch="noarch" +license="GPL-3.0-or-later" +options="!check !tracedeps pmb:cross-native" +source=" + postmarketos-mvcfg-pre-upgrade.sh + postmarketos-mvcfg-package.sh + " + +package() { + for script in pre-upgrade package; do + install -Dm755 "postmarketos-mvcfg-$script.sh" \ + "$pkgdir/usr/bin/postmarketos-mvcfg-$script" + done +} +sha512sums="58affac657b588a8a1f3370aa649cbc4077206cc237a6180b9533e85108394eedbb10e4b71bb8aecafdbdfc0de820b116b8baa9a6c3fe44272da06a9a5d11d52 postmarketos-mvcfg-pre-upgrade.sh +82ae4ccc8de87acf1c40e8c6bfb9bd1d0e7eff11055e231000304000dec87de04dc988125aad8a60a8266a21b90da2e14c9605d29b0748ad3cbf5a92dd00910a postmarketos-mvcfg-package.sh" diff --git a/main/postmarketos-mvcfg/postmarketos-mvcfg-package.sh b/main/postmarketos-mvcfg/postmarketos-mvcfg-package.sh new file mode 100644 index 000000000..d12d3956d --- /dev/null +++ b/main/postmarketos-mvcfg/postmarketos-mvcfg-package.sh @@ -0,0 +1,17 @@ +#!/bin/sh -e + +pkgdir="$1" +dirname="$2" + +if [ -z "$dirname" ] || ! [ -d "$pkgdir" ]; then + echo "usage:" + # shellcheck disable=SC2016 + echo ' postmarketos-mvcfg-package "$pkgname" "$pkgdir"' + echo "more information:" + echo " https://postmarketos.org/mvcfg" + exit 1 +fi + +# Create "done" file, so postmarketos-mvcfg-pre-upgrade doesn't do anything +mkdir -p "$pkgdir/etc/postmarketos-mvcfg/done" +touch "$pkgdir/etc/postmarketos-mvcfg/done/$dirname" diff --git a/main/postmarketos-mvcfg/postmarketos-mvcfg-pre-upgrade.sh b/main/postmarketos-mvcfg/postmarketos-mvcfg-pre-upgrade.sh new file mode 100644 index 000000000..e427e1f54 --- /dev/null +++ b/main/postmarketos-mvcfg/postmarketos-mvcfg-pre-upgrade.sh @@ -0,0 +1,83 @@ +#!/bin/sh +# Move all configs that were created/modified with legacy methods in +# post-install scripts. + +if [ "$#" -lt 2 ]; then + echo "usage:" + echo " postmarketos-mvcfg-pre-upgrade dirname cfg [cfg ...]" + echo "example:" + echo " postmarketos-mvcfg-pre-upgrade \\" + echo " postmarketos-base \\" + echo " /etc/issue \\" + echo " /etc/fstab" + echo "more information:" + echo " https://postmarketos.org/mvcfg" + exit 1 +fi + +# Skip if "done" file exists. This is created in package() with +# postmarketos-mvcfg-package, so this script doesn't do anything if the package +# installed at pre-upgrade time is already using properly packaged configs. +dirname="$1" +if [ -e "/etc/postmarketos-mvcfg/done/$dirname" ]; then + exit 0 +fi + +# Only act on existing files +shift +cfgs_found="" +for i in "$@"; do + if [ -e "$i" ]; then + cfgs_found="$cfgs_found $i" + fi +done + +if [ -n "$cfgs_found" ]; then + # Create non-existing backupdir + backupdir="/etc/postmarketos-mvcfg/backup/$dirname" + while [ -d "$backupdir" ]; do + backupdir="${backupdir}_" + done + mkdir -p "$backupdir" + + # Copy all configs first + for i in $cfgs_found; do + # Generate non-existing target path + # flatpath: /etc/issue -> etc-issue + flatpath="$(echo "$i" | sed s./.-.g | cut -d- -f2-)" + target="$backupdir/$flatpath" + while [ -e "$target" ]; do + target="${target}_" + done + + cp -a "$i" "$target" + done + + # Remove configs + for i in $cfgs_found; do + rm "$i" + done + + # List moved configs + echo " *" + echo " * These configs were created with legacy packaging methods:" + for i in $cfgs_found; do + echo " * $i" + done + echo " *" + echo " * In order to replace them with properly packaged configs," + echo " * the old versions (which you might have adjusted manually)" + echo " * were moved to:" + echo " * $backupdir" + echo " *" + echo " * If you did not manually adjust these configs, you can ignore" + echo " * this message." + echo " *" + echo " * More information: https://postmarketos.org/mvcfg" + echo " *" +fi + +# Make sure that the "done" file exists, even if the packager forgot to call +# 'postmarketos-mvcfg-package' in package() of the APKBUILD. +mkdir -p "/etc/postmarketos-mvcfg/done" +touch "/etc/postmarketos-mvcfg/done/$dirname"