#!/bin/bash

# This script creates a .run installer for Xfe (Linux only)
# It is assumed that linuxdeploy and makeself are installed on the system
# 14/12/2024


# Compile and create AppDir directory 
./configure --prefix=`pwd`/AppDir/usr --enable-release
make
make install


# Check if AppDir directory exists
if [ ! -d ./AppDir ]; then

    echo ""
    echo "AppDir directory does not exist. Abort..."
    echo ""
    
    exit
    
fi

# Deploy libs
linuxdeploy --desktop-file=AppDir/usr/share/applications/xfe.desktop --appdir=AppDir

# Rename usr directory
mv AppDir/usr AppDir/xfe

# Remove unused files
rm -f AppDir/xfe.svg
rm -f AppDir/xfe.desktop
rm -f AppDir/AppRun

# Change iconpath in xferc
sed -i "s|iconpath = `pwd`/AppDir/usr|iconpath = /usr/local/xfe|g" AppDir/xfe/share/xfe/xferc

# Change exec path in pkexec rule
sed -i "s|`pwd`/AppDir/usr|/usr/local|g" AppDir/xfe/share/polkit-1/actions/org.xfe.root.policy

# Copy install script
cp installrun AppDir

# Build run file
makeself --xz ./AppDir ./xfe-install-linux.run "Install xfe..." ./installrun

# End
echo ""
echo "Done!"
echo ""
