commit 05a8ff033bb79b107b5f5812db7d7f46b0549545
parent 434374c57fc499f47b86d92a3bdfdc53bede7ac3
Author: ccx <ccx@te2000.cz>
Date: Thu, 7 Mar 2024 16:05:46 +0000
Fix argument handling
Diffstat:
M | postinstall | | | 77 | +++++++++++++++++++++++++++++++++++++++++++++-------------------------------- |
1 file changed, 45 insertions(+), 32 deletions(-)
diff --git a/postinstall b/postinstall
@@ -27,6 +27,12 @@ die111() { # 111: system call failed
-() {
"$@" || die_ret $? "Command failed: $*"
}
+fatal100() {
+ die_ret 100 "Fatal: ${(qqq)this_command:t}: $@"
+}
+fatal111() {
+ die_ret 111 "Fatal: ${(qqq)this_command:t}: $@"
+}
# modules
- zmodload -F zsh/stat b:zstat
@@ -36,8 +42,8 @@ die111() { # 111: system call failed
# functions
link_changed() {
local prev cur
- prev=${${:-$prev_version/$1}:P}
- post=${${:-$current/$1}:P}
+ prev=${${:-$prev_env/$1}:P}
+ post=${${:-$current_env/$1}:P}
[[ "$pre" != "$post" ]]
}
@@ -92,10 +98,10 @@ setup_containers() {
setup_fileset() {
local -a rsync=(
rsync
- -aA
+ -a # TODO compile rsync with ACL support
--delete
--log-format=$'%i\t%B\t%U:%G\t%M\t%l\t%n'
- --filter='merge conf/postinstall.rsfilter'
+ --filter="merge $current/conf/postinstall.rsfilter"
--filter='- *'
)
$rsync --delete-excluded --log-file $SETUP_DIR/rsync.log.get / $SETUP_DIR/files.pre/ || return $?
@@ -119,9 +125,9 @@ postinstall() {
- cd $current
typeset -g SETUP_DIR
if (( $# )); then
- SETUP_DIR=$versions/postinstall/$EPOCHSECONDS.$this_version
+ SETUP_DIR=$versions/postinstall/$EPOCHSECONDS.${current_env:t}
else
- SETUP_DIR=$versions/postinstall/$EPOCHSECONDS.$this_version..$prev_version:t
+ SETUP_DIR=$versions/postinstall/$EPOCHSECONDS.${current_env:t}..${prev_env:t}
fi
- zf_mkdir -p $SETUP_DIR
@@ -135,35 +141,42 @@ postinstall() {
}
typeset -ft postinstall
-typeset -g versions current this_version
-current=/run/current # @@current@@
-versions=/versions # @@versions@@
-this_version=$0:A:h:h:t
+typeset -g versions current
+current=/run/current
+versions=/versions
+
+typeset -g this_command this_conf current_command current_env current_conf
+this_command=$0
+this_conf=$0:P:h:h
+current_command=$current/command/install-as-current-environment.postinstall
+current_env=$current_command:h:P:h
+current_conf=$current_command:P:h:h
# arguments and validation
-() {
- local linked_path=$current/command/install-as-current-environment.postinstall
- if (( $# > 1 )); then
- die100 "Fatal: ${(qqq)0}: Too many arguments"
- fi
- if [[ $0:A != $versions/* ]]; then
- die100 "Fatal: ${(qqq)0}: This script expects to be installed under ${(qqq)versions}."
- fi
- if [[ $0:A != $linked_path ]]; then
- die111 "Fatal: ${(qqq)0}: This script needs to be run after installing the given environment as ${(qqq)current}."
+if (( $# > 1 )); then
+ fatal100 "Too many arguments"
+fi
+if [[ $0:P != $versions/* ]]; then
+ fatal100 "This script expects to be installed under ${(qqq)versions}."
+fi
+this_command=$current/command/install-as-current-environment.postinstall
+if [[ $0:P != $current_command:P ]]; then
+ fatal111 "Fatal: This script needs to be run after installing the given environment as ${(qqq)current}."
+fi
+if (( $# )); then
+ typeset -g prev_command prev_env prev_conf
+ prev_command=$1/command/install-as-current-environment.postinstall
+ prev_env=$1:P
+ prev_conf=$prev_command:P:h:h
+ if [[ $prev_env != $versions/* ]]; then
+ fatal111 "Old version doesn't seem to be inside ${(qqq)versions}: ${(qqq)prev_env}."
fi
- if (( $# )); then
- if [[ $1:P != $versions/* ]]; then
- die111 "Fatal: ${(qqq)0}: Old version doesn't seem to be inside ${(qqq)versions}: ${(qqq)1}."
- fi
- typeset -g prev_version=$1:P
- if ! [[ $prev_version:t == env.* ]]; then
- die111 "Unexpected previous environment name: ${(qqq)prev_version}"
- fi
+ if ! [[ $prev_env:t == env.* ]]; then
+ fatal111 "Unexpected previous environment name: ${(qqq)prev_env}"
fi
- if ! [[ $this_version == env.* ]]; then
- die111 "Unexpected current environment name: ${(qqq)this_version}"
- fi
-}
+fi
+if ! [[ $current_env:t == env.* ]]; then
+ fatal111 "Unexpected current environment name: ${(qqq)current_env}"
+fi
- postinstall "$@"