Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions migrate_db.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
attach `/home/pifinder/PiFinder/astro_data/observations.db` as ad_obs;
attach `/home/pifinder/PiFinder_data/observations.db` as pfd_obs;
attach `__PIFINDER_REPO_DIR__/astro_data/observations.db` as ad_obs;
attach `__PIFINDER_DATA_DIR__/observations.db` as pfd_obs;
BEGIN;
insert into pfd_obs.obs_sessions(start_time_local, lat, lon, timezone, UID)
select start_time_local, lat, lon, timezone, UID from ad_obs.obs_sessions;
Expand Down
28 changes: 17 additions & 11 deletions migration_source/v1.x.x.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
PIFINDER_REPO_DIR="${PIFINDER_REPO_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
source "${PIFINDER_REPO_DIR}/pifinder_paths.sh"

# GPSD
sudo apt install -y gpsd
sudo dpkg-reconfigure -plow gpsd
sudo cp ~/PiFinder/pi_config_files/gpsd.conf /etc/default/gpsd
sudo cp "${PIFINDER_REPO_DIR}/pi_config_files/gpsd.conf" /etc/default/gpsd

# PWM
sudo sed -zi '/dtoverlay=pwm,pin=13,func=4\n/!s/$/\ndtoverlay=pwm,pin=13,func=4\n/' /boot/config.txt
BOOT_CONFIG="$(pifinder_boot_config_path)"
sudo sed -zi '/dtoverlay=pwm,pin=13,func=4\n/!s/$/\ndtoverlay=pwm,pin=13,func=4\n/' "${BOOT_CONFIG}"

# Uart for GPS
sudo sed -zi '/dtoverlay=uart3\n/!s/$/\ndtoverlay=uart3\n/' /boot/config.txt
sudo sed -zi '/dtoverlay=uart3\n/!s/$/\ndtoverlay=uart3\n/' "${BOOT_CONFIG}"

# Migrate DB
if [ -f "/home/pifinder/PiFinder/astro_data/observations.db" ]
if [ -f "${PIFINDER_REPO_DIR}/astro_data/observations.db" ]
then
echo "Migrating astro_data DB"
python -c "from PiFinder import setup;setup.create_logging_tables();"
sqlite3 < /home/pifinder/PiFinder/migrate_db.sql
rm /home/pifinder/PiFinder/astro_data/observations.db
sed \
-e "s|__PIFINDER_REPO_DIR__|${PIFINDER_REPO_DIR}|g" \
-e "s|__PIFINDER_DATA_DIR__|${PIFINDER_DATA_DIR}|g" \
"${PIFINDER_REPO_DIR}/migrate_db.sql" | sqlite3
rm "${PIFINDER_REPO_DIR}/astro_data/observations.db"
fi

# Migrate Config files
if ! [ -f "/home/pifinder/PiFinder_data/config.json" ]
if ! [ -f "${PIFINDER_DATA_DIR}/config.json" ] && [ -f "${PIFINDER_REPO_DIR}/config.json" ]
then
echo "Migrating config.json"
mv /home/pifinder/PiFinder/config.json /home/pifinder/PiFinder_data/config.json
mv "${PIFINDER_REPO_DIR}/config.json" "${PIFINDER_DATA_DIR}/config.json"
fi

# Adjust service definition
sudo systemctl disable pifinder
sudo rm /etc/systemd/system/pifinder.service
sudo cp /home/pifinder/PiFinder/pi_config_files/pifinder.service /lib/systemd/system/pifinder.service
pifinder_render_config "${PIFINDER_REPO_DIR}/pi_config_files/pifinder.service" /lib/systemd/system/pifinder.service
sudo systemctl daemon-reload
sudo systemctl enable pifinder

# add PiFinder_splash if not already in place
if ! [ -f "/lib/systemd/system/pifinder_spash.service" ]
then
sudo cp /home/pifinder/PiFinder/pi_config_files/pifinder_splash.service /lib/systemd/system/pifinder_splash.service
pifinder_render_config "${PIFINDER_REPO_DIR}/pi_config_files/pifinder_splash.service" /lib/systemd/system/pifinder_splash.service
sudo systemctl daemon-reload
sudo systemctl enable pifinder_splash
fi
Expand All @@ -45,4 +52,3 @@ sudo chmod 666 /etc/wpa_supplicant/wpa_supplicant.conf

# DONE
echo "Post Update Complete"

6 changes: 4 additions & 2 deletions migration_source/v2.1.0.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
PIFINDER_REPO_DIR="${PIFINDER_REPO_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
source "${PIFINDER_REPO_DIR}/pifinder_paths.sh"

# swap tetra3 submodule
git submodule sync
git submodule update --init --recursive

# Set up symlink
ln -s /home/pifinder/PiFinder/python/PiFinder/tetra3/tetra3 /home/pifinder/PiFinder/python/tetra3

ln -sfn "${PIFINDER_REPO_DIR}/python/PiFinder/tetra3/tetra3" "${PIFINDER_REPO_DIR}/python/tetra3"
6 changes: 4 additions & 2 deletions migration_source/v2.2.1.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
PIFINDER_REPO_DIR="${PIFINDER_REPO_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
source "${PIFINDER_REPO_DIR}/pifinder_paths.sh"

# install lib input
sudo apt install -y libinput10

# Add PiFinder user to input group
sudo usermod -G input -a "pifinder"

sudo usermod -G input -a "${PIFINDER_USER}"
8 changes: 6 additions & 2 deletions migration_source/v2.2.2.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
PIFINDER_REPO_DIR="${PIFINDER_REPO_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
source "${PIFINDER_REPO_DIR}/pifinder_paths.sh"

# Enable usb-host on usb-c port
BOOT_CONFIG="$(pifinder_boot_config_path)"

#Add it to the dw2 line if it exist
sudo sed -zi "s/dtoverlay=dwc2\n/dtoverlay=dwc2,dr_mode=host\n/" /boot/config.txt
sudo sed -zi "s/dtoverlay=dwc2\n/dtoverlay=dwc2,dr_mode=host\n/" "${BOOT_CONFIG}"

#Add the line if it does not exist
sudo sed -zi '/dtoverlay=dwc2,dr_mode=host\n/!s/$/\ndtoverlay=dwc2,dr_mode=host\n/' /boot/config.txt
sudo sed -zi '/dtoverlay=dwc2,dr_mode=host\n/!s/$/\ndtoverlay=dwc2,dr_mode=host\n/' "${BOOT_CONFIG}"
5 changes: 4 additions & 1 deletion migration_source/v2.4.0.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
PIFINDER_REPO_DIR="${PIFINDER_REPO_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
source "${PIFINDER_REPO_DIR}/pifinder_paths.sh"

#Add and enable cedar-detect as system process
sudo cp /home/pifinder/PiFinder/pi_config_files/cedar_detect.service /lib/systemd/system/cedar_detect.service
pifinder_render_config "${PIFINDER_REPO_DIR}/pi_config_files/cedar_detect.service" /lib/systemd/system/cedar_detect.service
sudo systemctl daemon-reload
sudo systemctl enable cedar_detect
5 changes: 4 additions & 1 deletion migration_source/v2.6.0.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
PIFINDER_REPO_DIR="${PIFINDER_REPO_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
source "${PIFINDER_REPO_DIR}/pifinder_paths.sh"

# Clear stale flop_image=true on the shipped "Generic Dobsonian" default.
# flip/flop are now applied to the object-detail image; a Dobsonian needs
# neither flag, so repair any persisted config that froze the bad default.
# Idempotent and version-gated by pifinder_post_update.sh. See
# docs/adr/0003-object-image-orientation.md.
python /home/pifinder/PiFinder/python/PiFinder/migrations/v2_6_0_dob_flop.py /home/pifinder/PiFinder_data/config.json
python "${PIFINDER_REPO_DIR}/python/PiFinder/migrations/v2_6_0_dob_flop.py" "${PIFINDER_DATA_DIR}/config.json"
6 changes: 3 additions & 3 deletions pi_config_files/cedar_detect.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ After=basic.target

[Service]
Type=idle
User=pifinder
WorkingDirectory=/home/pifinder/PiFinder
User=__PIFINDER_USER__
WorkingDirectory=__PIFINDER_REPO_DIR__
Environment=RUST_BACKTRACE=1
ExecStart=/home/pifinder/PiFinder/bin/cedar-detect-server-aarch64 --port 50551
ExecStart=__PIFINDER_REPO_DIR__/bin/cedar-detect-server-aarch64 --port 50551
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
Expand Down
4 changes: 2 additions & 2 deletions pi_config_files/pifinder.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ After=basic.target

[Service]
Type=idle
User=pifinder
WorkingDirectory=/home/pifinder/PiFinder/python
User=__PIFINDER_USER__
WorkingDirectory=__PIFINDER_REPO_DIR__/python
ExecStart=/usr/bin/python -m PiFinder.main
AmbientCapabilities=CAP_NET_BIND_SERVICE

Expand Down
2 changes: 1 addition & 1 deletion pi_config_files/pifinder_splash.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Description=PiFinderSplash

[Service]
WorkingDirectory=/home/pifinder/PiFinder/python
WorkingDirectory=__PIFINDER_REPO_DIR__/python
ExecStart=/usr/bin/python -m PiFinder.splash

[Install]
Expand Down
4 changes: 2 additions & 2 deletions pi_config_files/smb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#======================= Global Settings =======================

[global]
guest account = pifinder
guest account = __PIFINDER_USER__

## Browsing/Identification ###

Expand Down Expand Up @@ -235,7 +235,7 @@ guest account = pifinder
# to the drivers directory for these users to have write rights in it
; write list = root, @lpadmin
[shared]
path=/home/pifinder/PiFinder_data
path=__PIFINDER_DATA_DIR__
writeable=Yes
create mask=0777
directory mask=0777
Expand Down
58 changes: 58 additions & 0 deletions pifinder_paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# Shared path helpers for PiFinder shell install/update scripts.

set -e

if [[ -z "${PIFINDER_REPO_DIR:-}" ]]; then
PIFINDER_REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fi

if [[ -z "${PIFINDER_USER:-}" ]]; then
if [[ -n "${SUDO_USER:-}" && "${SUDO_USER}" != "root" ]]; then
PIFINDER_USER="${SUDO_USER}"
else
PIFINDER_USER="$(id -un)"
fi
fi

if [[ "${PIFINDER_USER}" == "root" ]]; then
echo "PiFinder must be installed for a non-root OS user." >&2
echo "Set PIFINDER_USER=<user> when running as root." >&2
exit 1
fi

if [[ -z "${PIFINDER_HOME:-}" ]]; then
PIFINDER_HOME="$(getent passwd "${PIFINDER_USER}" | cut -d: -f6)"
fi

if [[ -z "${PIFINDER_HOME}" || ! -d "${PIFINDER_HOME}" ]]; then
echo "Could not determine home directory for ${PIFINDER_USER}" >&2
exit 1
fi

PIFINDER_DATA_DIR="${PIFINDER_DATA_DIR:-${PIFINDER_HOME}/PiFinder_data}"

export PIFINDER_USER
export PIFINDER_HOME
export PIFINDER_REPO_DIR
export PIFINDER_DATA_DIR

pifinder_render_config() {
local source_file="$1"
local target_file="$2"

sudo sed \
-e "s|__PIFINDER_USER__|${PIFINDER_USER}|g" \
-e "s|__PIFINDER_HOME__|${PIFINDER_HOME}|g" \
-e "s|__PIFINDER_REPO_DIR__|${PIFINDER_REPO_DIR}|g" \
-e "s|__PIFINDER_DATA_DIR__|${PIFINDER_DATA_DIR}|g" \
"${source_file}" | sudo tee "${target_file}" >/dev/null
}

pifinder_boot_config_path() {
if [[ -e /boot/firmware/config.txt ]]; then
printf "%s\n" "/boot/firmware/config.txt"
else
printf "%s\n" "/boot/config.txt"
fi
}
46 changes: 24 additions & 22 deletions pifinder_post_update.sh
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
PIFINDER_REPO_DIR="${PIFINDER_REPO_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
source "${PIFINDER_REPO_DIR}/pifinder_paths.sh"

git submodule update --init --recursive
sudo pip install -r /home/pifinder/PiFinder/python/requirements.txt
sudo python3 -m pip install --break-system-packages -r "${PIFINDER_REPO_DIR}/python/requirements.txt"

# Set up migrations folder if it does not exist
if ! [ -d "/home/pifinder/PiFinder_data/migrations" ]
if ! [ -d "${PIFINDER_DATA_DIR}/migrations" ]
then
mkdir /home/pifinder/PiFinder_data/migrations
mkdir -p "${PIFINDER_DATA_DIR}/migrations"
fi

# v1.x.x
# everying prior to selecitve migrations
if ! [ -f "/home/pifinder/PiFinder_data/migrations/v1.x.x" ]
if ! [ -f "${PIFINDER_DATA_DIR}/migrations/v1.x.x" ]
then
source /home/pifinder/PiFinder/migration_source/v1.x.x.sh
touch /home/pifinder/PiFinder_data/migrations/v1.x.x
source "${PIFINDER_REPO_DIR}/migration_source/v1.x.x.sh"
touch "${PIFINDER_DATA_DIR}/migrations/v1.x.x"
fi

# v2.1.0
# Switch to Cedar
if ! [ -f "/home/pifinder/PiFinder_data/migrations/v2.1.0" ]
if ! [ -f "${PIFINDER_DATA_DIR}/migrations/v2.1.0" ]
then
source /home/pifinder/PiFinder/migration_source/v2.1.0.sh
touch /home/pifinder/PiFinder_data/migrations/v2.1.0
source "${PIFINDER_REPO_DIR}/migration_source/v2.1.0.sh"
touch "${PIFINDER_DATA_DIR}/migrations/v2.1.0"
fi

# v2.2.1
# Install libinput
if ! [ -f "/home/pifinder/PiFinder_data/migrations/v2.2.1" ]
if ! [ -f "${PIFINDER_DATA_DIR}/migrations/v2.2.1" ]
then
source /home/pifinder/PiFinder/migration_source/v2.2.1.sh
touch /home/pifinder/PiFinder_data/migrations/v2.2.1
source "${PIFINDER_REPO_DIR}/migration_source/v2.2.1.sh"
touch "${PIFINDER_DATA_DIR}/migrations/v2.2.1"
fi

# v2.2.2
# Enable host usb on usb-c port
if ! [ -f "/home/pifinder/PiFinder_data/migrations/v2.2.2" ]
if ! [ -f "${PIFINDER_DATA_DIR}/migrations/v2.2.2" ]
then
source /home/pifinder/PiFinder/migration_source/v2.2.2.sh
touch /home/pifinder/PiFinder_data/migrations/v2.2.2
source "${PIFINDER_REPO_DIR}/migration_source/v2.2.2.sh"
touch "${PIFINDER_DATA_DIR}/migrations/v2.2.2"
fi

# v2.4.0
# Switch detect to system process
if ! [ -f "/home/pifinder/PiFinder_data/migrations/v2.4.0" ]
if ! [ -f "${PIFINDER_DATA_DIR}/migrations/v2.4.0" ]
then
source /home/pifinder/PiFinder/migration_source/v2.4.0.sh
touch /home/pifinder/PiFinder_data/migrations/v2.4.0
source "${PIFINDER_REPO_DIR}/migration_source/v2.4.0.sh"
touch "${PIFINDER_DATA_DIR}/migrations/v2.4.0"
fi

# v2.6.0
# Clear stale flop_image=true on the default Dobsonian (flip/flop now live)
if ! [ -f "/home/pifinder/PiFinder_data/migrations/v2.6.0" ]
if ! [ -f "${PIFINDER_DATA_DIR}/migrations/v2.6.0" ]
then
source /home/pifinder/PiFinder/migration_source/v2.6.0.sh
touch /home/pifinder/PiFinder_data/migrations/v2.6.0
source "${PIFINDER_REPO_DIR}/migration_source/v2.6.0.sh"
touch "${PIFINDER_DATA_DIR}/migrations/v2.6.0"
fi

# DONE
echo "Post Update Complete"

Loading