#!/bin/bash

set -euo pipefail   # safety – stop on errors, unset vars, etc.

if [ ! -t 0 ]; then
    echo "Error: This script must be run from such as a terminal emulator (not a file manager)."
    exit 1
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd "$DIR"
cd ..
PROGRAM_NAME=`basename $PWD`
cd "$DIR"

sudo cp Shule.desktop /usr/share/applications/Shule.desktop #This puts Shule in the menu for all users.

if ! [[ -d "/opt/bin" ]]; then
    sudo mkdir /opt/bin
fi
if ! [[ -d "/opt/share" ]]; then
    sudo mkdir /opt/share
fi
sudo mkdir /opt/share/shule
sudo chmod -R 0777 /opt/share/shule #We want the settings to be writable by all users.
sudo cp ./shule /opt/bin/shule #This copies our script that launches Shule.
./UPDATE
#sudo chmod -R 0777 /opt/shule #This is if you want /opt/shule to be writable (and by all users)
sudo update-alternatives --install /usr/bin/shule shule /opt/bin/shule 0 #This makes it so shule is in your path. If you have another program named shule, this might cause problems.