#!/usr/bin/env bash

# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

systemctl stop epd-fuse

CONFIG="/etc/default/epd-fuse"

# Use this to set the new config value, needs 2 parameters. 
# You could check that $1 and $1 is set, but I am lazy
function set_config(){
    sudo sed -i "s/^\($1\s*=\s*\).*\$/\1$2/" $CONFIG
}

# LOAD THE CONFIG FILE
source $CONFIG

sed -i '/EPD_SIZE/s/^#//g' $CONFIG

echo "${EPD_SIZE}" # SHOULD OUTPUT DEFAULT (test) ON FIRST RUN
EPD_SIZE=$1

echo "${EPD_SIZE}" # SHOULD OUTPUT Erl
set_config EPD_SIZE $EPD_SIZE # SETS THE NEW VALUE

systemctl start epd-fuse

# sudo reboot
