#!/bin/bash
# Get dependencies
install_packages libsquashfuse0 squashfuse fuse libgconf-2-4 || exit 1
sudo apt install -y snapd || error "APT failed to install snapd"

sudo systemctl enable --now snapd.socket || error "Unable to enable snapd.socket"
sudo systemctl start snapd.service
if [ $? != 0 ];then
  echo "Unable to start snapd.service. Running debug..."
  echo "Running 'systemctl status snapd.service'"
  systemctl status snapd.service
  sudo /usr/lib/snapd/snapd
  exit 1
fi

sudo snap refresh
sudo systemctl restart snapd.service || error "Unable to restart snapd.service"
sudo modprobe squashfs || exit 1

sudo snap install core18 || error "Snapd was unable to install core18"
sudo snap install core || error "Snapd was unable to install core"
sudo snap install snapd || error "Snapd was unable to install snapd"

sudo ln -s /var/lib/snapd/snap /snap

echo "Output of 'snap version':"
snap version
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!"

