#!/bin/bash
file="$1"
shift 1
dirname=$(md5sum "$file" | cut -f1 -d" ")
tmp="$HOME/.cache/appimage-loader/$dirname"
mkdir -p $tmp
cp "$file" "$tmp/appimage"
chmod 755 "$tmp/appimage"
cur="$PWD"
cd "$tmp"
"$tmp/appimage" --appimage-extract
cd "$cur"
rm -f "$tmp/appimage"
"$tmp/squashfs-root/AppRun" "$@"
status="$?"
rm -rf "$tmp"
exit $status
