#!/bin/bash

total_commands=31
current_command=0

function print_progress {
  current_command=$((current_command + 1))
  percent=$((current_command * 100 / total_commands))
  echo "Executing command $current_command/$total_commands ($percent%): $1"
}

cd /home/pi/conjurer || exit
print_progress "cd /home/pi/conjurer"

git pull
print_progress "git pull"

cp ./deploy.sh /home/pi/
print_progress "cp ./deploy.sh /home/pi/"

cd /home/pi || exit
print_progress "cd /home/pi"

cp ./conjurer/LICENSE ./Conjurer/LICENSE
print_progress "cp ./conjurer/LICENSE ./Conjurer/LICENSE"

cp ./conjurer/fuckery.jpg ./Conjurer/
print_progress "cp ./conjurer/fuckery.jpg ./Conjurer/"

cp ./conjurer/willowisp.png ./Conjurer/
print_progress "cp ./conjurer/willowisp.png ./Conjurer/"

cp ./conjurer/wod_beacon.jpg ./Conjurer/
print_progress "cp ./conjurer/wod_beacon.jpg ./Conjurer/"

cp ./conjurer/settings.json ./Conjurer/
print_progress "cp ./conjurer/settings.json ./Conjurer/"

if [[ ./conjurer/system_gpt_settings.json -nt ./Conjurer/system_gpt_settings.json ]]; then
  cp ./conjurer/system_gpt_settings.json ./Conjurer/system_gpt_settings.json
  print_progress "cp ./conjurer/system_gpt_settings.json ./Conjurer/system_gpt_settings.json"
else
  print_progress "system_gpt_settings.json is up to date"
fi

cp ./conjurer/administration_commands.py ./Conjurer/
print_progress "cp ./conjurer/administration_commands.py ./Conjurer/"

cp ./conjurer/ai_commands.py ./Conjurer/
print_progress "cp ./conjurer/ai_commands.py ./Conjurer/"

cp ./conjurer/ai_functions.py ./Conjurer/
print_progress "cp ./conjurer/ai_functions.py ./Conjurer/"

cp ./conjurer/communication_subroutine.py ./Conjurer/
print_progress "cp ./conjurer/communication_subroutine.py ./Conjurer/"

cp ./conjurer/constants.py ./Conjurer/
print_progress "cp ./conjurer/constants.py ./Conjurer/"

cp ./conjurer/librarian_commands.py ./Conjurer/
print_progress "cp ./conjurer/librarian_commands.py ./Conjurer/"

cp ./conjurer/music_commands.py ./Conjurer/
print_progress "cp ./conjurer/music_commands.py ./Conjurer/"

cp ./conjurer/music_functions.py ./Conjurer/
print_progress "cp ./conjurer/music_functions.py ./Conjurer/"

cp ./conjurer/other_commands.py ./Conjurer/
print_progress "cp ./conjurer/other_commands.py ./Conjurer/"

cp ./conjurer/other_functions.py ./Conjurer/
print_progress "cp ./conjurer/other_functions.py ./Conjurer/"

cp ./conjurer/radio_commands.py ./Conjurer/
print_progress "cp ./conjurer/radio_commands.py ./Conjurer/"

cp ./conjurer/voice_recognition_commands.py ./Conjurer/
print_progress "cp ./conjurer/voice_recognition_commands.py ./Conjurer/"

cp ./conjurer/file_search_functions.py ./Conjurer/

print_progress "cp ./conjurer/file_search_functions.py ./Conjurer/"

cp ./conjurer/file_search_commands.py ./Conjurer
print_progress "cp ./conjurer/file_search_functions.py ./Conjurer/"

cp ./conjurer/latex_commands.py ./Conjurer/
print_progress "cp ./conjurer/latex_commands.py ./Conjurer/"

cp ./conjurer/latex_functions.py ./Conjurer/
print_progress "cp ./conjurer/latex_functions.py ./Conjurer/"

cp ./conjurer/librarian_functions.py ./Conjurer
print_progress "cp ./conjurer/librarian_functions.py ./Conjurer/"

cp ./conjurer/conanjurer_commands.py ./Conjurer/
print_progress "cp ./conjurer/conanjurer_commands.py ./Conjurer/"

cp ./conjurer/conanjurer_functions.py ./Conjurer/
print_progress "cp ./conjurer/conanjurer_functions.py ./Conjurer/"

cp ./conjurer/bot.py ./Conjurer/bot.py
print_progress "cp ./conjurer/bot.py ./Conjurer/bot.py"

sudo systemctl restart conjurer.service
print_progress "sudo systemctl restart conjurer.service"
