#!/usr/bin/env bash # -u: treat unset variables as an error and exit immediately # -e: exit when command fails set -e # print commands prior to executing (for debuging) #set -x PP_GITREPO="https://github.com/txoof/PaperPi.git" #PP_GITREPO="git@github.com:txoof/PaperPi.git" #PP_GITBRANCH="manage_modules" PP_GITBRANCH="main" long_bit=$(getconf LONG_BIT) if [[ $1 == "-b" && ! -z $2 ]] then PP_GITBRANCH="$2" else PP_GITBRANCH="main" fi echo "installing PaperPi from branch: $PP_GITBRANCH" INSTALLER="/install/install.sh" # string formatters if [[ -t 1 ]] then tty_escape() { printf "\033[%sm" "$1"; } else tty_escape() { :; } fi tty_mkbold() { tty_escape "1;$1"; } tty_underline="$(tty_escape "4;39")" tty_blue="$(tty_mkbold 34)" tty_red="$(tty_mkbold 31)" tty_bold="$(tty_mkbold 39)" tty_reset="$(tty_escape 0)" abort() { printf "%s\n" "$@" exit 1 } shell_join() { local arg printf "%s" "$1" shift for arg in "$@" do printf " " printf "%s" "${arg// /\ }" done } ohai() { printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")" } # Fail fast with a concise message when not using bash # Single brackets are needed here for POSIX compatibility if [ -z "${BASH_VERSION:-}" ] then abort "Bash is required to interpret this script." fi # # fail if not 32 bit os # if [ ! "$long_bit" == "32" ] # then # abort "PaperPi is officially supported only on 32 bit versions of RaspberryPi OS. See the README for manual install instructions." # fi # check if git is available if ! command -v git > /dev/null then abort "$( cat </dev/null else "${SUDO[@]}" -v && "${SUDO[@]}" -l mkdir &>/dev/null fi HAVE_SUDO_ACCESS="$?" fi return "${HAVE_SUDO_ACCESS}" } execute() { if ! "$@" then abort "$(printf "Failed during: %s" "$(shell_join "$@")")" fi } execute_sudo() { local -a args=("$@") if have_sudo_access then if [[ -n "${SUDO_ASKPASS-}" ]] then args=("-A" "${args[@]}") fi ohai "/usr/bin/sudo" "${args[@]}" execute "/usr/bin/sudo" "${args[@]}" else ohai "${args[@]}" execute "${args[@]}" fi } echo "$git_temp" execute_sudo "$git_temp/install/install.sh" rm -rf $git_temp