diff options
author | eoli3n | 2020-05-11 12:01:08 +0200 |
---|---|---|
committer | eoli3n | 2020-05-11 12:01:08 +0200 |
commit | 51b4f16186351174d0dcd43504e2d62a454cb8e0 (patch) | |
tree | 4446c75d6aa1e781b8cbd3fd39681b9266b10b93 | |
download | aur-51b4f16186351174d0dcd43504e2d62a454cb8e0.tar.gz |
added first files
-rw-r--r-- | .SRCINFO | 18 | ||||
-rw-r--r-- | 10-zectl-pre.hook | 11 | ||||
-rw-r--r-- | INSTALL | 13 | ||||
-rw-r--r-- | PKGBUILD | 23 | ||||
-rw-r--r-- | README.md | 65 | ||||
-rw-r--r-- | UNLICENSE | 24 | ||||
-rwxr-xr-x | zectl-prune | 99 |
7 files changed, 253 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..f14b84408768 --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,18 @@ +pkgbase = zectl-pacman-hook + pkgdesc = Create and prune zectl boot environments before any pacman command + pkgver = 0.1.0 + pkgrel = 1 + url = https://github.com/eoli3n/zectl-pacman-hook + install = INSTALL + arch = any + license = UNLICENSE + depends = zectl + source = 10-zectl-pre.hook + source = zectl-prune + source = UNLICENSE + sha256sums = de9a144e6cda1911395b6491f2e83af0089a72e9eab92199d489b29919d76c2f + sha256sums = b38b0b2fca33ce64d5c1e713feb3bd7d3a0e85fa8d5c4c5220edefc2a63440da + sha256sums = d3c4f1607c9488b22732511b83e6f6173d82499c0678c899666ca12c36517f72 + +pkgname = zectl-pacman-hook + diff --git a/10-zectl-pre.hook b/10-zectl-pre.hook new file mode 100644 index 000000000000..69852b4dedd6 --- /dev/null +++ b/10-zectl-pre.hook @@ -0,0 +1,11 @@ +[Trigger] +Operation = Remove +Operation = Install +Operation = Upgrade +Type = Package +Target = * + +[Action] +Description = Create a boot environment +When = PreTransaction +Exec = /usr/bin/bash -c 'if [[ $(/usr/bin/zectl get -H pacmanhook) =~ yes ]];then /usr/share/libalpm/scripts/zectl-prune ; fi' diff --git a/INSTALL b/INSTALL new file mode 100644 index 000000000000..41ad8eb59943 --- /dev/null +++ b/INSTALL @@ -0,0 +1,13 @@ +post_install() { + + # Set default options + zectl set pacmanhook-prunecount=1 + zectl set pacmanhook="yes" + + cat << EOF +Please set number of version to keep, default is 1 + + $ sudo zectl set pacmanhook-prunecount=5 + +EOF +} diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..438ce562b734 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,23 @@ +# Maintainer: Jonathan Kirszling <jkirsz@gmail.com> +# Info: https://github.com/johnramsden/zectl/issues/16 +pkgname=zectl-pacman-hook +pkgrel=1 +pkgver=0.1.0 +pkgdesc="Create and prune zectl boot environments before any pacman command" +arch=('any') +url="https://github.com/eoli3n/$pkgname" +license=('UNLICENSE') +depends=('zectl') +install="INSTALL" +source=("10-zectl-pre.hook" + "zectl-prune" + "UNLICENSE") +sha256sums=("de9a144e6cda1911395b6491f2e83af0089a72e9eab92199d489b29919d76c2f" +"b38b0b2fca33ce64d5c1e713feb3bd7d3a0e85fa8d5c4c5220edefc2a63440da" +"d3c4f1607c9488b22732511b83e6f6173d82499c0678c899666ca12c36517f72") + +package() { + install -Dm644 '10-zectl-pre.hook' "${pkgdir}/usr/share/libalpm/hooks/10-zectl-pre.hook" + install -Dm755 'zectl-prune' "${pkgdir}/usr/share/libalpm/scripts/zectl-prune" + install -Dm644 'UNLICENSE' "${pkgdir}/usr/share/licenses/${pkgname}/UNLICENSE" +} diff --git a/README.md b/README.md new file mode 100644 index 000000000000..d33e94fb6f8f --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +### zectl-pacman-hook + +It will create a boot environment prefixed with ``pacmanhook`` with ``zectl`` at each use of pacman. By default, it keeps only 1 boot environment, each use of pacman will erase previously created boot environment. + +```bash +$ LANG=C sudo pacman -S sl +warning: sl-5.02-5 is up to date -- reinstalling +resolving dependencies... +looking for conflicting packages... + +Packages (1) sl-5.02-5 + +Total Installed Size: 0.02 MiB +Net Upgrade Size: 0.00 MiB + +:: Proceed with installation? [Y/n] y +(1/1) checking keys in keyring [------------------------] 100% +(1/1) checking package integrity [------------------------] 100% +(1/1) loading package files [------------------------] 100% +(1/1) checking for file conflicts [------------------------] 100% +(1/1) checking available disk space [------------------------] 100% +:: Running pre-transaction hooks... +(1/1) Create a boot environment +• Destroyed pacmanhook-20200511T111356 +• Created pacmanhook-20200511T111422 +:: Processing package changes... +(1/1) reinstalling sl [------------------------] 100% +:: Running post-transaction hooks... +(1/1) Arming ConditionNeedsUpdate... +``` + +### Installation + +Install aur package [zectl-pacman-hook]() + +### Configuration + +To keep more than 1 boot environment, use: +``` +zectl set pacmanhook-prunecount=5 +``` + +Be aware of your ``/boot`` size limitation. +To know ~ max prunecount you could set, try: +```bash +boot_size=$(du /boot | awk '{print $1}') +efi_size=$(df /efi --output=avail | sed '1d') +echo "$efi_size / $boot_size" | bc +``` + +We discuss about increasing max number of boot envs here: +https://github.com/johnramsden/zectl/issues/19 + +To disable the hook, use: +``` +zectl set pacmanhook="no" +``` + +### Manual install +``` +git clone https://github.com/eoli3n/zectl-pacman-hook +cd zectl-pacman-hook +makepkg -c +makepkg -si +``` diff --git a/UNLICENSE b/UNLICENSE new file mode 100644 index 000000000000..7836f7f7a79f --- /dev/null +++ b/UNLICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/> diff --git a/zectl-prune b/zectl-prune new file mode 100755 index 000000000000..e4dacd1391d6 --- /dev/null +++ b/zectl-prune @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# +# zectl-prune is used by zectl-hook to rotate Boot Environments + +# Tests + +if [ "$EUID" -ne 0 ] + then echo "Please run as root" + exit +fi + +# Vars + +# Set where zectl is installed +PATH="$PATH:/usr/bin" +BIN=/usr/bin/zectl +# Get current script name +FILENAME="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")" +# String to prepend to boot env name +PREFIX="pacmanhook" + +# Functions + +print () { + echo -e "\033[1m• $1\033[0m" +} + +usage(){ + echo "Usage: $FILENAME [options]" + echo "-h : afficher l'aide" + exit +} + +# Get a value from zectl +get_value () { + value=$("$BIN" get -H "$1" | awk '{print $2}') + if [[ $value =~ \t- ]] + then + return 1 + else + echo "$value" + fi + +} + +# Create a boot env prepended with prefix +zectl_create () { + bename="$PREFIX-$(date +'%Y%m%dT%H%M%S')" + $BIN create "$bename" && print "Created $bename" +} + +# List boot env by prefix, and omit booted|activated +zectl_list () { + # TOFIX: sort https://github.com/johnramsden/zectl/issues/18 + # Here: sorting on the be name which contains date + $BIN list -H | grep $PREFIX | grep -Ev '\ N\ |\ NR\ |\ R\ ' | sort -k1 +} + +# Remove latest prefixed boot env +zectl_purge () { + latest=$(zectl_list | head -n1 | grep "$PREFIX" | awk '{print $1}') + zectl destroy "$latest" && print "Destroyed $latest" +} + +# Args + +while getopts "h" option; do + case "${option}" in + h) + usage + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) + +# Main + +# Get how many boot env to keep from zectl +prune_count=$(get_value pacmanhook-prunecount) + +# Test if value is numeric +if [[ $prune_count =~ ^[0-9]+$ ]] +then + + # If keep number is not reach, create a boot env + if [[ $(zectl_list | wc -l) -lt "$prune_count" ]] + then + zectl_create + # Else remove the latest and create a boot env + else + zectl_purge + zectl_create + fi +else + echo 'error: please run "zectl set pacmanhook-prunecount=X" where "X" is the number of boot environment to keep when rotating.' +fi |