Kaynağa Gözat

Setup fixes to pull necessary files

ArtyomV2X 1 ay önce
ebeveyn
işleme
298fd4891c
1 değiştirilmiş dosya ile 46 ekleme ve 21 silme
  1. 46 21
      setup.sh

+ 46 - 21
setup.sh

@@ -35,6 +35,10 @@ LOG_DIR="${YAAR_DIR}/logs"
 JOB_DIR="${YAAR_DIR}/jobs"
 PORT=7474
 
+# Raw file endpoint on Gogs. Used to fetch app files when they aren't already
+# present next to this script (i.e. when installing via the curl | sh one-liner).
+RAW="https://gogs.av2x.dev/av2x/yaar/raw/master"
+
 RED='\033[0;31m'; GREEN='\033[0;32m'; CYAN='\033[0;36m'; YELLOW='\033[0;33m'; NC='\033[0m'
 info()    { printf "${CYAN}[YAAR]${NC} %s\n" "$*"; }
 success() { printf "${GREEN}[OK]${NC} %s\n" "$*"; }
@@ -56,27 +60,50 @@ if command -v pveversion >/dev/null 2>&1; then
 fi
 
 # Make sure we're on Alpine (or at least warn loudly if not).
+# Read the prompt from the terminal, not stdin — stdin may be the piped script
+# when installing via `curl ... | sh`.
 if [ ! -f /etc/alpine-release ]; then
   warn "This does not look like an Alpine Linux system."
   warn "The apk commands below will fail on non-Alpine distros."
-  printf "${YELLOW}Continue anyway? [y/N] ${NC}"
-  read -r yn
-  case "$yn" in
-    [Yy]*) ;;
-    *) die "Aborted." ;;
-  esac
+  if [ -e /dev/tty ]; then
+    printf "${YELLOW}Continue anyway? [y/N] ${NC}"
+    read -r yn </dev/tty
+    case "$yn" in
+      [Yy]*) ;;
+      *) die "Aborted." ;;
+    esac
+  else
+    die "Not Alpine and no terminal to confirm. Aborting."
+  fi
 fi
 
-# Confirm the source files are next to this script.
-SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
-[ -f "${SCRIPT_DIR}/web/app.py" ] || \
-  die "Cannot find web/app.py relative to setup.sh (expected at ${SCRIPT_DIR}/web/app.py).
-       Make sure you extracted the full YAAR archive before running this."
-[ -f "${SCRIPT_DIR}/web/templates/index.html" ] || \
-  die "Cannot find web/templates/index.html relative to setup.sh."
+# Determine where app files come from. If this script was extracted alongside
+# the web/ folder (git clone / tarball), copy from disk. If it was piped in via
+# `curl ... | sh`, SCRIPT_DIR won't hold the files — fetch them from RAW instead.
+SCRIPT_DIR="$(cd "$(dirname "$0")" 2>/dev/null && pwd || echo /nonexistent)"
+
+# fetch_or_copy <relative-path> <destination>
+# Uses the local file when present, otherwise downloads it from the repo.
+fetch_or_copy() {
+  _rel="$1"; _dest="$2"
+  if [ -f "${SCRIPT_DIR}/${_rel}" ]; then
+    cp "${SCRIPT_DIR}/${_rel}" "${_dest}"
+  else
+    curl -fsSL "${RAW}/${_rel}" -o "${_dest}" \
+      || die "Could not fetch ${_rel} from ${RAW}"
+  fi
+}
 
 info "Running inside container as root — Proxmox host will not be touched."
 
+# Ensure curl exists now — fetch_or_copy and the mount/version checks may need it
+# before the main package install step runs.
+if ! command -v curl >/dev/null 2>&1; then
+  info "Installing curl (needed to fetch files)..."
+  apk add --no-cache curl ca-certificates >/dev/null 2>&1 || \
+    die "Could not install curl. Check network/DNS in the container."
+fi
+
 # ── 1. Bind-mount check ───────────────────────────────────────────────────────
 info "Checking Jellyfin media mount at ${MEDIA_DIR}..."
 MOUNT_READY=1
@@ -123,18 +150,16 @@ mkdir -p "${WEB_DIR}/templates" "${LOG_DIR}" "${JOB_DIR}"
 # YAAR will create Movies/, Shows/, YouTube/ inside it on first archive.
 success "Directories ready"
 
-# ── 4. Copy application files ─────────────────────────────────────────────────
+# ── 4. Install application files ──────────────────────────────────────────────
 info "Installing application files to ${WEB_DIR}..."
-cp "${SCRIPT_DIR}/web/app.py"               "${WEB_DIR}/app.py"
-cp "${SCRIPT_DIR}/web/templates/index.html" "${WEB_DIR}/templates/index.html"
+fetch_or_copy "web/app.py"               "${WEB_DIR}/app.py"
+fetch_or_copy "web/templates/index.html" "${WEB_DIR}/templates/index.html"
 success "Files installed"
 
 # ── 4b. Install update script + convenience command ───────────────────────────
-if [ -f "${SCRIPT_DIR}/update.sh" ]; then
-  info "Installing update script to ${YAAR_DIR}/update.sh..."
-  cp "${SCRIPT_DIR}/update.sh" "${YAAR_DIR}/update.sh"
+info "Installing update script to ${YAAR_DIR}/update.sh..."
+if fetch_or_copy "update.sh" "${YAAR_DIR}/update.sh" 2>/dev/null; then
   chmod +x "${YAAR_DIR}/update.sh"
-  # Convenience command: run `yaar-update` from anywhere.
   cat > /usr/local/bin/yaar-update <<'WRAPEOF'
 #!/bin/sh
 exec sh /opt/yaar/update.sh "$@"
@@ -142,7 +167,7 @@ WRAPEOF
   chmod +x /usr/local/bin/yaar-update
   success "Update script installed — run 'yaar-update' anytime"
 else
-  warn "update.sh not found in archive — skipping (you can add it later)"
+  warn "Could not install update.sh — you can add it later"
 fi
 
 # ── 5. Python virtualenv + pip packages ──────────────────────────────────────