main/postmarketos-mvcfg: new package (MR 1713)

Add scripts to move configs from legacy packaging, as described at:
https://postmarketos.org/mvcfg
This commit is contained in:
Oliver Smith 2020-11-12 10:08:56 +01:00
parent c108a5a8d1
commit 4d6a1a2458
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
4 changed files with 123 additions and 0 deletions

View file

@ -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')
"

View file

@ -0,0 +1,22 @@
# Maintainer: Oliver Smith <ollieparanoid@postmarketos.org>
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"

View file

@ -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"

View file

@ -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"