#!/bin/bash
file="$1"
shift 1
# try chmod
chmod +x "$file"
if [ $? -eq 0 ] ; then
    exec "$file" "$@"
fi
dirname=$(md5sum "$file" | cut -f1 -d" ")
tmp="$HOME/.cache/appimage-loader/$dirname"
mkdir -p $tmp
cp "$file" "$tmp/appimage"
chmod 755 "$tmp/appimage"
"$tmp/appimage" "$@"
status="$?"
rm -rf "$tmp"
exit $status
