#!/bin/bash
clear

TERM=linux toilet -f standard -F metal "RetrOrangePi 4.0" 

#    RetrOrangePi BashWelcomeTweak

echo -e "       \033[0;32m█              █\033[0m     "
echo -e "  \033[0;33m█\033[0m     \033[0;32m█            █\033[0m     \033[0;33m█"
echo -e "\033[0;33m  █  ████████████████████  █"
echo -e "\033[0;33m  ███████\033[1;37m██\033[0;33m████████\033[1;37m██\033[0;33m███████"
echo -e "\033[0;33m  ██████████████████████████"
echo -e "\033[0;33m    ██████████████████████ "
echo -e "\033[0;33m     ████████████████████  "
echo -e "\033[0;33m        █             █   "
echo -e "\033[0;33m       █               █  "
echo ""
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*             Downloading RetrOrangePi 4.0 UPDATE               *"
echo "*                                                               *"
echo "*****************************************************************"
sleep 3
cd /home/pi
echo "Please wait a few minutes..."
wget -q -O updater_v4.tar.gz http://www.retrorangepi.org/updater_v4.tar.gz
tar -zxf updater_v4.tar.gz
echo "*****************************************************************"
echo "*                                                               *"
echo "*                     Backing up your configs...                *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
mkdir ~/backup_v3
cp -r /opt/retropie/configs backup_v3/
sudo mv -t ~/backup_v3 ~/RetroPie-Setup /etc/init.d/asplashscreen /etc/apt /opt/retropie/configs/all/launching.png
clear
echo "*****************************************************************"
echo "*                                                               *"
echo "*    INSTALLING UPDATE                                          *"
echo "*    - RetroPie-Setup 4.3.3                                     *"
echo "*    - EmulationStation 2.6.5 with video support                *"
echo "*    - Retroarch 1.6.7 - Retroachievements tested               *"
echo "*    - New RetrOrangePi menu for easy updates                   *"
echo "*    - Power button features                                    *"
echo "*    - Overscan fixed in AV outputs                             *"
echo "*    - CRT curvature shader, console overlays, launching images *"
echo "*    - Kodi Krypton 17.4                                        *"
echo "*    - AdvanceMAME 3.5                                          *"
echo "*    - Mupen64Plus 2.5 from OGST (Odroid)                       *"
echo "*    - PPSSPP v1.4.2-77 from OGST (Odroid)                      *"
echo "*    - All Libretro cores updated                               *"
echo "*    - Experimental new libretro cores                          *"
echo "*    - Boot selection from Desktop                              *"
echo "*    - Onscreen keyboard (Florence)                             *"
echo "*    - New Desktop wallpaper and icons                          *"
echo "*    - Customized Retroarch configuration                       *"
echo "*    - New HDMI/Analog AV configuration tool - user contrib     *"
echo "*    - New exclusive ROPi Radio beta version                    *"
echo "*    - All RetroPie themes available for installation           *"
echo "*    - New ROPi themes: Cosmos-ROPi and Hyperion                *"
echo "*    - RetroPie services tested: splashscreen,usb roms,scraper  *"
echo "*    - Custom ES splashscreen                                   *"
echo "*    - Custom MOTD with ROPi invader + Armbian info             *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
echo ""
echo "Please wait a few minutes..."
sudo killall -q emulationstation
sudo cp -prf update/* /
wget -q http://www.retrorangepi.org/hotfix.tar.gz
sudo tar -zxvf hotfix.tar.gz -C /
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*                    Configuring RetroPie 4.3                   *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
sudo chown -R pi:pi /home/pi/.config/retroarch /opt/retropie/configs/ ~/RetroPie/retropiemenu/RetrOrangePi
rm -rf ~/RetroPie/roms/apple2/*.sh ~/RetroPie/roms/apple2/*.SH ~/RetroPie/retropiemenu/gamelist.xml /opt/retropie/configs/all/retroarch ~/.config/retroarch/autoconfig ~/RetroPie/RetroPie ~/RetroPie/retropiemenu/ropiwifi.rp
ln -s /home/pi/.config/retroarch /opt/retropie/configs/all/
ln -s /opt/retropie/configs/all/retroarch-joypads ~/.config/retroarch/autoconfig
ln -s ~/RetroPie/retropiemenu/RetrOrangePi/gamelist.xml ~/RetroPie/retropiemenu/
ln -s ~/RetroPie/retropiemenu/RetrOrangePi ~/
sudo ~/RetroPie-Setup/retropie_packages.sh emulationstation depends
sudo ~/RetroPie-Setup/retropie_packages.sh runcommand
sudo cp /opt/retropie/configs/all/autostart_emustation.sh /opt/retropie/configs/all/autostart.sh
cd ~/RetroPie/roms && mkdir cps1 cps2 cps3 && cd ~
cd ~/RetrOrangePi && git pull && cd ~
sed -i -e 's/kiosk/Full/g' /opt/retropie/configs/all/emulationstation/es_settings.cfg
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*        Reinstalling Mali packages - fbdev/X11                 *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
sudo dpkg -i --force-overwrite ~/sunxi-mali/*.deb
sudo ln -sf /usr/lib/libMali.so /usr/lib/libGLESv1_CM.so.1.1
sudo ln -sf /usr/lib/libMali.so /usr/lib/libGLESv2.so.2.0
sudo ln -sf /usr/lib/libMali.so /usr/lib/libEGL.so.1.4
sudo ln -sf /usr/local/lib/libMali.so /usr/local/lib/libGLESv1_CM.so.1.1
sudo ln -sf /usr/local/lib/libMali.so /usr/local/lib/libGLESv2.so.2.0
sudo ln -sf /usr/local/lib/libMali.so /usr/local/lib/libEGL.so.1.4
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*                 Installing Kodi Krypton 17.4                  *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
rm -rf ~/RetroPie/roms/kodi
sudo dpkg -r kodi kodi-bin kodi-data
sudo dpkg -i ~/deb/kodi_17-4_armhf.deb
sudo chown -R pi:pi ~/.kodi/userdata/addon_data/pvr.iptvsimple/
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*                  Installing AdvanceMAME 3.5                   *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
sudo dpkg -i ~/deb/advancemame_3.5-1_armhf.deb
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*                  Configuring Amiga UAE4ARM v0.5               *"
echo "*                                                               *"
echo "*****************************************************************"
mv ~/RetroPie/roms/amiga/+FS-UAE_Launcher.sh ~/RetroPie/roms/amiga/+UAE4ARM_Launcher.sh
sudo rm -rf /opt/retropie/configs/amiga/uae4arm/conf/*
cp ~/update/opt/retropie/configs/amiga/uae4arm/conf/A1200.uae /opt/retropie/configs/amiga/uae4arm/conf/
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*         Installing Mupen64Plus emulator (ODROID port)         *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
sudo dpkg -i ~/deb/libminizip1_1.1-5_armhf.deb
sudo chown -R pi:pi ~/.local/share/mupen64plus/
sudo chown -R pi:pi ~/.config/mupen64plus/
sudo dpkg -i ~/deb/mupen64plus-odroid_2.5.0+deb8-1_armhf.deb
rm -rf /opt/retropie/configs/n64/mupen64plus.cfg
ln -sf /home/pi/.config/mupen64plus/mupen64plus.cfg /opt/retropie/configs/n64/
sudo chmod +x /usr/local/bin/mupen64plus.sh
sudo ~/RetroPie-Setup/retropie_packages.sh mupen64plus configure
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*         Installing PPSSPP emulator (ODROID port)              *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
sudo dpkg -i ~/deb/ppsspp-odroid_1.4.2-20170531-1+deb8_armhf.deb
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*         Installing ScummVM 1.7.0 (best compatibility)         *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
sudo ~/RetroPie-Setup/retropie_packages.sh scummvm
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*    Updating ARMBIAN packages and installing dependencies...   *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
sudo apt-mark hold armbian-firmware-full linux-headers-sun8i libsdl2-dev libmali-sunxi-r3p0 linux-jessie-root-*
sudo apt-get -y install usbmount pmount exfat-fuse python-pyudev florence at-spi2-core ruby-notify acpid
sudo dpkg -i ~/deb/sdl_2.0.5-mali_armhf.deb
sudo chmod a+x /etc/init.d/asplashscreen
sudo insserv /etc/init.d/asplashscreen
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*                  Adding Power Button feature                  *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
sudo cp ~/RetrOrangePi/Power_Button/restart /etc/acpi/events/button_power
sudo service acpid restart
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*                   Cleaning a few things...                    *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
mv -t ~/backup_v3/ cfg CHANGELOG.txt DISCLAIMER.txt gliden64.log goonies.dbg LICENSES.txt Logs Music Paks Saves ScreenShots \
Templates THANKS.txt Videos Pictures SOURCES.txt FS-UAE Documents Public ~/RetroPie/music/*.sh ~/RetroPie/music/*.py
sudo rm -rf ~/deb ~/update ~/updater_v4.tar.gz ~/hotfix.tar.gz ~/Desktop/emulation-station.sh ~/.xinitrc.amiga ~/sunxi-mali "/home/pi/RetroPie/roms/scummvm/+Start ScummVM.sh" /home/pi/RetroPie/roms/genesis/megadrive
wget -q http://www.retrorangepi.org/hotfix2.tar.gz
sudo tar -zxvf hotfix2.tar.gz -C /
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*            Installing the new Cosmos-ROPI theme...            *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""
sudo git clone https://github.com/retr0rangepi/es-theme-cosmos-ropi /etc/emulationstation/themes/cosmos-ropi
echo ""
echo "*****************************************************************"
echo "*                                                               *"
echo "*      ROPi 4.0 is installed. Run <sudo reboot> to restart.     *"
echo "*                                                               *"
echo "*****************************************************************"
echo ""

