#!/bin/sh

APP=arch-deployer

# CREATE THE FOLDER
mkdir /opt/$APP
cd /opt/$APP

# ADD THE REMOVER
echo '#!/bin/sh' >> /opt/$APP/remove
echo "rm -R -f /opt/$APP /usr/local/bin/$APP" >> /opt/$APP/remove
chmod a+x /opt/$APP/remove

# DOWNLOAD THE PROGRAM
mkdir tmp
cd tmp
wget https://raw.githubusercontent.com/ivan-hc/Arch-Deployer/main/$APP
cd ..
mv ./tmp/$APP ./
chmod a+x /opt/$APP/$APP
rmdir ./tmp

# LINK
ln -s /opt/$APP/$APP /usr/local/bin/$APP

# SCRIPT TO UPDATE THIS RELEASE
echo '#!/bin/sh
mkdir /opt/'$APP'/tmp
cd /opt/'$APP'/tmp
wget https://raw.githubusercontent.com/ivan-hc/Arch-Deployer/main/'$APP'
cd ..
mv ./tmp/'$APP' ./
chmod a+x /opt/'$APP'/'$APP'
rmdir ./tmp' >> /opt/$APP/AM-updater
chmod a+x /opt/$APP/AM-updater
