-cp ctdlvisor citadel.AppDir/usr/bin/
-ARCH=x86_64 appimagetool citadel.AppDir/
-rm -fr /usr/local/citadel /usr/local/webcit
+# Install the Citadel Server application tree
+mkdir -p citadel.AppDir/usr/local/citadel || exit 17
+rsync -va $CITADEL_BUILD_DIR/ ./citadel.AppDir/usr/local/citadel/ || exit 18
+
+# Install the WebCit application tree
+mkdir -p citadel.AppDir/usr/local/webcit || exit 19
+rsync -va $WEBCIT_BUILD_DIR/ ./citadel.AppDir/usr/local/webcit/ || exit 20
+
+# Remove the build directories
+rm -fr $CITADEL_BUILD_DIR $WEBCIT_BUILD_DIR
+
+cc ctdlvisor.c -o citadel.AppDir/usr/bin/ctdlvisor || exit 21
+
+CPU=`uname -m`
+basefilename=citadel-`date +%s`
+if [ $CPU == x86_64 ] ; then
+ export ARCH=x86_64
+elif [ $CPU == armv7l ] ; then
+ export ARCH=ARM
+fi
+echo ARCH: $ARCH
+echo CPU: $CPU
+appimagetool citadel.AppDir/ ${basefilename}-${CPU}.appimage