#!/usr/bin/env bash

set -e

# Uninstall IPFS
sudo systemctl disable ipfs.service 2>/dev/null || true
sudo systemctl stop ipfs.service 2>/dev/null || true
sudo systemctl daemon-reload
sudo rm -f /usr/local/bin/ipfs
sudo rm -f /lib/systemd/system/ipfs.service

if [ -d "~/.ipfs" ]; then
    echo "Found ~/.ipfs"
    read -p "Keep your IPFS data (Y/n)? " -n 1 -r
    echo ""
    if [[ $REPLY =~ ^[Nn]$ ]]; then
        echo -e "\e[1;31mRemoving ~/.ipfs\e[0m"
        rm -rf ~/.ipfs
    else
        echo -e "\e[1;32mKeeping ~/.ipfs\e[0m"
    fi
fi

# Remove HTTP to IPFS gateway
sudo rm -f /etc/nginx/sites-enabled/ipfs-http-gateway
sudo rm -f /etc/nginx/sites-available/ipfs-http-gateway
sudo systemctl restart nginx.service
