Skip to content

Commit

Permalink
Install script updates (#1281)
Browse files Browse the repository at this point in the history
* Remove custom gphoto2 install

* Install from apt, which is at the current version. This should save a lot of time compared to the compiling needed for the custom install.

* * Source micromamba properly

* * Fixing up more of the conda/mamba init on install.

* * Removing install shell function for udev entries, which are handled by `pocs mount setup`.

* * Small change to writing of dev entry.

* * Remove gphoto2 dev install.

* Moving script file location.

* Split each install function into a separate file.

* Small script fixes.

* Passwordless sudo on machine.

* Default POCS dir to uppercase.

* More consistency with the PANUSER and PANDIR.

* Remove from functions so just scripts run.

* Setup user and do passwordless, all the good stuff.

* Handle pocs clone

* Change default shell with sudo

* Updating the script install order.

* Fix conda install.

* Make scripts executable.

* Check for zsh dir

* Explicit ohmyzsh

* Python 3.12 for now.

* Add a base script that can be fetched and installed.
  • Loading branch information
wtgee authored Nov 21, 2024
1 parent ed60027 commit 8e2c0e3
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 352 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions resources/arduino/install-arduino-cli.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions resources/arduino/install-arduino.sh → resources/arduino/install-power-board.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ FQBN="${FQBN:-arduino:avr:uno}"
SKETCH_LOCATION="${SKETCH_LOCATION:-PowerBoard}"
ARDUINO_PORT="${ARDUINO_PORT:-/dev/ttyACM0}"

arduino-cli config init
arduino-cli core update-index
arduino-cli core install arduino:avr
arduino-cli lib install ArduinoJson
arduino-cli compile -b "${FQBN}" "${SKETCH_LOCATION}"
arduino-cli upload -p "${ARDUINO_PORT}" -b "${FQBN}" "${SKETCH_LOCATION}"
27 changes: 27 additions & 0 deletions resources/scripts/fix-time.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions resources/scripts/get-pocs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

BRANCH="${BRANCH:-develop}"

git clone https://github.com/panoptes/POCS
cd POCS
git checkout "${BRANCH}"
cd resources/scripts
./install.sh

echo "POCS installed, please reboot."
22 changes: 22 additions & 0 deletions resources/scripts/install-conda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

CONDA_URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-$(uname -m).sh"
PANDIR="${PANDIR:-${HOME}/POCS}"
CONDA_ENV_NAME=conda-pocs

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"

# 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.12

# Activate by default
echo "conda activate ${CONDA_ENV_NAME}" >>"${HOME}/.zshrc"
30 changes: 30 additions & 0 deletions resources/scripts/install-pocs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

CODE_BRANCH=${CODE_BRANCH:-"develop"}
CONDA_ENV_NAME=conda-pocs
PANDIR="${PANDIR:-${HOME}/POCS}"

# Check if PANDIR exists and if not, clone.
if [ -d "${PANDIR}" ]; then
echo "POCS repo already exists."
else
echo "Cloning POCS repo."
git clone https://github.com/panoptes/POCS "${PANDIR}"
cd "${PANDIR}"
git checkout "${CODE_BRANCH}"
cd
fi

echo "Installing POCS into ${CONDA_ENV_NAME} environment."
"${HOME}/conda/bin/conda" env update -p "${HOME}/conda/envs/${CONDA_ENV_NAME}" -f "${PANDIR}/environment.yaml"

echo "Creating POCS 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}"
17 changes: 17 additions & 0 deletions resources/scripts/install-services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

PANUSER="${PANUSER:-panoptes}"

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
35 changes: 35 additions & 0 deletions resources/scripts/install-system-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

echo "Installing system dependencies."

# Clean up problems.
sudo apt-get update --fix-missing -y

# Upgrade.
sudo apt-get -y full-upgrade

sudo apt-get -y install \
ack \
astrometry.net \
astrometry-data-tycho2-10-19 \
byobu \
curl \
dcraw \
exiftool \
fonts-powerline \
gcc \
git \
gphoto2 \
htop \
httpie \
jo \
jq \
libcfitsio-bin \
make \
nano \
supervisor \
vim-nox \
wget \
zsh

sudo apt-get -y autoremove
43 changes: 43 additions & 0 deletions resources/scripts/install-zsh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

PANUSER="${PANUSER:-panoptes}"
PANDIR="${PANDIR:-${HOME}/POCS}"

function install_zsh() {
if [ ! -d "${HOME}/.oh-my-zsh" ]; then
echo "Using zsh for a better shell experience."

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" <<EOT
zstyle ':omz:update' mode disabled
export PATH="\$HOME/bin:\$HOME/.local/bin:/usr/local/bin:\$PATH"
export ZSH="/home/${PANUSER}/.oh-my-zsh"
export PANDIR="${PANDIR}"
ZSH_THEME="agnoster"
plugins=(git sudo zsh-autosuggestions docker docker-compose python)
source \$ZSH/oh-my-zsh.sh
unsetopt share_history
EOT
}

install_zsh
25 changes: 25 additions & 0 deletions resources/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -e

echo "Installing POCS"

echo "Setting up user."
source ./setup-user.sh > install.log 2>&1

echo "Fixing system time."
source ./fix-time.sh >> install.log 2>&1

echo "Installing system dependencies."
source ./install-system-deps.sh >> install.log 2>&1

echo "Installing ZSH for a better shell."
source ./install-zsh.sh >> install.log 2>&1

echo "Installing conda python."
source ./install-conda.sh >> install.log 2>&1

echo "Installing POCS software."
source ./install-pocs.sh >> install.log 2>&1

echo "Installing services so things run at startup."
source ./install-services.sh >> install.log 2>&1
10 changes: 10 additions & 0 deletions resources/scripts/setup-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# Set up passwordless sudo for all sudo group.
echo "%sudo ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/panoptes

# 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
Loading

0 comments on commit 8e2c0e3

Please sign in to comment.