|
@@ -13,13 +13,24 @@ WORK_DIR="${SCRIPT_DIR}"
|
|
|
if ! command -v "$DIALOG" >/dev/null 2>&1; then
|
|
if ! command -v "$DIALOG" >/dev/null 2>&1; then
|
|
|
echo "\n[ERROR] 'dialog' is not installed or not in PATH." >&2
|
|
echo "\n[ERROR] 'dialog' is not installed or not in PATH." >&2
|
|
|
echo "On macOS: brew install dialog" >&2
|
|
echo "On macOS: brew install dialog" >&2
|
|
|
- echo "On Debian: sudo apt-get install dialog" >&2
|
|
|
|
|
|
|
+ echo "On Debian: sudo apt install dialog" >&2
|
|
|
exit 1
|
|
exit 1
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+HAS_PODMAN=true
|
|
|
if ! command -v podman >/dev/null 2>&1; then
|
|
if ! command -v podman >/dev/null 2>&1; then
|
|
|
- "$DIALOG" --title "BeepZone Setup" --msgbox "podman is required but not found in PATH.\nPlease install and configure podman (podman-desktop recommended)." 10 60
|
|
|
|
|
- exit 1
|
|
|
|
|
|
|
+ HAS_PODMAN=false
|
|
|
|
|
+ "$DIALOG" --title "BeepZone Setup" --yes-label "Exit" --no-label "Ignore" --yesno "podman is recommended but not found in PATH.\nPlease install and configure podman (for dev work podman-desktop is recommended)." 10 60
|
|
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
|
|
+ exit 1
|
|
|
|
|
+ fi
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
|
|
+IS_DEBIAN_NATIVE=false
|
|
|
|
|
+if [[ -f /etc/debian_version ]]; then
|
|
|
|
|
+ if grep -qE "^(12|13)" /etc/debian_version; then
|
|
|
|
|
+ IS_DEBIAN_NATIVE=true
|
|
|
|
|
+ fi
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
# Check for MariaDB/MySQL client - try common brew locations on macOS
|
|
# Check for MariaDB/MySQL client - try common brew locations on macOS
|
|
@@ -50,8 +61,10 @@ elif [[ -x /usr/local/bin/mysql ]]; then
|
|
|
MYSQL_CLIENT="/usr/local/bin/mysql"
|
|
MYSQL_CLIENT="/usr/local/bin/mysql"
|
|
|
export PATH="/usr/local/bin:$PATH"
|
|
export PATH="/usr/local/bin:$PATH"
|
|
|
else
|
|
else
|
|
|
- "$DIALOG" --title "BeepZone Setup" --msgbox "MariaDB/MySQL client is required but not found.\n\nSearched locations:\n- System PATH\n- /opt/homebrew/opt/mysql-client/bin/\n- /opt/homebrew/opt/mariadb/bin/\n- /opt/homebrew/bin/\n- /usr/local/opt/mysql-client/bin/\n- /usr/local/bin/\n\nOn macOS: brew install mysql-client\nOn Debian: sudo apt-get install mariadb-client" 18 70
|
|
|
|
|
- exit 1
|
|
|
|
|
|
|
+ "$DIALOG" --title "BeepZone Setup" --yes-label "Exit" --no-label "Ignore" --yesno "MariaDB/MySQL client is required but not found.\n\nSearched locations:\n- System PATH\n- /opt/homebrew/opt/mysql-client/bin/\n- /opt/homebrew/opt/mariadb/bin/\n- /opt/homebrew/bin/\n- /usr/local/opt/mysql-client/bin/\n- /usr/local/bin/\n\nOn macOS: brew install mysql-client\nOn Debian: sudo apt-get install mariadb-client" 18 70
|
|
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
|
|
+ exit 1
|
|
|
|
|
+ fi
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
TMP_FILE="$(mktemp)"
|
|
TMP_FILE="$(mktemp)"
|
|
@@ -102,21 +115,43 @@ EOF
|
|
|
|
|
|
|
|
ask_main_menu() {
|
|
ask_main_menu() {
|
|
|
while true; do
|
|
while true; do
|
|
|
|
|
+ local options=()
|
|
|
|
|
+
|
|
|
|
|
+ if $HAS_PODMAN; then
|
|
|
|
|
+ options+=(1 "Configure and run MariaDB (podman)")
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ if $IS_DEBIAN_NATIVE; then
|
|
|
|
|
+ options+=(9 "Configure and run MariaDB (native Debian)") options+=(10 "Setup SeckelAPI (Native Debian)") fi
|
|
|
|
|
+
|
|
|
|
|
+ if [[ -n "$MYSQL_CLIENT" ]]; then
|
|
|
|
|
+ options+=(
|
|
|
|
|
+ 2 "Import DB schema and data"
|
|
|
|
|
+ 3 "Manage users and roles"
|
|
|
|
|
+ )
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ if $HAS_PODMAN; then
|
|
|
|
|
+ options+=(4 "Configure and setup SeckelAPI (podman)")
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ options+=(
|
|
|
|
|
+ 5 "Build desktop client"
|
|
|
|
|
+ 6 "Update from git masters"
|
|
|
|
|
+ 7 "Clean sources"
|
|
|
|
|
+ 8 "Quit"
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
$DIALOG --clear \
|
|
$DIALOG --clear \
|
|
|
--title "BeepZone Setup" \
|
|
--title "BeepZone Setup" \
|
|
|
--menu "Choose an action" 17 76 7 \
|
|
--menu "Choose an action" 17 76 7 \
|
|
|
- 1 "Configure & run MariaDB (podman)" \
|
|
|
|
|
- 2 "Import DB schema & data" \
|
|
|
|
|
- 3 "Manage users & roles" \
|
|
|
|
|
- 4 "Configure & setup SeckelAPI" \
|
|
|
|
|
- 5 "Build desktop client" \
|
|
|
|
|
- 6 "Update from git masters" \
|
|
|
|
|
- 7 "Clean sources" \
|
|
|
|
|
- 8 "Quit" 2>"$CHOICE_FILE"
|
|
|
|
|
|
|
+ "${options[@]}" 2>"$CHOICE_FILE"
|
|
|
|
|
|
|
|
choice=$(<"$CHOICE_FILE")
|
|
choice=$(<"$CHOICE_FILE")
|
|
|
case $choice in
|
|
case $choice in
|
|
|
1) configure_and_run_db ;;
|
|
1) configure_and_run_db ;;
|
|
|
|
|
+ 9) configure_and_run_native_db ;;
|
|
|
|
|
+ 10) setup_seckelapi_native ;;
|
|
|
2) import_schema_and_seed ;;
|
|
2) import_schema_and_seed ;;
|
|
|
3) manage_users_and_roles ;;
|
|
3) manage_users_and_roles ;;
|
|
|
4) setup_seckelapi ;;
|
|
4) setup_seckelapi ;;
|
|
@@ -191,6 +226,65 @@ configure_and_run_db() {
|
|
|
fi
|
|
fi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+configure_and_run_native_db() {
|
|
|
|
|
+ "$DIALOG" --msgbox "You'll need this for the Native MariaDB Setup:\n\n1. Debian 12/13\n2. Sudo privileges\n3. The following packages installed:\n - mariadb-server\n - mariadb-client\n - sudo\n\nIf you are unsure or know you're missing one hit CTRL-C now" 14 60
|
|
|
|
|
+
|
|
|
|
|
+ # Ask if root password is set
|
|
|
|
|
+ if ! "$DIALOG" --yesno "Have you already set up a root password for MariaDB?" 10 60; then
|
|
|
|
|
+ # User said No (exit code 1)
|
|
|
|
|
+ clear
|
|
|
|
|
+ echo "Running mysql_secure_installation..."
|
|
|
|
|
+ sudo mysql_secure_installation
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ $DIALOG --form "MariaDB configuration" 16 70 6 \
|
|
|
|
|
+ "DB Host" 1 1 "$DB_HOST" 1 18 30 30 \
|
|
|
|
|
+ "DB Port" 2 1 "$DB_PORT" 2 18 30 30 \
|
|
|
|
|
+ "DB Name" 3 1 "$DB_NAME" 3 18 30 30 \
|
|
|
|
|
+ "DB User" 4 1 "$DB_USER" 4 18 30 30 \
|
|
|
|
|
+ "DB Password" 5 1 "$DB_PASS" 5 18 30 30 \
|
|
|
|
|
+ "Root Password" 6 1 "$DB_ROOT_PASSWORD" 6 18 30 30 2>"$TMP_FILE" || return
|
|
|
|
|
+
|
|
|
|
|
+ # Parse dialog output (6 lines)
|
|
|
|
|
+ {
|
|
|
|
|
+ read -r DB_HOST
|
|
|
|
|
+ read -r DB_PORT
|
|
|
|
|
+ read -r DB_NAME
|
|
|
|
|
+ read -r DB_USER
|
|
|
|
|
+ read -r DB_PASS
|
|
|
|
|
+ read -r DB_ROOT_PASSWORD
|
|
|
|
|
+ } < "$TMP_FILE"
|
|
|
|
|
+
|
|
|
|
|
+ save_env
|
|
|
|
|
+
|
|
|
|
|
+ # Check if mariadb is even running
|
|
|
|
|
+ if ! systemctl is-active --quiet mariadb; then
|
|
|
|
|
+ if $DIALOG --yesno "MariaDB service aint running. Try and start it?" 10 60; then
|
|
|
|
|
+ sudo systemctl start mariadb || {
|
|
|
|
|
+ $DIALOG --msgbox "Crap, Failed to start MariaDB service" 8 60
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ return
|
|
|
|
|
+ fi
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ local create_sql="
|
|
|
|
|
+ CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\`;
|
|
|
|
|
+ CREATE USER IF NOT EXISTS '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASS}';
|
|
|
|
|
+ GRANT ALL PRIVILEGES ON \`${DB_NAME}\`.* TO '${DB_USER}'@'%';
|
|
|
|
|
+ FLUSH PRIVILEGES;
|
|
|
|
|
+ "
|
|
|
|
|
+
|
|
|
|
|
+ if "$DIALOG" --yesno "Script will now do the following:\n\nCreate DB: $DB_NAME\nCreate User: $DB_USER\n\nThis alright?" 12 70; then
|
|
|
|
|
+ if echo "$create_sql" | mysql -u root -p"$DB_ROOT_PASSWORD" 2>>"$LOG_FILE"; then
|
|
|
|
|
+ "$DIALOG" --msgbox "Database '$DB_NAME' and user '$DB_USER' created successfully." 8 70
|
|
|
|
|
+ else
|
|
|
|
|
+ "$DIALOG" --msgbox "Fuck something went wrong Check $LOG_FILE for details." 8 70
|
|
|
|
|
+ fi
|
|
|
|
|
+ fi
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
import_schema_and_seed() {
|
|
import_schema_and_seed() {
|
|
|
local import_type schema_file full_dump_file
|
|
local import_type schema_file full_dump_file
|
|
|
schema_file="$WORK_DIR/backend/database/schema/beepzone-schema-dump.sql"
|
|
schema_file="$WORK_DIR/backend/database/schema/beepzone-schema-dump.sql"
|
|
@@ -200,8 +294,8 @@ import_schema_and_seed() {
|
|
|
$DIALOG --clear \
|
|
$DIALOG --clear \
|
|
|
--title "Database Import" \
|
|
--title "Database Import" \
|
|
|
--menu "Select import type" 12 70 2 \
|
|
--menu "Select import type" 12 70 2 \
|
|
|
- 1 "Full dump (schema + data in one file)" \
|
|
|
|
|
- 2 "Clean schema only (no data)" 2>"$CHOICE_FILE" || return
|
|
|
|
|
|
|
+ 1 "Full dump (schema + data in one file, not recommended unless you know what you're doing)" \
|
|
|
|
|
+ 2 "Clean schema only (no data, recommended but make sure to read docs on how to get started)" 2>"$CHOICE_FILE" || return
|
|
|
|
|
|
|
|
import_type=$(<"$CHOICE_FILE")
|
|
import_type=$(<"$CHOICE_FILE")
|
|
|
|
|
|
|
@@ -212,7 +306,7 @@ import_schema_and_seed() {
|
|
|
return
|
|
return
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
- $DIALOG --yesno "import full database dump from:\n$full_dump_file\n\nThis will DROP and recreate the database.\n\nProceed?" 12 70 || return
|
|
|
|
|
|
|
+ $DIALOG --yesno "import full database dump from:\n$full_dump_file\n\nThis will DROP and recreate the database.\n\nYou Sure?" 12 70 || return
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
echo "DROP DATABASE IF EXISTS \`$DB_NAME\`;"
|
|
echo "DROP DATABASE IF EXISTS \`$DB_NAME\`;"
|
|
@@ -224,7 +318,7 @@ import_schema_and_seed() {
|
|
|
} | podman exec -i "$BEEPZONE_DB_CONTAINER_NAME" \
|
|
} | podman exec -i "$BEEPZONE_DB_CONTAINER_NAME" \
|
|
|
mariadb -h"$DB_HOST" -P"$DB_PORT" -uroot -p"$DB_ROOT_PASSWORD" >>"$LOG_FILE" 2>&1 || {
|
|
mariadb -h"$DB_HOST" -P"$DB_PORT" -uroot -p"$DB_ROOT_PASSWORD" >>"$LOG_FILE" 2>&1 || {
|
|
|
error_log=$(tail -30 "$LOG_FILE")
|
|
error_log=$(tail -30 "$LOG_FILE")
|
|
|
- $DIALOG --title "Error" --msgbox "full dump import failed.\n\nError:\n${error_log}" 22 76
|
|
|
|
|
|
|
+ $DIALOG --title "Fuck" --msgbox "full dump import failed.\n\nError:\n${error_log}" 22 76
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -692,6 +786,108 @@ setup_seckelapi() {
|
|
|
fi
|
|
fi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+setup_seckelapi_native() {
|
|
|
|
|
+ # 1. Check Pre-requisites
|
|
|
|
|
+ $DIALOG --msgbox "Pre-requisites for Native SeckelAPI Setup:\n\n1. Rust toolchain (rustup, cargo)\n2. build-essential (gcc, etc.)\n3. pkg-config\n4. libssl-dev\n5. Sudo privileges (for systemd service)\n\nEnsure these are met before proceeding." 14 60
|
|
|
|
|
+
|
|
|
|
|
+ local sources_dir="$WORK_DIR/backend/seckelapi/sources"
|
|
|
|
|
+ local config_dir="$WORK_DIR/backend/seckelapi/config"
|
|
|
|
|
+ local sources_basics_config="$sources_dir/config/basics.toml"
|
|
|
|
|
+
|
|
|
|
|
+ # 2. Clone sources if missing
|
|
|
|
|
+ if [[ ! -d "$sources_dir/.git" ]]; then
|
|
|
|
|
+ mkdir -p "$sources_dir"
|
|
|
|
|
+ clone_if_missing "$SECKELAPI_REPO" "$sources_dir" || return
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ # 3. Configure basics.toml
|
|
|
|
|
+ # Ensure sources config directory exists and copy all template configs
|
|
|
|
|
+ mkdir -p "$sources_dir/config"
|
|
|
|
|
+ for conf_file in "$config_dir"/*.toml; do
|
|
|
|
|
+ conf_name=$(basename "$conf_file")
|
|
|
|
|
+ cp "$conf_file" "$sources_dir/config/$conf_name" 2>>"$LOG_FILE"
|
|
|
|
|
+ done
|
|
|
|
|
+
|
|
|
|
|
+ if [[ -f "$sources_basics_config" ]]; then
|
|
|
|
|
+ # Update with DB settings from .env (localhost since it's native)
|
|
|
|
|
+ sed -i.bak \
|
|
|
|
|
+ -e '/^\[database\]/,/^\[/ {
|
|
|
|
|
+ /^host = /s|= .*|= "'"$DB_HOST"'"|
|
|
|
|
|
+ /^port = /s|= .*|= '"$DB_PORT"'|
|
|
|
|
|
+ /^database = /s|= .*|= "'"$DB_NAME"'"|
|
|
|
|
|
+ /^username = /s|= .*|= "'"$DB_USER"'"|
|
|
|
|
|
+ /^password = /s|= .*|= "'"$DB_PASS"'"|
|
|
|
|
|
+ }' \
|
|
|
|
|
+ "$sources_basics_config"
|
|
|
|
|
+ else
|
|
|
|
|
+ $DIALOG --msgbox "Error: basics.toml not found at $sources_basics_config" 8 60
|
|
|
|
|
+ return 1
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ # 4. Build Release
|
|
|
|
|
+ clear
|
|
|
|
|
+ echo "Building SeckelAPI (Native)..."
|
|
|
|
|
+ echo "============================"
|
|
|
|
|
+ echo ""
|
|
|
|
|
+
|
|
|
|
|
+ if (cd "$sources_dir" && cargo build --release); then
|
|
|
|
|
+ # Copy config files to the build output directory
|
|
|
|
|
+ local target_dir="$sources_dir/target/release"
|
|
|
|
|
+ mkdir -p "$target_dir/config"
|
|
|
|
|
+ cp "$sources_dir/config"/*.toml "$target_dir/config/" 2>>"$LOG_FILE"
|
|
|
|
|
+
|
|
|
|
|
+ echo ""
|
|
|
|
|
+ echo "Build completed successfully!"
|
|
|
|
|
+ else
|
|
|
|
|
+ echo ""
|
|
|
|
|
+ echo "Build failed! Check the output above for errors."
|
|
|
|
|
+ read -p "Press Enter to continue..."
|
|
|
|
|
+ return 1
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ # 5. Install Systemd Service
|
|
|
|
|
+ if $DIALOG --yesno "Do you want to install SeckelAPI as a systemd service?" 8 60; then
|
|
|
|
|
+ local service_name="beepzone-seckelapi"
|
|
|
|
|
+ local service_file="/tmp/${service_name}.service"
|
|
|
|
|
+ local current_user
|
|
|
|
|
+ current_user=$(whoami)
|
|
|
|
|
+
|
|
|
|
|
+ # Working directory for the binary
|
|
|
|
|
+ local working_dir="$sources_dir/target/release"
|
|
|
|
|
+ local exec_path="$working_dir/seckelapi"
|
|
|
|
|
+
|
|
|
|
|
+ cat > "$service_file" <<EOF
|
|
|
|
|
+[Unit]
|
|
|
|
|
+Description=BeepZone SeckelAPI Service
|
|
|
|
|
+After=network.target mariadb.service
|
|
|
|
|
+Requires=mariadb.service
|
|
|
|
|
+
|
|
|
|
|
+[Service]
|
|
|
|
|
+Type=simple
|
|
|
|
|
+User=${current_user}
|
|
|
|
|
+WorkingDirectory=${working_dir}
|
|
|
|
|
+ExecStart=${exec_path}
|
|
|
|
|
+Restart=always
|
|
|
|
|
+RestartSec=10
|
|
|
|
|
+Environment=RUST_LOG=info
|
|
|
|
|
+
|
|
|
|
|
+[Install]
|
|
|
|
|
+WantedBy=multi-user.target
|
|
|
|
|
+EOF
|
|
|
|
|
+
|
|
|
|
|
+ echo "Installing systemd service..."
|
|
|
|
|
+ sudo mv "$service_file" "/etc/systemd/system/${service_name}.service"
|
|
|
|
|
+ sudo systemctl daemon-reload
|
|
|
|
|
+ sudo systemctl enable "${service_name}"
|
|
|
|
|
+
|
|
|
|
|
+ if sudo systemctl start "${service_name}"; then
|
|
|
|
|
+ $DIALOG --msgbox "Service '${service_name}' installed and started successfully!" 8 60
|
|
|
|
|
+ else
|
|
|
|
|
+ $DIALOG --msgbox "Failed to start service '${service_name}'. Check 'sudo systemctl status ${service_name}'" 10 70
|
|
|
|
|
+ fi
|
|
|
|
|
+ fi
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
update_from_git_masters() {
|
|
update_from_git_masters() {
|
|
|
local seckelapi_sources="$WORK_DIR/backend/seckelapi/sources"
|
|
local seckelapi_sources="$WORK_DIR/backend/seckelapi/sources"
|
|
|
local client_sources="$WORK_DIR/frontend/desktop-client/sources"
|
|
local client_sources="$WORK_DIR/frontend/desktop-client/sources"
|