-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkdexe
executable file
·109 lines (100 loc) · 2.57 KB
/
mkdexe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#! /bin/bash
die() {
echo "$1"
exit 1
}
if [ "$#" -lt "6" ]; then
echo
echo "Usage: mkdexe -N <app_name> -P <app_path> -E <app_exe> " \
"[<extra_options>]"
echo
echo "extra_options are:"
echo " -C <app_category> (by default \"Game\")"
echo " -R <dosemurc_file> (use this file as dosemu2 config)"
echo " -r (same as -R, but takes ~/.dosemu/dosemurc)"
echo
echo "Example:"
echo "./mkdexe -N Wolf3d -P ~/dos/games/wolf -E wolf3d.exe"
echo " In this example dosemurc is not specified, which means default config."
exit 0
fi
optstring="N:C:P:E:R:rfx:"
# set defaults
CATEGORY=Game
APP_PREF=org.dosemu2
DOSEMURC=dosemurc
while getopts ${optstring} opt; do
case ${opt} in
N)
APP_NAME=${OPTARG}
;;
C)
CATEGORY=${OPTARG}
;;
P)
APP_PATH=${OPTARG}
;;
E)
APP_EXE=${OPTARG}
;;
R)
RC=${OPTARG}
;;
r)
RC="~/.dosemu/$DOSEMURC"
;;
f)
REFRESH=1
;;
x)
AI_ARGS="$AI_ARGS ${OPTARG}"
;;
?)
exit 1
;;
esac
done
[ -n "$APP_NAME" ] || die "app name missing, use -N"
[ -n "$APP_PATH" ] || die "app path missing, use -P"
[ -n "$APP_EXE" ] || die "app exe name missing, use -E"
[ -r "$APP_PATH/$APP_EXE" ] || die "$APP_PATH/$APP_EXE does not exist"
[ -z "$RC" -o -r "$RC" ] || die "$RC missing"
APP_DIR=`basename $APP_PATH`
APPNAME=${APP_PREF}.${APP_NAME}
subst_vars() {
sed -E \
-e "s/@APP_DIR[@]/$APP_DIR/g" \
-e "s/@APP_EXE[@]/$APP_EXE/g" \
-e "s/@APP_NAME[@]/$APP_NAME/g" \
-e "s/@ARCH[@]/$ARCH/g" \
-e "s/@APPNAME[@]/$APPNAME/g" \
-e "s/@CATEGORY[@]/$CATEGORY/g" \
$1 >$2
}
FLIST=`find AppDir -mindepth 1 -name '*.tmpl' -prune -o -print`
[ -n "$FLIST" ] || die "AppDir not found"
ARCH=`uname -m`
RUNDIR="$XDG_RUNTIME_DIR/mkdexe"
APPT="appimagetool-${ARCH}.AppImage"
APPTOOL="$RUNDIR/$APPT"
URL="https://github.com/AppImage/appimagetool/releases/download/continuous/$APPT"
[ -d "$RUNDIR" ] || mkdir "$RUNDIR"
[ -z "$REFRESH" ] || rm -f $APPTOOL
[ -f "$APPTOOL" ] || wget -O "$APPTOOL" $URL || die "appimagetool download failed"
[ -x "$APPTOOL" ] || chmod +x "$APPTOOL"
TMPD=`mktemp -d /tmp/mkdexe.XXXXXX`
[ -n "$TMPD" ] || die "failed to create tmp dir"
AD="$TMPD/AppDir"
mkdir "$AD"
[ -d "$AD" ] || die "failed to create AppDir"
echo "Created $AD"
cp $FLIST "$AD"
subst_vars AppDir/AppRun.env.tmpl "$AD/AppRun.env"
subst_vars AppDir/desktop.tmpl "$AD/${APPNAME}.desktop"
[ -z "$RC" ] || cp $RC $AD/$DOSEMURC
# copy game
cp -r "$APP_PATH" "$AD"
# now run appimagetool
export ARCH
$APPTOOL $AI_ARGS "$AD"
rm -rf "$TMPD"