#!/bin/bash -e # Run 'sudo iiab-remoteit' to enable remote.it AND get a new claim code. Also # lets you download + install the latest Device Package to IIAB. GENERAL TIPS: # http://FAQ.IIAB.IO -> "How can I remotely manage my Internet-in-a-Box?" # 'remoteit' Device Package AND /usr/bin/remoteit CLI already installed by: # https://github.com/iiab/iiab/blob/master/roles/remoteit/tasks/install.yml # 2022-04-03: SEE ALSO roles/remoteit/templates/iiab-remote.old echo -e "\nhttps://remote.it can help you remotely manage this IIAB.\n" echo -e "Let's generate a claim code and enable it. Documentation:\n" echo -e "https://github.com/iiab/iiab/blob/master/roles/remoteit/README.md\n" if [ -f /etc/remoteit/config.json ]; then echo -en "\e[1mTo proceed we will delete /etc/remoteit/config.json, Ok? [Y/n]\e[0m " read ans < /dev/tty # Strips outer whitespace, whether we like it or not! echo [[ $ans = "n" ]] || [[ $ans = "N" ]] && exit 1 fi # Explanation below, on lines 65-72 if [ -f /etc/remoteit/registration ]; then echo -en "\e[1mTo proceed we will delete /etc/remoteit/registration, Ok? [Y/n]\e[0m " read ans < /dev/tty # Strips outer whitespace, whether we like it or not! echo [[ $ans = "n" ]] || [[ $ans = "N" ]] && exit 1 fi echo -e "\nThis IIAB must be online to begin!\n" echo -en "\e[1mOptionally download + install latest remote.it Device Package? [y/N]\e[0m " read ans < /dev/tty # Strips outer whitespace, whether we like it or not! echo if [[ $ans = "y" ]] || [[ $ans = "Y" ]]; then # 2022-04-02: Full Path Avoids problematic /usr/local/bin/apt on Linux Mint /usr/bin/apt -y purge "remoteit*" || true # Why the brutal purge? Even 'apt -y reinstall remoteit.*.deb' is stronger # than 'install -y' in install_agent.sh, but still sometimes insufficient! # apt install & enable "latest" remote.it Device Package for your CPU/OS curl -L https://downloads.remote.it/remoteit/install_agent.sh | sh else # 2022-04-04: Stop/Delete/Bounce sequence follows official suggestion here: # https://support.remote.it/hc/en-us/articles/360061228252-Oops-I-cloned-an-SD-card- echo -e "In a few seconds, all 3 {connectd, schannel, remoteit@...} should be enabled!\n" systemctl stop connectd # "Safer" (though it's generally exited already!) # If someone manually deleted the dir, this blocks generation of claim code [ ! -d /etc/remoteit ] && mkdir /etc/remoteit [ -f /etc/remoteit/config.json ] && mv /etc/remoteit/config.json /etc/remoteit/config.json.$(date +%F_%T_%Z) [ -f /etc/remoteit/registration ] && mv /etc/remoteit/registration /etc/remoteit/registration.$(date +%F_%T_%Z) # /etc/remoteit/registration is deleted above, but just FYI if it existed: # # 1) If /etc/remoteit/registration exists and is empty, connectd (below) # will not create /etc/remoteit/config.json # 2) If /etc/remoteit/registration contains an invalid license key, connectd # (below) will create /etc/remoteit/config.json WITH a claim code. # 3) If /etc/remoteit/registration contains a valid license key, connectd # (below) will create /etc/remoteit/config.json WITHOUT a claim code. systemctl start connectd # Claim Code logic + kickstarts 2 svcs below # /usr/share/remoteit/refresh.sh does the same thing (or close) as per: # https://docs.remote.it/oem-and-bulk-provisioning/registration-into-a-users-account systemctl enable connectd # 2 enable lines, like enable-or-disable.yml # schannel = "Remote tcp command service" started by connectd above if nec systemctl enable schannel # 2 enable lines, like enable-or-disable.yml # "Remote tcp connection service" appears a few seconds after connectd is # started above. Auto-enabled when spawned by connectd, SO NOT NEC HERE: # systemctl enable $(ls /etc/systemd/system/multi-user.target.wants/ | grep remoteit@*) # These systemd service names e.g. remoteit@80:00:01:7F:7E:00:56:36.service # change, e.g. when a new claim code is generated, and more arise when the # IIAB device is registered to a remote.it account (#3166), etc. fi if grep -q '^remoteit_enabled:' /etc/iiab/local_vars.yml; then sed -i "s/^remoteit_enabled:.*/remoteit_enabled: True/" /etc/iiab/local_vars.yml else echo "remoteit_enabled: True" >> /etc/iiab/local_vars.yml fi claim_code=$(grep claim /etc/remoteit/config.json | rev | cut -d\" -f2 | rev) echo -e "\nYour new claim code is \e[44;1m${claim_code}\e[0m -- YOUR NEXT STEPS ARE...\n" echo -e "\e[1m1) Install the remote.it Desktop Application on your own laptop/computer:\e[0m" echo -e " https://remote.it/download/\n" echo -e "\e[1m2) Use the above 8-character claim code WITHIN 24H as shown here:\e[0m" echo -e " https://docs.remote.it/software/device-package/installation#3.-claim-and-register-the-device\n"