2021-11-01 16:42:52 -06:00
|
|
|
#! /usr/bin/env bash
|
2022-12-28 20:05:39 -07:00
|
|
|
# This script will install WROLPi to `/opt/wrolpi` on a fresh/empty machine. It is expected to be run once to
|
2021-11-01 16:42:52 -06:00
|
|
|
# install, and any subsequent runs will update WROLPi. This script assumes it will be run as the `root` user.
|
|
|
|
|
|
|
|
|
|
Help() {
|
|
|
|
|
# Display Help
|
2022-12-28 20:05:39 -07:00
|
|
|
echo "Install WROLPi onto this machine."
|
2021-11-01 16:42:52 -06:00
|
|
|
echo
|
|
|
|
|
echo "Syntax: install.sh [-h] [-b BRANCH]"
|
|
|
|
|
echo "options:"
|
|
|
|
|
echo "h Print this help."
|
|
|
|
|
echo "b Install from this git BRANCH."
|
|
|
|
|
echo
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-15 18:25:06 -07:00
|
|
|
BRANCH="release"
|
2021-11-01 16:42:52 -06:00
|
|
|
while getopts ":hb:" option; do
|
|
|
|
|
case $option in
|
|
|
|
|
h) # display Help
|
|
|
|
|
Help
|
|
|
|
|
exit
|
|
|
|
|
;;
|
|
|
|
|
b)
|
|
|
|
|
BRANCH="${OPTARG}"
|
|
|
|
|
;;
|
|
|
|
|
*) # invalid argument(s)
|
|
|
|
|
echo "Error: Invalid option"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2022-03-16 18:09:02 -06:00
|
|
|
rpi=false
|
|
|
|
|
if (grep 'Raspberry Pi' /proc/cpuinfo >/dev/null); then
|
|
|
|
|
rpi=true
|
|
|
|
|
fi
|
|
|
|
|
|
2026-10-14 15:51:40 -06:00
|
|
|
# Raspberry Pi OS and Debian both report the Debian release in VERSION_ID. WROLPi requires Debian 13 (trixie) or
|
|
|
|
|
# newer; Debian 12 installs stay on their final version and cannot be upgraded in place.
|
|
|
|
|
os_id=""
|
|
|
|
|
os_version=""
|
|
|
|
|
if [ -r /etc/os-release ]; then
|
|
|
|
|
os_id=$(awk -F= '$1=="ID"{gsub(/"/,"",$2);print $2}' /etc/os-release)
|
|
|
|
|
os_version=$(awk -F= '$1=="VERSION_ID"{gsub(/"/,"",$2);print $2}' /etc/os-release)
|
|
|
|
|
fi
|
|
|
|
|
case "${os_version}" in
|
|
|
|
|
'' | *[!0-9]*) os_version=0 ;;
|
|
|
|
|
esac
|
|
|
|
|
if [[ ${os_id} != "debian" || ${os_version} -lt 13 ]]; then
|
|
|
|
|
echo 'This script can only be run on Debian 13 (trixie) or newer, or Raspberry Pi OS based on it!' && exit 2
|
2022-03-08 13:26:03 -07:00
|
|
|
fi
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
set -x
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
# Check that WROLPi directory exists, and contains wrolpi.
|
2022-03-08 13:26:03 -07:00
|
|
|
[ -d /opt/wrolpi ] && [ ! -d /opt/wrolpi/wrolpi ] && echo "/opt/wrolpi exists but does not contain wrolpi!" && exit 3
|
2022-01-06 13:56:04 -07:00
|
|
|
|
2022-05-18 08:20:05 -06:00
|
|
|
# Add the WROLPi directory as a global safe directory so root can fetch.
|
|
|
|
|
[ -d /opt/wrolpi ] && git config --global --add safe.directory /opt/wrolpi
|
|
|
|
|
|
2022-03-08 13:26:03 -07:00
|
|
|
# Get the latest WROLPi code. Use the branch requested.
|
|
|
|
|
apt install -y git
|
2021-11-01 16:42:52 -06:00
|
|
|
git --version
|
|
|
|
|
git clone https://github.com/lrnselfreliance/wrolpi.git /opt/wrolpi || :
|
2026-06-27 13:57:27 -06:00
|
|
|
# Use `checkout -B <branch> origin/<branch>` so the ref can never be mistaken for a path. A tracked `release/`
|
|
|
|
|
# directory otherwise collides with the `release` branch name, making a bare `git checkout release` ambiguous.
|
|
|
|
|
(cd /opt/wrolpi && git fetch && git checkout -B "${BRANCH}" "origin/${BRANCH}" && git reset --hard origin/"${BRANCH}") || exit 4
|
2022-01-17 12:43:04 -07:00
|
|
|
|
2022-03-16 18:09:02 -06:00
|
|
|
if [ ${rpi} == true ]; then
|
2023-02-23 12:09:19 -07:00
|
|
|
/opt/wrolpi/scripts/install_raspberrypios.sh 2>&1 | tee /opt/wrolpi/install.log
|
2022-03-16 18:09:02 -06:00
|
|
|
install_code=${PIPESTATUS[0]}
|
2026-10-14 15:51:40 -06:00
|
|
|
else
|
|
|
|
|
/opt/wrolpi/scripts/install_debian.sh 2>&1 | tee /opt/wrolpi/install.log
|
2022-03-16 18:09:02 -06:00
|
|
|
install_code=${PIPESTATUS[0]}
|
|
|
|
|
fi
|
2022-03-13 11:02:55 -06:00
|
|
|
|
|
|
|
|
set +x
|
2022-03-09 21:15:00 -07:00
|
|
|
|
|
|
|
|
echo "Install end $(date '+%Y-%m-%d %H:%M:%S')" >>/opt/wrolpi/install.log
|
2024-04-14 13:06:03 -06:00
|
|
|
|
|
|
|
|
if [ "${install_code}" -ne 0 ]; then
|
|
|
|
|
echo "Installation failed!"
|
|
|
|
|
fi
|
|
|
|
|
|
2022-03-16 18:09:02 -06:00
|
|
|
exit "${install_code}"
|