How to install reef-pi

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,280
Location
Edmonton, Canada
Rating - 0%
0   0   0
Hi, over the last couple years I've been using a script I made up to install reef-pi as there's quite a few steps and easy to miss 1wire, I2C or whatever. In 95% of the cases it worked great and made things easy for people but it wasn't perfect which is why I never shared it directly. A couple weeks ago @Tom Bishop came across it and saw a few things that could be improved, he was able to add the ability to change the Pi password, add a user account to the Pi and add a hostname to access the Pi on the network. This was my favorite as I always assumed it was complicated. He was also able to redirect the script to the Pi location selector, previously I had a link people needed to visit and manually type in the time zone so this is nice. After he did this it inspired me to polish it up and make it nearly bullet proof so a user can't make any mistakes. Thanks @Tom Bishop for helping improve this.

The installation script does the following
  • updates Raspberry Pi Operating System
  • updates Raspberry Pi password
  • prompts for new Raspbbery Pi user account
  • prompts for hostname
  • prompts for time zone
  • enables time sync
  • installs reef-pi
  • configures reef-pi
  • generates website address to access reef-pi
  • removes reef-pi installation files
  • expands file system on microSD card
  • all installation files are deleted when install is complete or script is aborted
To use reef-pi you need a Raspberry Pi, a microSD card, a memory card reader and a connection to your network either via Wi-Fi or Ethernet.

To install reef-pi there are three steps, first you need to install the operating system for the Raspberry Pi if you haven't yet, then you need to connect to the Raspberry Pi via SSH and finally you need to run the installation script. If your Pi is up and running and you can connect to it via SSH you can skip to the third step.

1. Install Raspberry Pi Operating System
  1. Visit the following page using the link below and download the ‘Raspberry Pi Imager’ to match your computer. This will automate the install process.

    https://www.raspberrypi.com/software/

    saSWUx-K2JhbuC4McssQYenyP9Ap16CWNPZQZopg-GdjjsSHYWYkxWqgot5UTKmEtP6R4Vc5RiuYDkTqTHJGJoWS9Jst6wTEZ3tDbBCTaYsFgSF5p8olKI7JUyIAsg

  2. Once the download is finished, open the file and go through the step-by-step install wizard to install, all the defaults are sufficient.
  3. Open the Raspberry Pi Imager program that you just installed. Before opening the program make sure your SD card is in your card reader as the program searches this when it opens.
  4. Now Press CTRL + SHIFT + X on your keyboard to open the advanced settings page.
    j0pzQIjyabNapkyuB6kq9NZZ6jFAcfznQL_W2yDVSpA1-GcOcEU5HB_yEC6NJGgy2nopkdS_rDzfGACei1xJnRRgPH0E_cTpprA2FT-h2ErMuoU7kqU6j-RHkwMxXw


  5. You should now see the Advanced options screen below. Enable SSH and add a password for the Raspberry Pi.
  6. Enable Configure wifi and add your network SSID and Password to connect to your Wi-Fi
  7. Set the Wifi country to match your location.
  8. Click the Save button at the bottom

    W22qpL1x7tqd4JwsLY8ZgIWtENbUOIjSqwzi1Zp4e6KAD6FA_1GMKnnB33mKDDkzhoW2xeBShet7xQFTD36RttQXPTbQZGxpaQqeBIIeIuN_5tNbGNcgqG7-1VsjDw

  9. Now you can click the CHOOSE OS button
    reUp0xUqmE5ETDpgiKDi_IACjAGuddl3igGc0k_wYZj4_2-pzT-H-ILfmAa1Cg0qakJilGXQlk3tkB2iDL3iAaAg4NyGOE5L7Zl9oUYV01o07utNaoj9VsFUbnY6PcNrhPT2Zb0


  10. If you are using a Raspberry Pi 3 or 4 and want to connect a display, keyboard and mouse for a Windows-like feel you can install the first option with ‘Desktop’ however it is recommended to install the Lite OS version using the 2nd option marked in the image below.

    i67dh0erVzwx2J99GwfiRxvGEn-Nx_sYsFS5lAsZEGSHU8zFbYm2iv0NK7dquz2Af_NBa_3BhMF09JUbrTaOXZr4IdP09SlyZko8L1C7ew1iHO8PXcmN900VXEB_Pzl62zjBWGA


  11. Now you will see another menu, you should select Raspberry Pi OS Lite (32-bit). The minimal installation is best as there’s less code running in the background that could cause reliability issues and require frequent security updates.

    N9XTall5SZmV6p6aIz3xm1YAxhH7BzHu43tqmximYIUkoiZxGRXvSvZax_dnO3MxolyUyxaSkKTWgQcSjQZnXEu2zuoqnKVYN8Ls_WOzc1SvBY4qgkV7pqv5J5MVDCPin0tCUpA


  12. Now you can choose which SD card to write to, press the CHOOSE SD CARD button to select one.

    R8QUbvBeS0Ju8RmZmOCNzjtmh3aTiscTJmnLPfFj3yAG3_6xQjoCBIrlS-M-vpeZOmcVnnKJpnNyA9soPRTxriDQl3Du3HuTQAnWxHBHp8kI0UpBbaYo8TcjKTbeHdsHdo5HoOk

  13. Depending on your card reader you may have one or more items in the list, if you are unsure remove your card and view this screen. Look for the row where the GB changes from 0 to the size of your microSD card.

    rsVBEyvI7fcYFHwsxoTf9TgL3MN5q3AlGz6Ydk1ti6-JSwNEyKgC9cLbFqVxRmDMBMUOr-tYwsSPZnsLyLAAdKXx-6RkKhHo2jKGQVI911rqh8CS6wlmi9Z9LxLpJz-k0usOyoA

  14. Now you can click the WRITE button and sit back while it installs everything to your microSD card. This will take a while to complete but when it’s finished you’ll have the latest Raspberry Pi OS and should be able to connect to your network.

    B-j1Ud-ZiOPREe7X1BpMDhw6tCjnttk-sap0Pav_Df1D0-oVHJkr4rXAz8GRE55cjurUzNKLLRLRAjz5VvZL6yUbLxRTBmEnAhc4Z1VduB6sd4-OUNdl-QrW6GgOk6tNtoycLv8


  15. Once complete you’ll see the screen below. Click on the CONTINUE button to finish. You can now close the Raspberry Pi Imager program.
    m987ccAwZVvF04wKFJ-UZlfdti0Dl1rhAkJ9N614IzZWRb8fIz5Ik8Y1NZxjPidJ_QyvFSUvja399xHwLb8iONAZr4kFcHYUafABA9EgJ0ziYEbvgmGoBIVRo_4tEVulY71wtA8


1. Access Raspberry Pi via SSH

Now that the operating system is installed you need to connect to the Raspberry Pi using SSH so we can actually install reef-pi. Any program for SSH will work such as Putty or Tera Term.
  1. Download Putty from https://www.putty.org/, the link is at the top of the page.
  2. Install Putty, the default settings throughout the install are sufficient.
  3. Once it’s installed you can open it and you’ll see the screen in the image below. Follow the next 3 steps.
    1. Set the Connection type to SSH
    2. Change Host Name to the IP address of your Raspberry Pi. You can log into your router or run an IP scanner to get this.
    3. Set the Port to 22.
    4. Optional - You can enter a name in the Saved Sessions field and click the save button, now next time you want to connect to your Pi you only need to double click the Saved Session and it will load up.
  4. Click the Open button at the bottom to start the connection.

    osS4GaIMG9BdCxSkzT1TNy2ABvh_TZFhX_Yy83YjC2LDCWgipnyAo6BiQcSBwzLjUtck2TLh-TxeFLe6F_fi36tIn2bHF6V9Y5L5OIC-UOu2QhRsC5Ff9vAIUD8ItBoJv26TagA

  5. When you open a new connection you need to enter in your user name and password to log in to your Raspberry Pi, it will prompt you for this. The default username is pi and the password is what you set up earlier when you installed the Raspberry Pi OS. Note as you type the password nothing will show but it knows.

    F5INNS1BeH9oo1n6E0wOv5DpZvBgvixUa_bMFNVCif7nDiWiR9EtwNR9lGfPhiQq_ZCqFeaJI1CWilBygeGlAnkdGWmnYph924HlYDB7QYQTxMiG7g-zp4VuhI91Aj0Hcol-A5g

  6. Once successfully logged in you’ll see something like the following image. When you get this you are ready to complete the installation.

    Picture1

3. Install reef-pi​

  1. If you haven’t connected to your Raspberry Pi via SSH follow step 2.
  2. Once connected type in the following command to download the script to your Raspberry Pi and press enter.
    sudo wget -c https://www.robo-tank.ca/reef-pi_install_files.zip

  3. Now type in the following command to unzip the file you downloaded.
    sudo unzip reef-pi_install_files.zip

  4. Now type in the following command to start the installation, follow the on screen instructions.
    sudo bash reef-pi_install_files/install_reefpi.sh
This is what to expect during the installation. At the end of the script it provides a couple links to access reef-pi.

script1.PNG

script2.PNG

script3.PNG
 
OP
OP
robsworld78

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,280
Location
Edmonton, Canada
Rating - 0%
0   0   0
Here's the actual code.

Bash:
#!/bin/bash
    clear
    
    catch_exits() {  # function to clean up install files if script is aborted
        echo "Removing reef-pi Installation Files             ...takes less than 1 minute"
        CWD="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
        sudo rm -r "${CWD}" &> /dev/null
        sudo rm -r "reef-pi_install_files.zip" &> /dev/null
        sudo rm -r reef-pi-4.3-pi*.deb &> /dev/null
        exit 0
        printf "\n$(basename $0): exiting\n" 1>&2
        rm -rf $DIR
        exit 1
    }

    trap catch_exits 1 2 3 15 20  # run clean up if script is aborted

    cyan='\033[0;36m'
    NC='\033[0m' # No Color
    bold=$(tput bold)
    normal=$(tput sgr0)
    
    echo ""
    echo ""
    echo ""
    echo "This script will automate the installation process for reef-pi but does require attending."
    echo ""
    echo ""
    echo "This script does the following"
    echo "    * updates Raspberry Pi Operating System"
    echo "    * updates Raspberry Pi password"
    echo "    * prompts for new Raspbbery Pi user account"
    echo "    * prompts for hostname"
    echo "    * prompts for time zone"
    echo "    * enables time sync"
    echo "    * installs reef-pi"
    echo "    * configures reef-pi"
    echo "    * generates website address to access reef-pi"
    echo "    * removes reef-pi installation files"
    echo "    * expands file system on microSD card"
    echo ""
    echo ""
    echo ""
    echo "Press enter to continue or press ${bold}Ctrl + C${normal} to abort"
    read input
    echo ""
    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"


    # check if sudo is used
    if [ "$(id -u)" != 0 ]; then
        echo ""
        echo ""
        echo "You need to run this script with ${bold}sudo${normal} at the beginning of the command"
        echo ""
        echo ""
        echo ""
        echo ""
        exit 1
    fi


    # update password
    echo ""
    echo ""
    echo "Type in a new password for the Raspberry Pi and press ${bold}ENTER${normal} on your keyboard"
    echo "(note the cursor won't move as you type)"
    sudo passwd pi
    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"


    # create new user
    echo ""
    echo ""
    echo "Do you want to create a new user account?"
    echo "Type Y or N and press ${bold}ENTER${normal} on your keyboard"
    echo ""
    echo "    ${bold}Y${normal} = Create new user account"
    echo "    ${bold}N${normal} = No thanks"
    echo ""
    read addusr
    valid=0
    while (( $valid <= 0 ))  # continue to ask for for board type until valid one is entered
    do
        if [ -z "$addusr" ]  # check if board type is empty
        then
            echo "Selection not valid, please try again"
            read addusr
        else
            if [ $addusr = y ] || [ $addusr = Y ] || [ $addusr = Yes ] || [ $addusr = yes ] || [ $addusr = YES ]
            then
                echo ""
                echo -e "${cyan}________________________________________________________________________________________${NC}"
                echo ""
                echo ""
                echo "Type in your a new username and password for the Raspberry Pi and press ${bold}ENTER${normal}"
                echo "on your keyboard"
                read newusr
                sudo useradd -m $newusr &> /dev/null
                # add new user to same groups as pi user
                sudo usermod $newusr -a -G pi,adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio &> /dev/null
                # set passwd for new user
                sudo passwd $newusr
                echo ""
                echo "New user was created"
                echo ""
                valid=1
            elif [ $addusr = n ] || [ $addusr = N ] || [ $addusr = No ] || [ $addusr = no ] || [ $addusr = NO ]
            then
                echo ""
                valid=1
            else
                echo "Selection not valid, please try again"
                read addusr
                valid=0
            fi
        fi
    done
    


    # update hostname
    echo -e "${cyan}________________________________________________________________________________________${NC}"
    echo ""
    echo ""
    echo "Type in a hostname for reef-pi and press ${bold}ENTER${normal} on your keyboard, this is similar to"
    echo "a domain name to access a website."
    read new_hostname

    while [ -z "$new_hostname" ]  # continue to ask for hostname until one in entered
    do
        if [ -z "$new_hostname" ]  # check if hostname is empty
        then
            echo "Hostname was blank, please try again."
            read new_hostname
        fi
    done

    sudo raspi-config nonint do_hostname $new_hostname &> /dev/null
    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"


    # update timezone
    echo ""
    echo ""
    echo "Press ${bold}ENTER${normal} on your keyboard to select your Timezone from the list"
    read input
    dpkg-reconfigure tzdata
    echo -e "${cyan}________________________________________________________________________________________${NC}"


    # install reef-pi
    echo ""
    echo ""
    echo "Type in a number from the list below for the Raspberry Pi you will use and press"
    echo "${bold}ENTER${normal} on your keyboard"
    echo ""
    echo "    ${bold}1${normal} = Raspberry Pi Zero W or Zero 2 W"
    echo "    ${bold}2${normal} = Raspberry Pi 3"
    echo "    ${bold}3${normal} = Raspberry Pi 4"
    echo ""
    valid=0
    read pi

    while (( $valid <= 0 ))  # continue to ask for Pi version until valid one is entered
    do
        if [ -z "$pi" ]  # check if Pi version is empty
        then
            echo "Selection not valid, please try again"
            read pi
        else
            if [ $pi = 1 ]
            then
                rasp="Raspberry Pi Zero W"
                valid=1
            elif [ $pi = 2 ]
            then
                rasp="Raspberry Pi 3     "
                valid=1
            elif [ $pi = 3 ]
            then
                rasp="Raspberry Pi 4     "
                valid=1
            else
                echo "Selection not valid, please try again"
                read pi
                valid=0
            fi
        fi
    done

    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"
    echo ""
    echo ""
    echo "Would you like to setup reef-pi for a Robo-Tank Controller?"
    echo "Type Y or N and press ${bold}ENTER${normal} on your keyboard"
    echo ""
    echo "    ${bold}Y${normal} = yes setup for Robo-Tank"
    echo "    ${bold}N${normal} = no I will setup manually"
    echo ""
    read board

    robotank=0
    valid=0
    while (( $valid <= 0 ))  # continue to ask for for board type until valid one is entered
    do
        if [ -z "$board" ]  # check if board type is empty
        then
            echo "Selection not valid, please try again"
            read board
        else
            if [ $board = y ] || [ $board = Y ] || [ $board = Yes ] || [ $board = yes ] || [ $board = YES ]
            then
                robotank=1
                echo ""
                echo -e "${cyan}________________________________________________________________________________________${NC}"
                echo ""
                echo ""
                echo "Which Robo-Tank Controller do you have? Type in a number from the list below and"
                echo "and press ${bold}ENTER${normal} on your keyboard"
                echo ""
                echo "    ${bold}1${normal} = Robo-Tank Version 1"
                echo "    ${bold}2${normal} = Robo-Tank Version 2"
                echo "    ${bold}3${normal} = Robo-Tank Version 3 - Latest"
                echo ""
                read boardV

                while (( $valid <= 0 ))  # continue to ask for board version until valid one is entered
                do
                    if [ -z "$boardV" ]  # check if board version is empty
                    then
                        echo "Selection not valid, please try again"
                        read boardV
                    else
                        if [ $boardV = 1 ]
                        then
                            valid=1
                        elif [ $boardV = 2 ]
                        then
                            valid=1
                        elif [ $boardV = 3 ]
                        then
                            valid=1
                        else
                            echo "Selection not valid, please try again"
                            read boardV
                            valid=0
                        fi
                    fi
                done

                valid=1
            elif [ $board = n ] || [ $board = N ] || [ $board = No ] || [ $board = no ] || [ $board = NO ]
            then
                robotank=0
                valid=1
            else
                echo "Selection not valid, please try again"
                read board
                valid=0
            fi
        fi
    done

    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"
    echo ""
    echo ""
    echo -e "${cyan}The installtion will now begin, once it finishes you'll be prompted.${NC}"
    echo ""
    echo ""
    echo ""


    # # sync time
    echo "Syncing time                                    ...takes less than 1 minute"
    sudo systemctl start systemd-timesyncd &> /dev/null
    sudo systemctl enable systemd-timesyncd &> /dev/null


    # update Raspbian
    apt update &> /dev/null && apt upgrade -y &> /dev/null && apt autoremove -y &> /dev/null && apt install -y i2c-tools &> /dev/null & PID=$!
    echo "Updating Raspberry Pi Operating System          ...takes 1-30 minutes"
    # While process is running...
    while kill -0 $PID 2> /dev/null; do
    printf "\e[1;33m▓"
    sleep 15
    done
    echo ""
    printf "\e[0;37m"

    # Install reef-pi
    echo "${normal}Installing reef-pi on a" $rasp "         ...takes about 1 minute"

    if [ $pi = 1 ]
    then
        wget -c https://github.com/reef-pi/reef-pi/releases/download/4.3/reef-pi-4.3-pi0.deb &> /dev/null
        sudo dpkg -i reef-pi-4.3-pi0.deb &> /dev/null
    elif [ $pi = 2 ]
    then
        wget -c https://github.com/reef-pi/reef-pi/releases/download/4.3/reef-pi-4.3-pi3.deb &> /dev/null
        sudo dpkg -i reef-pi-4.3-pi3.deb &> /dev/null
    else
        wget -c https://github.com/reef-pi/reef-pi/releases/download/4.3/reef-pi-4.3-pi3.deb &> /dev/null
        sudo dpkg -i reef-pi-4.3-pi3.deb &> /dev/null
    fi


    echo "Backing up Raspberry Pi /boot/config.txt file   ...takes about 1 minute"
    # Verify if config.org exists and if not create a backup config.txt file for historical purposes
    FILE=/boot/config.org
    if [ ! -f "$FILE" ]; then
        sudo cp /boot/config.txt /boot/config.org &> /dev/null
    fi

    if grep -q 'i2c-bcm2708' /etc/modules; then
        echo ""
    else
        echo 'i2c-bcm2708' >> /etc/modules
    fi
    if grep -q 'i2c-dev' /etc/modules; then
        echo ""
    else
        echo 'i2c-dev' >> /etc/modules
    fi
    
    # Enable 1wire, rpi-pwm and i2c and set baudrate
    sudo sed -i 's/#dtparam=i2c_arm=on$/dtparam=i2c_arm=on,dtparam=i2c_arm_baudrate=10000\ndtoverlay=pwm-2chan/g' /boot/config.txt &> /dev/null
    sudo raspi-config nonint do_onewire 0 &> /dev/null
    # Disable spi
    sudo raspi-config nonint do_spi 1 &> /dev/null

    if [ $robotank = 1 ]
    then
        echo "Installing database for Robo-Tank               ...takes about 1 minute"
        sudo systemctl stop reef-pi.service &> /dev/null

        if [ $boardV = 1 ]
        then
            CWD="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
            sudo cp "${CWD}/v1/reef-pi.db" /var/lib/reef-pi/reef-pi.db &> /dev/null
        elif [ $boardV = 2 ]
        then
            CWD="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
            sudo cp "${CWD}/v2/reef-pi.db" /var/lib/reef-pi/reef-pi.db &> /dev/null
            sudo sed -i 's/dtoverlay=w1-gpio$/dtoverlay=w1-gpio,gpiopin=4\ndtoverlay=w1-gpio,gpiopin=23/g' /boot/config.txt &> /dev/null
        else
            CWD="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
            sudo cp "${CWD}/v3/reef-pi.db" /var/lib/reef-pi/reef-pi.db &> /dev/null
            sudo sed -i 's/dtoverlay=w1-gpio$/dtoverlay=w1-gpio,gpiopin=4\ndtoverlay=w1-gpio,gpiopin=22/g' /boot/config.txt &> /dev/null
        fi

        sudo systemctl start reef-pi.service &> /dev/null
        sleep 3
    else
        echo "Updating /boot/config.txt                       ...takes about 1 minute"
        sudo systemctl stop reef-pi.service &> /dev/null
        sudo rm -rf /var/lib/reef-pi/reef-pi.db &> /dev/null
        sudo systemctl start reef-pi.service &> /dev/null
        sleep 3
    fi


    echo "Removing reef-pi Installation Files             ...takes less than 1 minute"
    CWD="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    sudo rm -r "${CWD}" &> /dev/null
    sudo rm -r "reef-pi_install_files.zip" &> /dev/null
    sudo rm -r reef-pi-4.3-pi*.deb &> /dev/null
    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"
    echo ""
    echo ""
    echo ""
    echo ""
    echo ""
    echo "You have successfully installed reef-pi, you can now press ${bold}ENTER${normal} on your keyboard to"
    echo "restart your Raspberry Pi."
    echo ""
    echo "After the Raspberry Pi restarts open a web browser from any device on your local "
    echo "network and type one of the links below. The first link is the IP address of the"
    echo "Raspberry Pi, the 2nd link is the hostname you added during the installation. Write"
    echo "these down or create a bookmark in your browser. Note it is possible your network"
    echo "changes the IP address for the Raspberry Pi and the link no longer works, this is"
    echo "why we setup a hostname as this will never change."
    echo ""
    ip= hostname -I | awk '{ print "http://" $1 }'
    echo "${bold}http://$new_hostname${normal}"
    echo ""
    echo ""

    echo "The default login for reef-pi is as follows."
    echo ""
    echo "Username = ${bold}reef-pi${normal}"
    echo "Password = ${bold}reef-pi${normal}"
    echo ""
    echo ""
    echo "Have a great day!"
    echo ""
    echo ""
    echo ""
    echo "Press ${bold}ENTER${normal} on your keyboard to restart the Raspberry Pi."
    echo ""
    echo ""
    echo ""
    
    read input
    # # # expand file system
    sudo raspi-config --expand-rootfs &> /dev/null
    sudo reboot
 

theatrus

Valuable Member
View Badges
Joined
Mar 26, 2016
Messages
1,943
Reaction score
3,337
Location
Sacramento, CA area
Rating - 0%
0   0   0
Here's the actual code.

Bash:
#!/bin/bash
    clear
   
    catch_exits() {  # function to clean up install files if script is aborted
        echo "Removing reef-pi Installation Files             ...takes less than 1 minute"
        CWD="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
        sudo rm -r "${CWD}" &> /dev/null
        sudo rm -r "reef-pi_install_files.zip" &> /dev/null
        sudo rm -r reef-pi-4.3-pi*.deb &> /dev/null
        exit 0
        printf "\n$(basename $0): exiting\n" 1>&2
        rm -rf $DIR
        exit 1
    }

    trap catch_exits 1 2 3 15 20  # run clean up if script is aborted

    cyan='\033[0;36m'
    NC='\033[0m' # No Color
    bold=$(tput bold)
    normal=$(tput sgr0)
   
    echo ""
    echo ""
    echo ""
    echo "This script will automate the installation process for reef-pi but does require attending."
    echo ""
    echo ""
    echo "This script does the following"
    echo "    * updates Raspberry Pi Operating System"
    echo "    * updates Raspberry Pi password"
    echo "    * prompts for new Raspbbery Pi user account"
    echo "    * prompts for hostname"
    echo "    * prompts for time zone"
    echo "    * enables time sync"
    echo "    * installs reef-pi"
    echo "    * configures reef-pi"
    echo "    * generates website address to access reef-pi"
    echo "    * removes reef-pi installation files"
    echo "    * expands file system on microSD card"
    echo ""
    echo ""
    echo ""
    echo "Press enter to continue or press ${bold}Ctrl + C${normal} to abort"
    read input
    echo ""
    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"


    # check if sudo is used
    if [ "$(id -u)" != 0 ]; then
        echo ""
        echo ""
        echo "You need to run this script with ${bold}sudo${normal} at the beginning of the command"
        echo ""
        echo ""
        echo ""
        echo ""
        exit 1
    fi


    # update password
    echo ""
    echo ""
    echo "Type in a new password for the Raspberry Pi and press ${bold}ENTER${normal} on your keyboard"
    echo "(note the cursor won't move as you type)"
    sudo passwd pi
    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"


    # create new user
    echo ""
    echo ""
    echo "Do you want to create a new user account?"
    echo "Type Y or N and press ${bold}ENTER${normal} on your keyboard"
    echo ""
    echo "    ${bold}Y${normal} = Create new user account"
    echo "    ${bold}N${normal} = No thanks"
    echo ""
    read addusr
    valid=0
    while (( $valid <= 0 ))  # continue to ask for for board type until valid one is entered
    do
        if [ -z "$addusr" ]  # check if board type is empty
        then
            echo "Selection not valid, please try again"
            read addusr
        else
            if [ $addusr = y ] || [ $addusr = Y ] || [ $addusr = Yes ] || [ $addusr = yes ] || [ $addusr = YES ]
            then
                echo ""
                echo -e "${cyan}________________________________________________________________________________________${NC}"
                echo ""
                echo ""
                echo "Type in your a new username and password for the Raspberry Pi and press ${bold}ENTER${normal}"
                echo "on your keyboard"
                read newusr
                sudo useradd -m $newusr &> /dev/null
                # add new user to same groups as pi user
                sudo usermod $newusr -a -G pi,adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio &> /dev/null
                # set passwd for new user
                sudo passwd $newusr
                echo ""
                echo "New user was created"
                echo ""
                valid=1
            elif [ $addusr = n ] || [ $addusr = N ] || [ $addusr = No ] || [ $addusr = no ] || [ $addusr = NO ]
            then
                echo ""
                valid=1
            else
                echo "Selection not valid, please try again"
                read addusr
                valid=0
            fi
        fi
    done
   


    # update hostname
    echo -e "${cyan}________________________________________________________________________________________${NC}"
    echo ""
    echo ""
    echo "Type in a hostname for reef-pi and press ${bold}ENTER${normal} on your keyboard, this is similar to"
    echo "a domain name to access a website."
    read new_hostname

    while [ -z "$new_hostname" ]  # continue to ask for hostname until one in entered
    do
        if [ -z "$new_hostname" ]  # check if hostname is empty
        then
            echo "Hostname was blank, please try again."
            read new_hostname
        fi
    done

    sudo raspi-config nonint do_hostname $new_hostname &> /dev/null
    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"


    # update timezone
    echo ""
    echo ""
    echo "Press ${bold}ENTER${normal} on your keyboard to select your Timezone from the list"
    read input
    dpkg-reconfigure tzdata
    echo -e "${cyan}________________________________________________________________________________________${NC}"


    # install reef-pi
    echo ""
    echo ""
    echo "Type in a number from the list below for the Raspberry Pi you will use and press"
    echo "${bold}ENTER${normal} on your keyboard"
    echo ""
    echo "    ${bold}1${normal} = Raspberry Pi Zero W or Zero 2 W"
    echo "    ${bold}2${normal} = Raspberry Pi 3"
    echo "    ${bold}3${normal} = Raspberry Pi 4"
    echo ""
    valid=0
    read pi

    while (( $valid <= 0 ))  # continue to ask for Pi version until valid one is entered
    do
        if [ -z "$pi" ]  # check if Pi version is empty
        then
            echo "Selection not valid, please try again"
            read pi
        else
            if [ $pi = 1 ]
            then
                rasp="Raspberry Pi Zero W"
                valid=1
            elif [ $pi = 2 ]
            then
                rasp="Raspberry Pi 3     "
                valid=1
            elif [ $pi = 3 ]
            then
                rasp="Raspberry Pi 4     "
                valid=1
            else
                echo "Selection not valid, please try again"
                read pi
                valid=0
            fi
        fi
    done

    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"
    echo ""
    echo ""
    echo "Would you like to setup reef-pi for a Robo-Tank Controller?"
    echo "Type Y or N and press ${bold}ENTER${normal} on your keyboard"
    echo ""
    echo "    ${bold}Y${normal} = yes setup for Robo-Tank"
    echo "    ${bold}N${normal} = no I will setup manually"
    echo ""
    read board

    robotank=0
    valid=0
    while (( $valid <= 0 ))  # continue to ask for for board type until valid one is entered
    do
        if [ -z "$board" ]  # check if board type is empty
        then
            echo "Selection not valid, please try again"
            read board
        else
            if [ $board = y ] || [ $board = Y ] || [ $board = Yes ] || [ $board = yes ] || [ $board = YES ]
            then
                robotank=1
                echo ""
                echo -e "${cyan}________________________________________________________________________________________${NC}"
                echo ""
                echo ""
                echo "Which Robo-Tank Controller do you have? Type in a number from the list below and"
                echo "and press ${bold}ENTER${normal} on your keyboard"
                echo ""
                echo "    ${bold}1${normal} = Robo-Tank Version 1"
                echo "    ${bold}2${normal} = Robo-Tank Version 2"
                echo "    ${bold}3${normal} = Robo-Tank Version 3 - Latest"
                echo ""
                read boardV

                while (( $valid <= 0 ))  # continue to ask for board version until valid one is entered
                do
                    if [ -z "$boardV" ]  # check if board version is empty
                    then
                        echo "Selection not valid, please try again"
                        read boardV
                    else
                        if [ $boardV = 1 ]
                        then
                            valid=1
                        elif [ $boardV = 2 ]
                        then
                            valid=1
                        elif [ $boardV = 3 ]
                        then
                            valid=1
                        else
                            echo "Selection not valid, please try again"
                            read boardV
                            valid=0
                        fi
                    fi
                done

                valid=1
            elif [ $board = n ] || [ $board = N ] || [ $board = No ] || [ $board = no ] || [ $board = NO ]
            then
                robotank=0
                valid=1
            else
                echo "Selection not valid, please try again"
                read board
                valid=0
            fi
        fi
    done

    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"
    echo ""
    echo ""
    echo -e "${cyan}The installtion will now begin, once it finishes you'll be prompted.${NC}"
    echo ""
    echo ""
    echo ""


    # # sync time
    echo "Syncing time                                    ...takes less than 1 minute"
    sudo systemctl start systemd-timesyncd &> /dev/null
    sudo systemctl enable systemd-timesyncd &> /dev/null


    # update Raspbian
    apt update &> /dev/null && apt upgrade -y &> /dev/null && apt autoremove -y &> /dev/null && apt install -y i2c-tools &> /dev/null & PID=$!
    echo "Updating Raspberry Pi Operating System          ...takes 1-30 minutes"
    # While process is running...
    while kill -0 $PID 2> /dev/null; do
    printf "\e[1;33m▓"
    sleep 15
    done
    echo ""
    printf "\e[0;37m"

    # Install reef-pi
    echo "${normal}Installing reef-pi on a" $rasp "         ...takes about 1 minute"

    if [ $pi = 1 ]
    then
        wget -c https://github.com/reef-pi/reef-pi/releases/download/4.3/reef-pi-4.3-pi0.deb &> /dev/null
        sudo dpkg -i reef-pi-4.3-pi0.deb &> /dev/null
    elif [ $pi = 2 ]
    then
        wget -c https://github.com/reef-pi/reef-pi/releases/download/4.3/reef-pi-4.3-pi3.deb &> /dev/null
        sudo dpkg -i reef-pi-4.3-pi3.deb &> /dev/null
    else
        wget -c https://github.com/reef-pi/reef-pi/releases/download/4.3/reef-pi-4.3-pi3.deb &> /dev/null
        sudo dpkg -i reef-pi-4.3-pi3.deb &> /dev/null
    fi


    echo "Backing up Raspberry Pi /boot/config.txt file   ...takes about 1 minute"
    # Verify if config.org exists and if not create a backup config.txt file for historical purposes
    FILE=/boot/config.org
    if [ ! -f "$FILE" ]; then
        sudo cp /boot/config.txt /boot/config.org &> /dev/null
    fi

    if grep -q 'i2c-bcm2708' /etc/modules; then
        echo ""
    else
        echo 'i2c-bcm2708' >> /etc/modules
    fi
    if grep -q 'i2c-dev' /etc/modules; then
        echo ""
    else
        echo 'i2c-dev' >> /etc/modules
    fi
   
    # Enable 1wire, rpi-pwm and i2c and set baudrate
    sudo sed -i 's/#dtparam=i2c_arm=on$/dtparam=i2c_arm=on,dtparam=i2c_arm_baudrate=10000\ndtoverlay=pwm-2chan/g' /boot/config.txt &> /dev/null
    sudo raspi-config nonint do_onewire 0 &> /dev/null
    # Disable spi
    sudo raspi-config nonint do_spi 1 &> /dev/null

    if [ $robotank = 1 ]
    then
        echo "Installing database for Robo-Tank               ...takes about 1 minute"
        sudo systemctl stop reef-pi.service &> /dev/null

        if [ $boardV = 1 ]
        then
            CWD="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
            sudo cp "${CWD}/v1/reef-pi.db" /var/lib/reef-pi/reef-pi.db &> /dev/null
        elif [ $boardV = 2 ]
        then
            CWD="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
            sudo cp "${CWD}/v2/reef-pi.db" /var/lib/reef-pi/reef-pi.db &> /dev/null
            sudo sed -i 's/dtoverlay=w1-gpio$/dtoverlay=w1-gpio,gpiopin=4\ndtoverlay=w1-gpio,gpiopin=23/g' /boot/config.txt &> /dev/null
        else
            CWD="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
            sudo cp "${CWD}/v3/reef-pi.db" /var/lib/reef-pi/reef-pi.db &> /dev/null
            sudo sed -i 's/dtoverlay=w1-gpio$/dtoverlay=w1-gpio,gpiopin=4\ndtoverlay=w1-gpio,gpiopin=22/g' /boot/config.txt &> /dev/null
        fi

        sudo systemctl start reef-pi.service &> /dev/null
        sleep 3
    else
        echo "Updating /boot/config.txt                       ...takes about 1 minute"
        sudo systemctl stop reef-pi.service &> /dev/null
        sudo rm -rf /var/lib/reef-pi/reef-pi.db &> /dev/null
        sudo systemctl start reef-pi.service &> /dev/null
        sleep 3
    fi


    echo "Removing reef-pi Installation Files             ...takes less than 1 minute"
    CWD="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    sudo rm -r "${CWD}" &> /dev/null
    sudo rm -r "reef-pi_install_files.zip" &> /dev/null
    sudo rm -r reef-pi-4.3-pi*.deb &> /dev/null
    echo ""
    echo -e "${cyan}________________________________________________________________________________________${NC}"
    echo ""
    echo ""
    echo ""
    echo ""
    echo ""
    echo "You have successfully installed reef-pi, you can now press ${bold}ENTER${normal} on your keyboard to"
    echo "restart your Raspberry Pi."
    echo ""
    echo "After the Raspberry Pi restarts open a web browser from any device on your local "
    echo "network and type one of the links below. The first link is the IP address of the"
    echo "Raspberry Pi, the 2nd link is the hostname you added during the installation. Write"
    echo "these down or create a bookmark in your browser. Note it is possible your network"
    echo "changes the IP address for the Raspberry Pi and the link no longer works, this is"
    echo "why we setup a hostname as this will never change."
    echo ""
    ip= hostname -I | awk '{ print "http://" $1 }'
    echo "${bold}http://$new_hostname${normal}"
    echo ""
    echo ""

    echo "The default login for reef-pi is as follows."
    echo ""
    echo "Username = ${bold}reef-pi${normal}"
    echo "Password = ${bold}reef-pi${normal}"
    echo ""
    echo ""
    echo "Have a great day!"
    echo ""
    echo ""
    echo ""
    echo "Press ${bold}ENTER${normal} on your keyboard to restart the Raspberry Pi."
    echo ""
    echo ""
    echo ""
   
    read input
    # # # expand file system
    sudo raspi-config --expand-rootfs &> /dev/null
    sudo reboot

Want to throw this on GitHub as well?

There are a few more tricks you can do to reduce the steps, including just a "curl https://url | sudo sh -c" :)
 
OP
OP
robsworld78

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,280
Location
Edmonton, Canada
Rating - 0%
0   0   0
Want to throw this on GitHub as well?

There are a few more tricks you can do to reduce the steps, including just a "curl https://url | sudo sh -c" :)
Yeah I'll get it on GitHub soon, there's a couple other things I should be adding as well.

Thanks for that, I asked @Tom Bishop about shortening my commands to start the scripts and he recommended the same but as that will automatically launch the script I thought it might be better so people can download and look at the script if they wish before running it.
 

Brewski262

Active Member
View Badges
Joined
Jan 9, 2021
Messages
192
Reaction score
689
Location
Nashotah WI- Waukesha county
Rating - 0%
0   0   0
so i have reef-pi up and running with just a temp sensor. everything is working as it should. however, i am wanting to access reef pi outside of my local net work. attempting to use VNC currently. its installed and works except when i type in my "hostname.local" chromium gives an error saying "hostname.local refused to connect" and says to check the connection and the proxy and firewall.

tried to look in chromiums advanced settings for firewall and proxy settings but it give me another error message stating " When running Chromium under a supported desktop environment, the system proxy settings will be used. However, either your system is not supported or there was a problem launching your system configuration.

But you can still configure via the command line. Please see man chromium-browser-v7 for more information on flags and environment variables."

any ideas on what i am doing wrong? Thanks in advanced!!
 

twelvefive

Well-Known Member
View Badges
Joined
Jul 2, 2013
Messages
576
Reaction score
314
Location
Alabama
Rating - 0%
0   0   0
so i have reef-pi up and running with just a temp sensor. everything is working as it should. however, i am wanting to access reef pi outside of my local net work. attempting to use VNC currently. its installed and works except when i type in my "hostname.local" chromium gives an error saying "hostname.local refused to connect" and says to check the connection and the proxy and firewall.

tried to look in chromiums advanced settings for firewall and proxy settings but it give me another error message stating " When running Chromium under a supported desktop environment, the system proxy settings will be used. However, either your system is not supported or there was a problem launching your system configuration.

But you can still configure via the command line. Please see man chromium-browser-v7 for more information on flags and environment variables."

any ideas on what i am doing wrong? Thanks in advanced!!
You either need to set up a VPN or port forwarding to ssh from your router to access it outside your local network.

 

Brewski262

Active Member
View Badges
Joined
Jan 9, 2021
Messages
192
Reaction score
689
Location
Nashotah WI- Waukesha county
Rating - 0%
0   0   0
You either need to set up a VPN or port forwarding to ssh from your router to access it outside your local network.

SSH wont allow me to view the dashboard of reef pi i dont think? unless im miss understanding that. SSH will get me into the terminal window.

as far as a VPN goes, i am currently running one. tried with and without it.

according to a Github link VNC or TOR is the only options?


to be clear, VNC works, i connect, can use the desktop GUI. everything is fine until i open chromium and try to connect via .local from the PI
 

twelvefive

Well-Known Member
View Badges
Joined
Jul 2, 2013
Messages
576
Reaction score
314
Location
Alabama
Rating - 0%
0   0   0
SSH wont allow me to view the dashboard of reef pi i dont think? unless im miss understanding that. SSH will get me into the terminal window.

as far as a VPN goes, i am currently running one. tried with and without it.

according to a Github link VNC or TOR is the only options?


to be clear, VNC works, i connect, can use the desktop GUI. everything is fine until i open chromium and try to connect via .local from the PI
Ah gotcha. Do you have realvnc-vnc-server and realvnc-vnc-viewer installed? If so, you can use https://www.realvnc.com/en/raspberrypi/#sign-up
 

Brewski262

Active Member
View Badges
Joined
Jan 9, 2021
Messages
192
Reaction score
689
Location
Nashotah WI- Waukesha county
Rating - 0%
0   0   0
yes, server and viewer both installed and works, issue seems to be as i mentioned above

when i type in my "hostname.local" via VNC, chromium gives an error saying "hostname.local refused to connect" and says to check the connection and the proxy and firewall.

tried to look in chromiums advanced settings for firewall and proxy settings but it give me another error message stating " When running Chromium under a supported desktop environment, the system proxy settings will be used. However, either your system is not supported or there was a problem launching your system configuration.

But you can still configure via the command line. Please see man chromium-browser-v7 for more information on flags and environment variables."
 

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,825
Reaction score
17,041
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
@Ranjib any idea on how to access reef-pi remotely with the above mentioned issue with chromium?
use ipaddress directly. I think this is due to mdns service. Check if you have avahi running on the pi or search on .local name resolution in chromium
 

AbjectMaelstroM

Valuable Member
View Badges
Joined
Jul 21, 2019
Messages
1,526
Reaction score
1,810
Location
RVA
Rating - 100%
1   0   0
yes, server and viewer both installed and works, issue seems to be as i mentioned above

when i type in my "hostname.local" via VNC, chromium gives an error saying "hostname.local refused to connect" and says to check the connection and the proxy and firewall.

tried to look in chromiums advanced settings for firewall and proxy settings but it give me another error message stating " When running Chromium under a supported desktop environment, the system proxy settings will be used. However, either your system is not supported or there was a problem launching your system configuration.

But you can still configure via the command line. Please see man chromium-browser-v7 for more information on flags and environment variables."
Use the actual local IP address for the Pi instead of hostname.local. I would also suggest setting up a VPN into your personal network rather than using VNC. I've been using a VPN through my Unifi setup for close to two years and its much more responsive and stable than VNC has ever been.
 

bishoptf

Valuable Member
View Badges
Joined
Jan 1, 2019
Messages
1,344
Reaction score
1,720
Location
Missouri
Rating - 0%
0   0   0
that worked perfect. thanks for the help!
Bumping this old thread for remote access I would really go look at tailscale - https://tailscale.com/ it should allow you to do what you want and does it in a pretty secure way. Would recommend it over a lot of the other stuff unless your rolling your own vpn etc...

When I get some spare cycles, I'd like to throw together a remote access how-to, maybe we can throw that into the mix of the other documents that @robsworld78 has written up. It gets asked about frequently and think it would be good to have something. :)
 
OP
OP
robsworld78

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,280
Location
Edmonton, Canada
Rating - 0%
0   0   0
Bumping this old thread for remote access I would really go look at tailscale - https://tailscale.com/ it should allow you to do what you want and does it in a pretty secure way. Would recommend it over a lot of the other stuff unless your rolling your own vpn etc...

When I get some spare cycles, I'd like to throw together a remote access how-to, maybe we can throw that into the mix of the other documents that @robsworld78 has written up. It gets asked about frequently and think it would be good to have something. :)
Thanks, one thing I don't like about them is they require you to sign in using another account like Google. Someone mentioned using Teamviewer instead of a VPN, I personally like this idea as it's very easy and should be safe?
 

Mastering the art of locking and unlocking water pathways: What type of valves do you have on your aquarium plumbing?

  • Ball valves.

    Votes: 75 51.7%
  • Gate valves.

    Votes: 74 51.0%
  • Check valves.

    Votes: 37 25.5%
  • None.

    Votes: 32 22.1%
  • Other.

    Votes: 9 6.2%
Back
Top