#!/bin/bash #

clear cd /home/pi sudo rm -f tinkerBOY.tar sudo rm -f md5 sudo rm -rf tinkerBOY* error=0 printf "\ntinkerBOY Setup v1.0 [8.30.2019] [www.tinkerboy.xyz]\n\nLoading...\n\n" if wget -q "https://github.com/tinkerBOY-git/RetroPie/releases/download/setup/tinkerBOY.tar"; then wget -q "https://github.com/tinkerBOY-git/RetroPie/releases/download/setup/md5" if md5sum -c --status md5; then tar xf tinkerBOY.tar sudo rm -f tinkerBOY.tar sudo chmod -R 755 tinkerBOY for arg in "$@" do if [ "$arg" == "d1" ]; then printf "\n320x240: Setting up DPI settings...\n\n" sudo cp tinkerBOY/config/LQ035NC111.txt /boot/config.txt sudo cp tinkerBOY/config/dpi18_666.dtbo /boot/overlays fi if [ "$arg" == "d2" ]; then printf "\n320x240: Setting up DPI settings...\n\n" sudo cp tinkerBOY/config/Z035Q06.txt /boot/config.txt sudo cp tinkerBOY/config/dpi18_666.dtbo /boot/overlays fi if [ "$arg" == "d3" ]; then printf "\n640x480: Setting up DPI settings...\n\n" sudo cp tinkerBOY/config/xxx.txt /boot/config.txt sudo cp tinkerBOY/config/dpi18_666.dtbo /boot/overlays fi if [ "$arg" == "d4" ]; then printf "\n640x480: Setting up DPI settings...\n\n" sudo cp tinkerBOY/config/xxx.txt /boot/config.txt sudo cp tinkerBOY/config/dpi18_666.dtbo /boot/overlays fi if [ "$arg" == "v3" ]; then printf "\nV3: Setting up files...\n\n" sudo cp tinkerBOY/v3/asound.conf /etc sudo cp tinkerBOY/v3/v3_config.py /home/pi fi if [ "$arg" == "bm" ]; then STATUS=$(systemctl is-active battmon.service) if [[ ${STATUS} == 'active' ]]; then printf "\nStopping Battery Monitoring service..\n\n" sudo systemctl stop battmon.service fi sudo apt-get -y install python-serial if (dpkg -s python-serial >/dev/null 2>&1); then version=$(python tinkerBOY/v3/version.py) if [[ $version == *"tinkerBOY"* ]]; then flashed=false if ! [[ $version == *"V1.2"* ]]; then sudo apt-get -y install avrdude if (dpkg -s avrdude >/dev/null 2>&1); then stty -F /dev/ttyACM0 1200 sleep 2 hex_file="`pwd`/tinkerBOY/v3/v1.2.hex" #avrdude -C/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:$hex_file:i printf "\nUpdating your tinkerBOY Controller v3...\n\n" STATUS=$(avrdude -C/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:$hex_file:i) if [ $? -eq 0 ]; then flashed=true else error=4 fi else error=2 # avrdude no installed. fi fi if [[ $version == *"V1.2"* ]] || [ "$flashed" == true ]; then printf "\nInstalling Battery Monitoring service..\n\n" sudo cp -r tinkerBOY/battmon /home/pi sudo cp tinkerBOY/services/battmon.service /etc/systemd/system sudo chmod +x /etc/systemd/system/battmon.service fi else error=1 # not a tinkerBOY board or cannot open port. fi else error=2 # python-serial no installed. fi fi if [ "$arg" == "u" ]; then sudo apt-get -y install avrdude if dpkg -s avrdude >/dev/null 2>&1; then STATUS=$(systemctl is-active battmon.service) if [[ ${STATUS} == 'active' ]]; then printf "\nStopping Battery Monitoring service..\n\n" sudo systemctl stop battmon.service fi version=$(python tinkerBOY/v3/version.py) if [[ $version == *"tinkerBOY"* ]]; then flashed=false if ! [[ $version == *"V1.2"* ]]; then stty -F /dev/ttyACM0 1200 sleep 2 hex_file="`pwd`/tinkerBOY/v3/v1.2.hex" printf "\nUpdating your tinkerBOY Controller v3...\n\n" STATUS=$(avrdude -C/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:$hex_file:i) if [ $? -eq 0 ]; then flashed=true else error=4 fi fi else error=1 # not a tinkerBOY board or cannot open port. fi else error=2 # avrdude no installed. fi fi if [ "$arg" == "v2" ]; then printf "\nV2: Setting up files...\n\n" pwm_audio_enable="dtparam=audio=on" pwm_audio="dtoverlay=pwm-2chan,pin2=13,func2=4" sudo sh -c "echo '$pwm_audio_enable' >> /boot/config.txt" sudo sh -c "echo '$pwm_audio' >> /boot/config.txt" sudo cp tinkerBOY/v2/asound.conf /etc fi if [ "$arg" == "rg" ]; then printf "\nInstalling Adafruit-Retrogame service...\n\n" sudo cp tinkerBOY/Adafruit-Retrogame/retrogame /usr/local/bin sudo chmod 777 /usr/local/bin/retrogame sudo cp tinkerBOY/Adafruit-Retrogame/retrogame.cfg /boot sudo cp tinkerBOY/Adafruit-Retrogame/10-retrogame.rules /etc/udev/rules.d sudo cp tinkerBOY/services/retrogame.service /etc/systemd/system sudo chmod +x /etc/systemd/system/retrogame.service fi if [ "$arg" == "ss" ]; then printf "\nSetting up Safe Shutdown...\n\n" poweroff="dtoverlay=gpio-poweroff,gpiopin=10,active_low=1" shutdown="dtoverlay=gpio-shutdown,gpio_pin=11,active_low=1" sudo sh -c "echo '$poweroff' >> /boot/config.txt" sudo sh -c "echo '$shutdown' >> /boot/config.txt" fi if [ "$arg" == "db" ]; then printf "\nSetting up DPI Brightness Control service...\n\n" sudo cp tinkerBOY/dpi/dpi_brightness /usr/local/bin sudo chmod 777 /usr/local/bin/dpi_brightness sudo cp tinkerBOY/services/dpi_brightness.service /etc/systemd/system sudo chmod +x /etc/systemd/system/dpi_brightness.service fi done else error=8 fi else error=9 fi sudo rm -rf tinkerBOY sudo rm -f tinkerBOY.tar clear printf "\ntinkerBOY Setup v1.0 [8.30.2019] [www.tinkerboy.xyz]\n\n" if (( $error > 0 )); then printf "ERROR $error" printf "\n\nSomething went wrong! :(\n\n" else printf "OK!" printf "\n\nHave a nice day! :)\n\n" fi # SERVICE COMMANDS ############################### # sudo systemctl daemon-reload # sudo systemctl enable battmon.service # sudo systemctl start battmon.service # sudo systemctl stop battmon.service # sudo systemctl disable battmon.service # sudo systemctl status battmon.service # sudo journalctl -f -u battmon.service ################################################## # wget -O - https://github.com/tinkerBOY-git/RetroPie/releases/download/setup/tinkerBOY_setup.sh -q --show-progress | bash -s config v3 v2 battmon dpi_brightness # wget -O - https://github.com/tinkerBOY-git/RetroPie/releases/download/setup/tinkerBOY_setup.sh -q | bash -s d3 v3 v2 bm ss rg db u d6 #