# To be rewritten so that packages are not installed into the system and ldd is not needed

APP=Audacity
LOWERAPP=audacity

sudo add-apt-repository -y ppa:ubuntuhandbook1/audacity
sudo apt-get update

sudo apt-get -y install $LOWERAPP

mkdir -p $APP/$APP.AppDir

cd $APP

wget -q https://github.com/probonopd/AppImages/raw/master/functions.sh -O ./functions.sh
. ./functions.sh

cd $APP.AppDir

find /var/cache/apt/archives/$LOWERAPP* -exec dpkg -x {} . \;

cp ./usr/share/applications/$LOWERAPP.desktop .
sed -i -e 's|env UBUNTU_MENUPROXY=0 ||g' $LOWERAPP.desktop

rm -rf ./usr/share/icons/48x48/apps || true
rm -rf ./usr/share/icons/hicolor/48x48/apps || true

get_apprun

# Copy in the indirect dependencies
copy_deps # Three runs to ensure we catch indirect ones

patch_usr

delete_blacklisted

VERSION=$(ls /var/cache/apt/archives/$LOWERAPP_* | head -n 1 | cut -d "_" -f 2 | cut -d "-" -f 1)
echo $VERSION

get_desktopintegration $LOWERAPP

# Go out of AppImage
cd ..

generate_appimage
