save, then run, dont execuet while piping

This commit is contained in:
Dominik Moritz Roth 2025-08-17 23:23:34 +02:00
parent 7beb5bf119
commit aa9ba7ce23

View File

@ -4,6 +4,14 @@
set -euo pipefail set -euo pipefail
# If we're being piped, save to a temp file and re-execute
if [ ! -t 0 ]; then
TEMP_SCRIPT=$(mktemp)
cat > "$TEMP_SCRIPT"
chmod +x "$TEMP_SCRIPT"
exec bash "$TEMP_SCRIPT"
fi
BANNER=$(cat << "EOF" BANNER=$(cat << "EOF"
:^7J5GB##&&##GPY?~: :^7J5GB##&&##GPY?~:
^75B&@@@@@@&&&@@@@@@@#GJ~: ^75B&@@@@@@&&&@@@@@@@#GJ~:
@ -93,8 +101,9 @@ sed -i "s/^CRYPTPASSWORD .*/CRYPTPASSWORD $LUKS_PASS/" install.conf
# Update post-install.sh # Update post-install.sh
sed -i "s/^ALMA_USER=.*/ALMA_USER=\"$USERNAME\"/" post-install.sh sed -i "s/^ALMA_USER=.*/ALMA_USER=\"$USERNAME\"/" post-install.sh
# Use a different approach for SSH_KEY to handle special characters # Use a different approach for SSH_KEY to handle special characters
escaped_key=$(printf '%s\n' "$SSH_KEY" | sed 's/[[\.*^$()+?{|]/\\&/g') # Escape the SSH key for use in sed by replacing special characters
sed -i "s|^SSH_KEY=.*|SSH_KEY=\"$escaped_key\"|" post-install.sh escaped_key=$(printf '%s' "$SSH_KEY" | sed 's/[[\.*^$()+?{|]/\\&/g; s/]/\\&/g')
sed -i "s|^SSH_KEY=.*|SSH_KEY=\"${escaped_key}\"|" post-install.sh
# Copy to root directory where installimage expects them # Copy to root directory where installimage expects them
cp install.conf /root/ cp install.conf /root/