Last active
February 15, 2025 15:38
-
-
Save jes/543669252b2951e961614e2f2a873b22 to your computer and use it in GitHub Desktop.
Create the world's lamest AppImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [[ -z "$1" ]]; then | |
echo "Usage: $0 <binary> [additional files...]" | |
exit 1 | |
fi | |
BIN_PATH=$(realpath "$1") | |
BIN_NAME=$(basename "$BIN_PATH") | |
TMPDIR=$(mktemp -d) | |
OUTFILE="$BIN_NAME.run" | |
echo "Packaging $BIN_NAME into $OUTFILE..." | |
# Create the runtime directory | |
mkdir -p "$TMPDIR/app/bin" | |
cp "$BIN_PATH" "$TMPDIR/app/bin/" | |
# Copy additional files if provided | |
shift # Remove the binary path from arguments | |
for file in "$@"; do | |
if [[ -e "$file" ]]; then | |
echo "Including additional file: $file" | |
cp -a "$file" "$TMPDIR/app/" | |
else | |
echo "Warning: File not found: $file" | |
fi | |
done | |
# Find all required shared libraries | |
echo "Finding shared libraries..." | |
ldd "$BIN_PATH" | awk '{print $3}' | grep -E '^/' | sort -u | while read -r lib; do | |
cp "$lib" "$TMPDIR/app/" | |
done | |
# Create self-extracting script | |
{ | |
echo "#!/bin/bash" | |
echo "TMPDIR=\$(mktemp -d)" | |
echo "echo Extracting to \$TMPDIR..." | |
echo "ARCHIVE_LINE=\$(awk '/^__ARCHIVE__/{print NR + 1; exit 0}' \"\$0\")" | |
echo "tail -n +\$ARCHIVE_LINE \"\$0\" | tar xf - -C \"\$TMPDIR\"" | |
echo "cd \"\$TMPDIR/app\"" | |
echo "export LD_LIBRARY_PATH=\"\$TMPDIR/app\"" | |
echo "exec \"./bin/$BIN_NAME\" \"\$@\"" | |
echo "__ARCHIVE__" | |
tar cf - -C "$TMPDIR" app # <-- NO COMPRESSION | |
} > "$OUTFILE" | |
chmod +x "$OUTFILE" | |
rm -rf "$TMPDIR" | |
echo "Created $OUTFILE. You can run it anywhere!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment