#!/bin/bash
# zenity --password --title="sudo password prompt" --timeout=10 > /tmp/pass.txt
# password=`cat /tmp/pass.txt`
# echo $password
pwd=`pwd`
pwd_='pwd'
filename="src/yoovo.desktop"
sed -i "s|$pwd_|$pwd|g" $filename
echo '#!/bin/bash' > src/run.sh
echo 'cd '$pwd'/src' >> src/run.sh
echo "python3.8 gpio_tester.py" >> src/run.sh
chmod +x src/run.sh
cp $filename ~/.config/autostart/
pi_arch=`uname -m`
{
    python3.8 --version
} || {
    sudo apt-get update
    sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev tar wget
    wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
    tar zxf Python-3.8.0.tgz
    cd Python-3.8.0
    sudo ./configure --enable-optimizations
    sudo make -j 2
    sudo make altinstall
    cd ..
    rm -r Python-3.8.0
    rm Python-3.8.0.tar.xz
}
# if [[ $pi_arch -eq 'armv7l' ]]
# then
# 	rm compiled_gui_64.so
# 	mv compiled_gui_32.so compiled_gui.so
# else
# 	rm compiled_gui_32.so
# 	mv compiled_gui_64.so compiled_gui.so
# fi
sudo apt-get install software-properties-common -y
sudo apt update
sudo apt install libjpeg-dev zlib1g-dev -y
sudo apt install python3-pip python3-tk -y
sudo apt-get install python3-pil python3-pil.imagetk -y
python3.8 -m pip install -r src/requirements.txt
./src/run.sh
# echo $password | sudo -S systemctl daemon-reload
# echo $password | sudo -S systemctl enable $filename
# echo $password | sudo -S systemctl start $filename