#!/usr/bin/env bash set -euo pipefail if [ "$#" -lt 3 ] || [ "$#" -gt 4 ]; then echo "Usage: scripts/deploy-raspi.sh [domain]" exit 1 fi ssh_user="$1" ssh_host="$2" repo_url="$3" domain="${4:-DietPi.ntp.kentcommunications.com}" deploy_path="${DEPLOY_PATH:-/var/www/warehouse}" deploy_ref="${DEPLOY_REF:-master}" ssh "${ssh_user}@${ssh_host}" bash -s -- "$repo_url" "$domain" "$deploy_path" "$deploy_ref" <<'REMOTE' set -euo pipefail repo_url="$1" domain="$2" deploy_path="$3" deploy_ref="$4" owner="$(id -un)" group="$(id -gn)" set_env() { file="$1" key="$2" value="$3" if grep -q "^${key}=" "$file"; then sed -i "s|^${key}=.*|${key}=${value}|" "$file" else printf '%s=%s\n' "$key" "$value" >> "$file" fi } sudo apt-get update sudo apt-get install -y \ git nginx composer \ php php-cli php-fpm php-mbstring php-xml php-curl php-zip php-sqlite3 php-mysql php_version="$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')" php_fpm_service="php${php_version}-fpm" php_fpm_socket="/run/php/${php_fpm_service}.sock" sudo mkdir -p "$(dirname "$deploy_path")" if [ ! -d "$deploy_path/.git" ]; then sudo git clone --branch "$deploy_ref" --single-branch "$repo_url" "$deploy_path" sudo chown -R "$owner:$group" "$deploy_path" else git -C "$deploy_path" fetch --prune origin git -C "$deploy_path" checkout "$deploy_ref" git -C "$deploy_path" reset --hard "origin/$deploy_ref" fi cd "$deploy_path" if [ ! -f .env ] && [ -f .env.example ]; then cp .env.example .env fi set_env .env APP_ENV prod set_env .env DB_CONNECTION sqlite set_env .env DB_SQLITE_PATH "$deploy_path/database/database.sqlite" composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader --ignore-platform-reqs mkdir -p storage/framework/views database touch database/database.sqlite sudo chgrp -R www-data storage database sudo chmod -R g+rwX storage database sudo find storage database -type d -exec chmod 2775 {} \; sudo chmod 664 database/database.sqlite php command.php migrate sudo tee /etc/systemd/system/warehouse-queue.service >/dev/null </dev/null <