Skip to content

Bundling command line tools

probonopd edited this page Jan 12, 2019 · 3 revisions

You can use a custom AppRun script to make your command line tool invocable from a symlink, and by passing the command line tool's name as the first parameter to the AppImage like this:

#!/bin/bash

HERE="$(dirname "$(readlink -f "${0}")")"

# Allow the AppImage to be symlinked to e.g., /usr/bin/commandname
# or called with ./Some*.AppImage commandname ...

if [ ! -z $APPIMAGE ] ; then
  BINARY_NAME=$(basename "$ARGV0")
else
  BINARY_NAME=$(basename "$0")
fi
if [ ! -z "$1" ] && [ -e "$HERE/bin/$1" ] ; then
  MAIN="$HERE/bin/$1" ; shift
elif [ ! -z "$1" ] && [ -e "$HERE/usr/bin/$1" ] ; then
  MAIN="$HERE/usr/bin/$1" ; shift
elif [ -e "$HERE/bin/$BINARY_NAME" ] ; then
  MAIN="$HERE/bin/$BINARY_NAME"
elif [ -e "$HERE/usr/bin/$BINARY_NAME" ] ; then
  MAIN="$HERE/usr/bin/$BINARY_NAME"
else
  MAIN="$HERE/usr/bin/freac"
fi

exec "${MAIN}" "$@"

This will allow the AppImage to be symlinked to e.g., /usr/bin/commandname (where the name of the command line tool is the name of the symlink) or to be called with ./Some*.AppImage commandname ... (where the name of the command line tool is the first parameter).