diff --git a/install-stack.sh b/install-stack.sh index ee8ddb3..e950d2a 100755 --- a/install-stack.sh +++ b/install-stack.sh @@ -1502,6 +1502,85 @@ ${build_out}" npm_add_location "/reports/" "10.10.10.122" 3080 } +deploy_wages() { + msg_step "Wages (LXC 124 · 10.10.10.124)" + + if [[ -z "${WAGES_DB_PASS:-}" ]]; then + WAGES_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) + printf '\nWAGES_DB_PASS=%s\n' "$WAGES_DB_PASS" >> "$CREDS_FILE" + msg_ok "Generated WAGES_DB_PASS → ${CREDS_FILE}" + fi + + msg_info "Creating LXC 124" + create_lxc 124 "10.10.10.124" "wages" 1024 1 + msg_ok "LXC 124 created" + + msg_info "Installing Docker" + install_docker 124 + install_mgmt_key 124 + msg_ok "Docker + SSH ready" + + msg_info "Creating wages database" + pct exec 100 -- bash -c " + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE USER wages WITH PASSWORD '${WAGES_DB_PASS}';\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE DATABASE wages_db OWNER wages;\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -d wages_db -c \ + \"GRANT ALL ON SCHEMA public TO wages;\" 2>/dev/null || true + " &>/dev/null + msg_ok "Database wages_db ready" + + msg_info "Deploying wages" + deploy_service 124 "wages" "${REPO_ROOT}/wages" /opt/wages + + push_file 124 /opt/wages/.env <&1"); then + msg_error "docker compose build failed in LXC 124: +${build_out}" + fi + + msg_info "Waiting for wages" + wait_healthy 124 "http://localhost:3080/wages/health" \ + && msg_ok "Wages running at 10.10.10.124:3080" \ + || msg_warn "Wages may need extra time — check LXC 124" + + msg_info "Seeding wages into auth DB" + pct exec 100 -- docker exec hotel-manage-postgres psql -U postgres -d auth_db -c " + INSERT INTO apps (slug, name, description, base_path, icon, theme_color, category, internal_host, internal_port) + VALUES ('wages', 'Wage Costs', 'Live wage cost reporting — weekly, monthly, and rolling history vs budget and net sales', '/wages', 'DollarSign', '#065f46', 'Finance', '10.10.10.124', 3080) + ON CONFLICT (slug) DO UPDATE SET + name=EXCLUDED.name, description=EXCLUDED.description, base_path=EXCLUDED.base_path, + icon=EXCLUDED.icon, theme_color=EXCLUDED.theme_color, category=EXCLUDED.category, + internal_host=EXCLUDED.internal_host, internal_port=EXCLUDED.internal_port; + INSERT INTO app_capabilities (app_id, slug, name, description, sort_order) + SELECT a.id, c.slug, c.name, c.description, c.sort_order + FROM apps a, (VALUES + ('view', 'View Reports', 'View all wage cost reports (weekly, monthly, rolling)', 1), + ('budget', 'Edit Budgets', 'Set monthly wage budget targets', 2), + ('sync', 'Manual Sync', 'Trigger a Workforce API data sync or backfill', 3), + ('settings', 'Settings', 'App settings, API configuration and department filter', 4) + ) AS c(slug, name, description, sort_order) + WHERE a.slug = 'wages' + ON CONFLICT (app_id, slug) DO NOTHING; + " &>/dev/null \ + && msg_ok "wages seeded into auth DB" \ + || msg_warn "Seed failed — run wages/seed-app.js manually" + + npm_add_location "/wages/" "10.10.10.124" 3080 +} + deploy_kitchen() { msg_step "Kitchen (LXC 110 · 10.10.10.110)" @@ -1913,7 +1992,7 @@ SUMMARY # Sources existing credentials and redeploys just the named service. if [[ "${1:-}" == "--only" ]]; then ONLY="${2:-}" - VALID="postgres auth portal npm management noticeboard settings cashup hk-planner twin-optimiser room-planner maintenance forecasting rates reports kitchen kds" + VALID="postgres auth portal npm management noticeboard settings cashup hk-planner twin-optimiser room-planner maintenance forecasting rates reports kitchen kds wages" [[ -z "$ONLY" ]] && msg_error "Usage: install-stack.sh --only (one of: ${VALID})" grep -qw "$ONLY" <<< "$VALID" || msg_error "Unknown service '${ONLY}'. Valid: ${VALID}" CREDS_FILE=/root/hotel-manage-credentials.txt @@ -1945,6 +2024,8 @@ if [[ "${1:-}" == "--only" ]]; then "$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)" [[ -z "${KITCHEN_DB_PASS:-}" ]] && _append_secret KITCHEN_DB_PASS \ "$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)" + [[ -z "${WAGES_DB_PASS:-}" ]] && _append_secret WAGES_DB_PASS \ + "$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)" USE_FORGEJO=true [[ -f /root/.ssh/hotel-manage_deploy.pub ]] \ @@ -1969,6 +2050,7 @@ if [[ "${1:-}" == "--only" ]]; then reports) deploy_reports ;; kitchen) deploy_kitchen ;; kds) deploy_kds ;; + wages) deploy_wages ;; esac exit 0 fi @@ -1996,5 +2078,6 @@ deploy_rates deploy_reports deploy_kitchen deploy_kds +deploy_wages configure_npm_proxy_hosts print_summary