#!/bin/bash
readonly red="\e[31m"
readonly normal="\e[0m"

#Removing existing /usr/local/bin/pi-apps and script
echo -n "removing existing version of the script..."
sudo rm -f /usr/local/bin/pi-apps
rm -f "${DIRECTORY}/pi-apps-terminal-bash-edition.sh"
echo "done"

#Download script
echo -n "Downloading script..."
wget https://raw.githubusercontent.com/Itai-Nelken/PiApps-terminal_bash-edition/main/pi-apps-terminal-bash-edition.sh -O "${DIRECTORY}/pi-apps-terminal-bash-edition.sh" || error "Failed to download pi-apps terminal bash edition script!"
echo "done"
chmod u+x "${DIRECTORY}/pi-apps-terminal-bash-edition.sh" || error "Failed to mark ${DIRECTORY}/pi-apps-terminal-bash-edition.sh as executable!"

#create launcher script
echo -n "creating launcher script..."
echo '#!/bin/bash
'"${DIRECTORY}"'/pi-apps-terminal-bash-edition.sh "$@"' | sudo tee /usr/local/bin/pi-apps >/dev/null || error "Failed to create pi-apps command in '/usr/local/bin/'!"
sudo chmod +x /usr/local/bin/pi-apps || error "Failed to make launcher script executable!"
echo "done"
