#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

# Get dependencies
"${DIRECTORY}/pkg-install" "snapd" "$(dirname "$0")" || exit 1

sudo systemctl enable --now snapd.socket || error "Unable to enable snapd.socket"
sudo ln -s /var/lib/snapd/snap /snap || error "unable to create symbolic link between /var/lib/snapd/snap and /snap"
sudo snap install core || error "Unable to install core"
sudo snap install snap-store || error "Unable to install snap store"
sudo rm -rf /usr/share/applications/snap
ln -s /var/lib/snapd/desktop/applications /usr/share/applications/snap || sudo ln -s /var/lib/snapd/desktop/applications /usr/share/applications/snap || error "Failed to create symlink for Snap app shortcuts!"


