From 890822ada60c0e44830d860c2965cd86af34400f Mon Sep 17 00:00:00 2001 From: Wilfred Tyler Gee Date: Tue, 19 Nov 2024 08:24:57 -1000 Subject: [PATCH] Split each install function into a separate file. --- README.md | 8 +- resources/arduino/install-arduino-cli.sh | 25 ++ resources/install-pocs.sh | 303 ----------------------- resources/scripts/fix-time.sh | 27 ++ resources/scripts/install-conda.sh | 29 +++ resources/scripts/install-pocs.sh | 30 +++ resources/scripts/install-services.sh | 22 ++ resources/scripts/install-system-deps.sh | 36 +++ resources/scripts/install-zsh.sh | 43 ++++ resources/scripts/install.sh | 9 + resources/scripts/setup-user.sh | 16 ++ 11 files changed, 241 insertions(+), 307 deletions(-) create mode 100755 resources/arduino/install-arduino-cli.sh delete mode 100644 resources/install-pocs.sh create mode 100644 resources/scripts/fix-time.sh create mode 100644 resources/scripts/install-conda.sh create mode 100644 resources/scripts/install-pocs.sh create mode 100644 resources/scripts/install-services.sh create mode 100644 resources/scripts/install-system-deps.sh create mode 100644 resources/scripts/install-zsh.sh create mode 100644 resources/scripts/install.sh create mode 100644 resources/scripts/setup-user.sh diff --git a/README.md b/README.md index a6a16b14f..8fd7d1bbb 100644 --- a/README.md +++ b/README.md @@ -38,15 +38,15 @@ folks even report that it works on a Mac. To install POCS via the script, open a terminal and enter (you may be prompted for your `sudo` password): ```bash -curl -fsSL https://install.projectpanoptes.org > install-pocs.sh -bash install-pocs.sh +curl -fsSL https://install.projectpanoptes.org > install.sh +bash install.sh ``` Or using `wget`: ```bash -wget -qO- https://install.projectpanoptes.org > install-pocs.sh -bash install-pocs.sh +wget -qO- https://install.projectpanoptes.org > install.sh +bash install.sh ``` The install script will ask a few questions at the beginning of the process. If you are unsure of diff --git a/resources/arduino/install-arduino-cli.sh b/resources/arduino/install-arduino-cli.sh new file mode 100755 index 000000000..9d630b931 --- /dev/null +++ b/resources/arduino/install-arduino-cli.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# Check for arduino-cli tool first. +if command -v arduino-cli &> /dev/null; then + echo "arduino-cli is already installed." + exit 0 +fi + +# Make sure we are at home. +cd + +# Get the arduino-cli tool and install. +curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh + +"${HOME}/bin/arduino-cli" config init +"${HOME}/bin/arduino-cli" core update-index +"${HOME}/bin/arduino-cli" core install arduino:avr +"${HOME}/bin/arduino-cli" lib install ArduinoJson + +# Ask if the user wants to install the power board software. +read -p "Do you want to install the power board software? [y/N] " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]]; then + source ./install-power-board.sh +fi diff --git a/resources/install-pocs.sh b/resources/install-pocs.sh deleted file mode 100644 index a0d8709f0..000000000 --- a/resources/install-pocs.sh +++ /dev/null @@ -1,303 +0,0 @@ -#!/usr/bin/env bash -set -e - -usage() { - echo -n "################################################## -# Install POCS and friends. -# -# Script Version: 2023-04-26 -# -# This script is designed to install the PANOPTES Observatory -# Control System (POCS) on a cleanly installed Ubuntu system -# (ideally on a Raspberry Pi). -# -# This script is meant for quick & easy install via: -# -# $ curl -fsSL https://install.projectpanoptes.org > install-pocs.sh -# $ bash install-pocs.sh -# or -# $ wget -qO- https://install.projectpanoptes.org > install-pocs.sh -# $ bash install-pocs.sh -## -# The script has been tested with a fresh install of Ubuntu Server 22.10 -# but may work on other linux systems. -# -# Changes: -# * 2020-07-05 - Initial release of versioned script. -# * 2020-07-06 (wtgee) - Fix the writing of the env file. Cleanup. -# * 2020-07-08 (wtgee) - Better test for ssh access for developer. -# * 2020-07-09 (wtgee) - Fix conditional for writing shell rc files. Use 3rd -# party docker-compose (linuxserver.io) for arm. -# * 2020-07-27 (wtgee) - Cleanup and consistency for Unit install. -# * 2020-11-08 (wtgee) - Add zsh, anaconda. Docker from apt. -# * 2021-01-18 (wtgee) - Simplify to only install minimal required on host, -# removing zsh, etc. Removed Darwin options. -# * 2023-01-29 (wtgee) - Simplified options. Added supervisor. Clean up. -# * 2023-04-26 (wtgee) - Added arduino-cli. Removed prompt for supervisord. -# * 2023-05-10 (wtgee) - Added install options for the camera. -# * 2023-05-17 (wtgee) - Simplify (again). One script for all boxes. -# * 2023-05-28 (wtgee) - Hide all the output in a nice progress indicator. Use logfile. -# -############################################################# - $ $(basename $0) [--user panoptes] [--pandir /panoptes] - - Options: - USER The PANUSER environment variable, defaults to current user (i.e. PANUSER=$USER). - PANDIR Default install directory, defaults to PANDIR=${PANDIR}. Saved as PANDIR - environment variable. -" -} - -LOGFILE="${LOGFILE:-install-pocs.log}" - -PANUSER="${PANUSER:-$USER}" -PANDIR="${PANDIR:-${HOME}/pocs}" -USE_ZSH="${USE_ZSH:-true}" -INSTALL_SERVICES="${INSTALL_SERVICES:-true}" -DEFAULT_GROUPS="dialout,plugdev,input,sudo" - -# We use htpdate below so this just needs to be a public url w/ trusted time. -TIME_SERVER="${TIME_SERVER:-google.com}" - -CONDA_URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-$(uname -m).sh" -CONDA_ENV_NAME=conda-pocs - -CODE_BRANCH=${CODE_BRANCH:-"develop"} - -declare -x FRAME=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏") -declare -x FRAME_INTERVAL=(0.1) - -function system_deps() { - echo "Installing system dependencies." - - # Clean up problems. - sudo apt-get -y -qq purge needrestart - sudo apt-get update --fix-missing -y -qq - sudo apt-get -y -qq full-upgrade - - sudo apt-get -y -qq install \ - ack \ - astrometry.net \ - astrometry-data-tycho2-10-19 \ - byobu \ - curl \ - dcraw \ - exiftool \ - fonts-powerline \ - gcc \ - gphoto2 \ - htop \ - httpie \ - jo \ - jq \ - libcfitsio-bin \ - make \ - nano \ - vim-nox \ - supervisor \ - wget - sudo apt-get -y -qq autoremove - - sudo usermod -aG "${DEFAULT_GROUPS}" "${PANUSER}" - - # Add an SSH key if one doesn't exist. - if [[ ! -f "${HOME}/.ssh/id_rsa" ]]; then - echo "Adding ssh key" - ssh-keygen -t rsa -N "" -f "${HOME}/.ssh/id_rsa" - fi - -} - -function install_conda() { - echo "Installing miniforge conda" - - wget -q "${CONDA_URL}" -O install-miniforge.sh - /bin/sh install-miniforge.sh -b -f -p "${HOME}/conda" - rm install-miniforge.sh - - source "${HOME}/conda/etc/profile.d/conda.sh" - source "${HOME}/conda/etc/profile.d/mamba.sh" - - # Initialize conda for the shells. - "${HOME}/conda/bin/conda" init bash zsh - - echo "Creating POCS conda environment" - "${HOME}/conda/bin/conda" create -y -q -n "${CONDA_ENV_NAME}" python=3 - - # Activate by default - echo "conda activate ${CONDA_ENV_NAME}" >>"${HOME}/.zshrc" - - cd "${PANDIR}" - "${HOME}/conda/bin/mamba" env update -p "${HOME}/conda/envs/${CONDA_ENV_NAME}" -f environment.yaml -} - -function get_pocs_repo() { - echo "Cloning POCS repo." - - git clone https://github.com/panoptes/POCS "${PANDIR}" - cd "${PANDIR}" - git checkout "${CODE_BRANCH}" - cd -} - -function make_directories() { - echo "Creating directories." - mkdir -p "${HOME}/logs" - mkdir -p "${HOME}/images" - mkdir -p "${HOME}/json_store" - mkdir -p "${HOME}/keys" - - # Link the needed POCS folders. - ln -s "${PANDIR}/conf_files" "${HOME}" - ln -s "${PANDIR}/resources" "${HOME}" - ln -s "${PANDIR}/notebooks" "${HOME}" -} - -function install_services() { - echo "Installing supervisor services." - - # Make supervisor read our conf file at its current location. - echo "files = ${HOME}/conf_files/pocs-supervisord.conf" | sudo tee -a /etc/supervisor/supervisord.conf - - # Change the user and home directory. - sed -i "s/chown=panoptes:panoptes/chown=${PANUSER}:${PANUSER}/g" "${HOME}/conf_files/pocs-supervisord.conf" - sed -i "s/user=panoptes/user=${PANUSER}/g" "${HOME}/conf_files/pocs-supervisord.conf" - sed -i "s|/home/panoptes|${HOME}|g" "${HOME}/conf_files/pocs-supervisord.conf" - - # Reread the supervisord conf and restart. - sudo supervisorctl reread - sudo supervisorctl update -} - -function install_zsh() { - if [ ! -d "$ZSH_CUSTOM" ]; then - echo "Using zsh for a better shell experience." - - DEBIAN_FRONTEND=noninteractive sudo apt-get -y -qq install zsh - - sudo chsh --shell /usr/bin/zsh "${PANUSER}" - - # Oh my zsh - wget -q https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O /tmp/install-ohmyzsh.sh - bash /tmp/install-ohmyzsh.sh --unattended - - export ZSH_CUSTOM="$HOME/.oh-my-zsh" - - # Autosuggestions plugin - git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-~/.oh-my-zsh/custom}"/plugins/zsh-autosuggestions - - write_zshrc - fi -} - -function write_zshrc() { - cat >"${HOME}/.zshrc" <>"${LOGFILE}" & - pid=$! - - while ps -p $pid &>/dev/null; do - echo -ne "\\r[ ] ${STEPS[$step]} ..." - - for k in "${!FRAME[@]}"; do - echo -ne "\\r[ ${FRAME[k]} ]" - sleep "${FRAME_INTERVAL}" - done - done - - echo -ne "\\r[ ✔ ] ${STEPS[$step]}\\n" - step=$((step + 1)) - done - - tput cnorm -} diff --git a/resources/scripts/fix-time.sh b/resources/scripts/fix-time.sh new file mode 100644 index 000000000..1c60a855b --- /dev/null +++ b/resources/scripts/fix-time.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# We use htpdate below so this just needs to be a public url w/ trusted time. +TIME_SERVER="${TIME_SERVER:-google.com}" + +function fix_time() { + echo "Syncing time." + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y -qq htpdate + sudo timedatectl set-ntp false + sudo /usr/sbin/htpdate -as "${TIME_SERVER}" + sudo timedatectl set-ntp true + + # Add crontab entries for reboot and every hour. + ( + sudo crontab -l + echo "@reboot /usr/sbin/htpdate -as ${TIME_SERVER}" + ) | sudo crontab - + ( + sudo crontab -l + echo "13 * * * * /usr/sbin/htpdate -s ${TIME_SERVER}" + ) | sudo crontab - + + # Show updated time. + timedatectl +} + +fix_time diff --git a/resources/scripts/install-conda.sh b/resources/scripts/install-conda.sh new file mode 100644 index 000000000..0a2444df4 --- /dev/null +++ b/resources/scripts/install-conda.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +CONDA_URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-$(uname -m).sh" +CONDA_ENV_NAME=conda-pocs + +function install_conda() { + echo "Installing miniforge conda" + + wget -q "${CONDA_URL}" -O install-miniforge.sh + /bin/sh install-miniforge.sh -b -f -p "${HOME}/conda" + rm install-miniforge.sh + + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + + # Initialize conda for the shells. + "${HOME}/conda/bin/conda" init bash zsh + + echo "Creating POCS conda environment" + "${HOME}/conda/bin/conda" create -y -q -n "${CONDA_ENV_NAME}" python=3 + + # Activate by default + echo "conda activate ${CONDA_ENV_NAME}" >>"${HOME}/.zshrc" + + cd "${PANDIR}" + "${HOME}/conda/bin/mamba" env update -p "${HOME}/conda/envs/${CONDA_ENV_NAME}" -f environment.yaml +} + +install_conda diff --git a/resources/scripts/install-pocs.sh b/resources/scripts/install-pocs.sh new file mode 100644 index 000000000..d2b8d80a9 --- /dev/null +++ b/resources/scripts/install-pocs.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +CODE_BRANCH=${CODE_BRANCH:-"develop"} +PANUSER="${PANUSER:-$USER}" +PANDIR="${PANDIR:-${HOME}/pocs}" + +function get_pocs_repo() { + echo "Cloning POCS repo." + + git clone https://github.com/panoptes/POCS "${PANDIR}" + cd "${PANDIR}" + git checkout "${CODE_BRANCH}" + cd +} + +function make_directories() { + echo "Creating directories." + mkdir -p "${HOME}/logs" + mkdir -p "${HOME}/images" + mkdir -p "${HOME}/json_store" + mkdir -p "${HOME}/keys" + + # Link the needed POCS folders. + ln -s "${PANDIR}/conf_files" "${HOME}" + ln -s "${PANDIR}/resources" "${HOME}" + ln -s "${PANDIR}/notebooks" "${HOME}" +} + +get_pocs_repo +make_directories diff --git a/resources/scripts/install-services.sh b/resources/scripts/install-services.sh new file mode 100644 index 000000000..06e30dd6f --- /dev/null +++ b/resources/scripts/install-services.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +PANUSER="${PANUSER:-$USER}" +PANDIR="${PANDIR:-${HOME}/pocs}" + +function install_services() { + echo "Installing supervisor services." + + # Make supervisor read our conf file at its current location. + echo "files = ${HOME}/conf_files/pocs-supervisord.conf" | sudo tee -a /etc/supervisor/supervisord.conf + + # Change the user and home directory. + sed -i "s/chown=panoptes:panoptes/chown=${PANUSER}:${PANUSER}/g" "${HOME}/conf_files/pocs-supervisord.conf" + sed -i "s/user=panoptes/user=${PANUSER}/g" "${HOME}/conf_files/pocs-supervisord.conf" + sed -i "s|/home/panoptes|${HOME}|g" "${HOME}/conf_files/pocs-supervisord.conf" + + # Reread the supervisord conf and restart. + sudo supervisorctl reread + sudo supervisorctl update +} + +install_services diff --git a/resources/scripts/install-system-deps.sh b/resources/scripts/install-system-deps.sh new file mode 100644 index 000000000..faccb2961 --- /dev/null +++ b/resources/scripts/install-system-deps.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +function system_deps() { + echo "Installing system dependencies." + + # Clean up problems. + apt-get -y -qq purge needrestart + apt-get update --fix-missing -y -qq + apt-get -y -qq full-upgrade + + apt-get -y -qq install \ + ack \ + astrometry.net \ + astrometry-data-tycho2-10-19 \ + byobu \ + curl \ + dcraw \ + exiftool \ + fonts-powerline \ + gcc \ + gphoto2 \ + htop \ + httpie \ + jo \ + jq \ + libcfitsio-bin \ + make \ + nano \ + vim-nox \ + supervisor \ + wget \ + zsh + apt-get -y -qq autoremove +} + +system_deps diff --git a/resources/scripts/install-zsh.sh b/resources/scripts/install-zsh.sh new file mode 100644 index 000000000..0cbbbaef5 --- /dev/null +++ b/resources/scripts/install-zsh.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +PANUSER="${PANUSER:-$USER}" +PANDIR="${PANDIR:-${HOME}/pocs}" + +function install_zsh() { + if [ ! -d "$ZSH_CUSTOM" ]; then + echo "Using zsh for a better shell experience." + + chsh --shell /usr/bin/zsh "${PANUSER}" + + # Oh my zsh + wget -q https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O /tmp/install-ohmyzsh.sh + bash /tmp/install-ohmyzsh.sh --unattended + + export ZSH_CUSTOM="$HOME/.oh-my-zsh" + + # Autosuggestions plugin + git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-~/.oh-my-zsh/custom}"/plugins/zsh-autosuggestions + + write_zshrc + fi +} + +function write_zshrc() { + cat >"${HOME}/.zshrc" <