Skip to content
Merged
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
2 changes: 1 addition & 1 deletion deploy/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.7
0.1.0
43 changes: 41 additions & 2 deletions deploy/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,47 @@ ip=$($target/certs/detect-ip.sh 2>/dev/null || true)
[ -n "$ip" ] || { read -r -p "LAN IP for TLS certificate: " ip; }
ca_issue_leaf "$SAPOT_ROOT/shared/certs" "$ip" "$ca_dir" false
log_info "certificate issued - the CA USB stick can be unplugged now"
read -r -p "Is the GSM Arduino connected at $(grep '^GSM_ARDUINO_PORT=' "$SAPOT_ROOT/shared/gsm-arduino.env" | cut -d= -f2)? [y/N] " answer
hardware=false; [[ "$answer" =~ ^[Yy]$ ]] && hardware=true
shopt -s nullglob
detected_ports=(/dev/ttyACM* /dev/ttyUSB*)
shopt -u nullglob

hardware=false
selected_port=""

if [ ${#detected_ports[@]} -eq 0 ]; then
read -r -p "No GSM Arduino detected. Enter port path manually or leave empty to skip: " answer
if [ -n "$answer" ]; then
selected_port="$answer"
hardware=true
fi
elif [ ${#detected_ports[@]} -eq 1 ]; then
read -r -p "Found GSM Arduino at ${detected_ports[0]}. Use this? [Y/n/custom] " answer
if [[ "$answer" =~ ^[Yy]$ ]] || [ -z "$answer" ]; then
selected_port="${detected_ports[0]}"
hardware=true
elif [[ "$answer" =~ ^[Cc]ustom$ ]]; then
read -r -p "Enter custom port path: " selected_port
if [ -n "$selected_port" ]; then hardware=true; fi
fi
else
echo "Multiple GSM Arduino devices found:"
for i in "${!detected_ports[@]}"; do
echo " $((i+1))) ${detected_ports[$i]}"
done
read -r -p "Select a number, type a custom path, or leave empty to skip: " answer
if [[ "$answer" =~ ^[0-9]+$ ]] && [ "$answer" -ge 1 ] && [ "$answer" -le "${#detected_ports[@]}" ]; then
selected_port="${detected_ports[$((answer-1))]}"
hardware=true
elif [ -n "$answer" ]; then
selected_port="$answer"
hardware=true
fi
fi

if [ "$hardware" = true ] && [ -n "$selected_port" ]; then
sed -i "s|^GSM_ARDUINO_PORT=.*|GSM_ARDUINO_PORT=$selected_port|" "$SAPOT_ROOT/shared/gsm-arduino.env"
sed -i "s|^SERIAL_PORT=.*|SERIAL_PORT=$selected_port|" "$SAPOT_ROOT/shared/gsm-fastapi.env"
fi
for image in "$target"/images/*.tar; do load_image_archive "$image"; done
"$VERIFY_DIGESTS" "$target/manifest.json"
compose "$target" up -d db redis; wait_healthy "$target" db; wait_healthy "$target" redis
Expand Down
49 changes: 48 additions & 1 deletion deploy/scripts/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,53 @@ version=$(manifest_value "$source_manifest" version)
target="$SAPOT_ROOT/releases/v$version"
disk_preflight "$source_release" "$target" "$(manifest_value "$source_manifest" requiredDiskBytes)"
mkdir -p "$SAPOT_ROOT/releases"; [ -e "$target" ] || cp -a "$source_release" "$target"

hardware=$(manifest_value "$SAPOT_ROOT/shared/state.json" gsmHardwarePresent)
selected_port=""

if [ "$(python3 "$SEMVER" compare "$current_version" "0.0.8")" -lt 0 ] && [ "$hardware" != "true" ]; then
shopt -s nullglob
detected_ports=(/dev/ttyACM* /dev/ttyUSB*)
shopt -u nullglob

if [ ${#detected_ports[@]} -eq 0 ]; then
read -r -p "No GSM Arduino detected. Enter port path manually or leave empty to keep current setting: " answer
if [ -n "$answer" ]; then
selected_port="$answer"
hardware=true
fi
elif [ ${#detected_ports[@]} -eq 1 ]; then
read -r -p "Found GSM Arduino at ${detected_ports[0]}. Use this? [Y/n/custom/skip] " answer
if [[ "$answer" =~ ^[Yy]$ ]] || [ -z "$answer" ]; then
selected_port="${detected_ports[0]}"
hardware=true
elif [[ "$answer" =~ ^[Cc]ustom$ ]]; then
read -r -p "Enter custom port path: " selected_port
if [ -n "$selected_port" ]; then hardware=true; fi
elif [[ "$answer" =~ ^[Nn]$ ]]; then
hardware=false
fi
else
echo "Multiple GSM Arduino devices found:"
for i in "${!detected_ports[@]}"; do
echo " $((i+1))) ${detected_ports[$i]}"
done
read -r -p "Select a number, type a custom path, or leave empty to keep current setting: " answer
if [[ "$answer" =~ ^[0-9]+$ ]] && [ "$answer" -ge 1 ] && [ "$answer" -le "${#detected_ports[@]}" ]; then
selected_port="${detected_ports[$((answer-1))]}"
hardware=true
elif [ -n "$answer" ]; then
selected_port="$answer"
hardware=true
fi
fi

if [ "$hardware" = true ] && [ -n "$selected_port" ]; then
sed -i "s|^GSM_ARDUINO_PORT=.*|GSM_ARDUINO_PORT=$selected_port|" "$SAPOT_ROOT/shared/gsm-arduino.env"
sed -i "s|^SERIAL_PORT=.*|SERIAL_PORT=$selected_port|" "$SAPOT_ROOT/shared/gsm-fastapi.env"
fi
fi

for image in "$target"/images/*.tar; do load_image_archive "$image"; done; "$VERIFY_DIGESTS" "$target/manifest.json"
compose "$target" up -d db redis; wait_healthy "$target" db; wait_healthy "$target" redis
live=$(compose "$current" run --rm api alembic current 2>/dev/null | awk '/^[0-9a-f]+/ {print $1; exit}')
Expand All @@ -21,7 +68,7 @@ head=$(compose "$current" run --rm api alembic heads 2>/dev/null | awk '/^[0-9a-
compose "$target" run --rm api alembic upgrade head
compose "$target" up -d; for _ in {1..36}; do curl -kfs https://localhost/version >/dev/null 2>&1 && break; sleep 5; done
curl -kfsS https://localhost/version >/dev/null || { log_error "nginx/api did not become ready"; exit 1; }
hardware=$(manifest_value "$SAPOT_ROOT/shared/state.json" gsmHardwarePresent); ln -sfn "$target" "$SAPOT_ROOT/releases/current"; write_state upgrade "$current_version" "$version" "$hardware"
ln -sfn "$target" "$SAPOT_ROOT/releases/current"; write_state upgrade "$current_version" "$version" "$hardware"
# Refresh the unit files only. An operator who deliberately disabled a timer
# should not have an upgrade switch it back on, so nothing is enabled here.
install_systemd_units "$target"
Expand Down
Loading