#!/bin/bash
webhook_file=/usr/share/DREAMMAKER/.discord_url
tag_file=/usr/share/DREAMMAKER/.discord_tag
script_file=/usr/local/bin/DREAMMAKER.sh
service_file=/etc/systemd/system/DREAMMAKER.service
store_path=/usr/share/DREAMMAKER
pink="$\033[35m"
reset="\033[0m"
header="\n\n${pink} ____  ______   _______  _______  _______  _______  _______  _______  _        _______  _______  ____
(  __)(  __  \ (  ____ )(  ____ \(  ___  )(       )(       )(  ___  )| \    /\(  ____ \(  ____ )(__  )
| (   | (  \  )| (    )|| (    \/| (   ) || () () || () () || (   ) ||  \  / /| (    \/| (    )|   ) |
| |   | |   ) || (____)|| (__    | (___) || || || || || || || (___) ||  (_/ / | (__    | (____)|   | |
| |   | |   | ||     __)|  __)   |  ___  || |(_)| || |(_)| ||  ___  ||   _ (  |  __)   |     __)   | |
| |   | |   ) || (\ (   | (      | (   ) || |   | || |   | || (   ) ||  ( \ \ | (      | (\ (      | |
| (__ | (__/  )| ) \ \__| (____/\| )   ( || )   ( || )   ( || )   ( ||  /  \ \| (____/\| ) \ \__ __) |
(____)(______/ |/   \__/(_______/|/     \||/     \||/     \||/     \||_/    \/(_______/|/   \__/(____)
\n\n${reset}https://github.com/${pink}PrincessPi3${reset}\n\n"

echo "installing [DЯΣΛMMΛKΣЯ]"
# kill any running instanes
echo "killing any running"
sudo systemctl stop DREAMMAKER.service 2>/dev/null

echo "cleaning up"
# see if wer need top nuke old filews
if [ -f "$script_file" ]; then
    echo "Deleting existing $script_file"
    sudo rm -f "$script_file" 2>/dev/null
fi

if [ -f "$service_file" ]; then
    echo "Deleting existing $service_file"
    sudo rm -f "$service_file" 2>/dev/null
fi

if [ ! -d "$store_path" ]; then
    echo "Creating $store_path"
    sudo mkdir -p "$store_path"
fi

if [ ! -f "$webhook_file" ]; then
    echo -e "Enter Discord Webhook URL\n\tRight click on server->server settings->integrations"
    read discord_webhook
    sudo bash -c "echo \"$discord_webhook\" > \"$webhook_file\""
    echo
fi

if [ ! -f "$tag_file" ]; then
    echo -e "Enter Discord Member group to tag\n\tuse a backslash when tagging the roll like \\@notifications"
    read discord_tag_file
    sudo bash -c "echo \"$discord_tag_file\" > \"$tag_file\""
    echo
fi

if [ ! $(which bluetoothctl) ]; then
    echo -e "\nERROR: bluetoothctl not found! Please install and try again.\n"
fi

if [ ! $(which CURL) ]; then
    echo -e "\nERROR: curl not found! Please install and try again.\n"
fi

# install itt
echo "installing service"
sudo cp DREAMMAKER.sh "$script_file"
sudo chmod +x "$script_file"
sudo cp DREAMMAKER.service "$service_file"
echo

# enable it at boot and run
echo "enabling [DЯΣΛMMΛKΣЯ] at boot and starting the service"
sudo systemctl enable DREAMMAKER.service
sudo systemctl start DREAMMAKER.service
sudo systemctl status DREAMMAKER.service
echo -e "\nall donesies :3 nytaa~\n"
