Skip to content

Commit

Permalink
fix(convertfs): error in conditional expressions (bsc#1228847)
Browse files Browse the repository at this point in the history
With POSIX conditionals using single brackets, `-n` followed by a variable
without quotes is always true.

Also, use `$ROOT` instead of hardcoding `/sysroot`.
  • Loading branch information
aafeijoo-suse committed Aug 5, 2024
1 parent 7870f08 commit 67f6075
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules.d/30convertfs/convertfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ done
[ -w $ROOT ] || mount -o remount,rw $ROOT

#mount /sysroot/var if it is a separate mount
VARDEV=$(sed -n -e 's/^\#.*//' -e '/ \/var /s/\([[:graph:]]* \).*/\1/p' /sysroot/etc/fstab)
VARFS=$(sed -n -e 's/^\#.*//' -e '/ \/var /s/[[:graph:]]* * [[:graph:]]* *\([[:graph:]]* \).*/\1/p' /sysroot/etc/fstab)
VARDEV=$(sed -n -e 's/^\#.*//' -e '/ \/var /s/\([[:graph:]]* \).*/\1/p' "$ROOT"/etc/fstab)
VARFS=$(sed -n -e 's/^\#.*//' -e '/ \/var /s/[[:graph:]]* * [[:graph:]]* *\([[:graph:]]* \).*/\1/p' "$ROOT"/etc/fstab)

if [ -n $VARDEV ] && [ -n $VARFS ]; then
if [[ -n $VARDEV ]] && [[ -n $VARFS ]]; then
#mount btrfs subvolume var
if [ $VARFS == btrfs ]; then
SUBVOLIDVAR=$(btrfs subvolume list $ROOT | sed -n '/var$/s/ID \([[:digit:]]*\) .*/\1/p')
Expand All @@ -50,7 +50,7 @@ if [ ! -L "$ROOT"/var/lock -a -e "$ROOT"/var/lock ]; then
ln -sfn ../run/lock "$ROOT"/var/lock
fi

[ -n $SUBVOLIDVAR ] && umount $ROOT/var
[[ -n $SUBVOLIDVAR ]] && umount $ROOT/var
[ -w $ROOT ] && mount -o remount,ro $ROOT

echo "Done."
Expand Down

0 comments on commit 67f6075

Please sign in to comment.