Last active
December 24, 2025 09:41
-
-
Save Milz0/8b10ff394a40d7d624c3f755b199397d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # -------------------------------------------------- | |
| # VERY EARLY LOGGING (NO strict mode yet) | |
| # -------------------------------------------------- | |
| LOG_FILE="/var/log/qp-init.log" | |
| mkdir -p /var/log | |
| touch "$LOG_FILE" | |
| chmod 644 "$LOG_FILE" | |
| exec >>"$LOG_FILE" 2>&1 | |
| echo "===== qp-init starting at $(date) =====" | |
| export DEBIAN_FRONTEND=noninteractive | |
| # -------------------------------------------------- | |
| # CONFIG | |
| # -------------------------------------------------- | |
| R2_BROWSER_URL="https://gist.githubusercontent.com/Milz0/2905440d96b8e9fce626537aedb80a3f/raw/0d9b1b288ef470ff413e74034898e7a971a657a0/r2-browser.sh" | |
| # -------------------------------------------------- | |
| # Sanity | |
| # -------------------------------------------------- | |
| echo "[qp-init] user: $(id)" | |
| echo "[qp-init] bash: $BASH_VERSION" | |
| echo "[qp-init] curl: $(command -v curl || echo missing)" | |
| # -------------------------------------------------- | |
| # Enable strict mode AFTER logging | |
| # -------------------------------------------------- | |
| set -Eeuo pipefail | |
| # -------------------------------------------------- | |
| # Install rclone ONLY (no apt) | |
| # -------------------------------------------------- | |
| if ! command -v rclone >/dev/null 2>&1; then | |
| echo "[qp-init] installing rclone" | |
| if curl -fL https://rclone.org/install.sh | bash; then | |
| echo "[qp-init] rclone installed: $(rclone version | head -n 1)" | |
| else | |
| echo "[ERROR] rclone install failed" | |
| fi | |
| else | |
| echo "[qp-init] rclone already present: $(rclone version | head -n 1)" | |
| fi | |
| # -------------------------------------------------- | |
| # Helper directory | |
| # -------------------------------------------------- | |
| install -d -m 755 /usr/local/bin | |
| # -------------------------------------------------- | |
| # r2-bootstrap.sh (bucket REQUIRED) | |
| # -------------------------------------------------- | |
| echo "[qp-init] writing r2-bootstrap.sh" | |
| cat >/usr/local/bin/r2-bootstrap.sh <<'EOF' | |
| #!/usr/bin/env bash | |
| set -Eeuo pipefail | |
| : "${R2_ACCESS_KEY_ID:?missing}" | |
| : "${R2_SECRET_ACCESS_KEY:?missing}" | |
| : "${R2_ACCOUNT_ID:?missing}" | |
| : "${R2_BUCKET:?missing}" | |
| CFG_DIR="$HOME/.config/rclone" | |
| CFG_FILE="$CFG_DIR/rclone.conf" | |
| mkdir -p "$CFG_DIR" | |
| chmod 700 "$CFG_DIR" | |
| cat >"$CFG_FILE" <<CONF | |
| [r2] | |
| type = s3 | |
| provider = Cloudflare | |
| access_key_id = ${R2_ACCESS_KEY_ID} | |
| secret_access_key = ${R2_SECRET_ACCESS_KEY} | |
| endpoint = https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com | |
| acl = private | |
| CONF | |
| chmod 600 "$CFG_FILE" | |
| echo "[r2-bootstrap] configured bucket: $R2_BUCKET" | |
| EOF | |
| chmod +x /usr/local/bin/r2-bootstrap.sh | |
| # -------------------------------------------------- | |
| # Download r2-browser.sh (DO NOT HARD FAIL) | |
| # -------------------------------------------------- | |
| echo "[qp-init] downloading r2-browser.sh" | |
| echo "[qp-init] url: $R2_BROWSER_URL" | |
| if curl -fL --retry 5 --retry-delay 2 \ | |
| --connect-timeout 10 \ | |
| "$R2_BROWSER_URL" \ | |
| -o /usr/local/bin/r2-browser.sh; then | |
| chmod +x /usr/local/bin/r2-browser.sh | |
| echo "[qp-init] r2-browser.sh installed" | |
| else | |
| echo "[ERROR] failed to download r2-browser.sh (continuing)" | |
| fi | |
| # -------------------------------------------------- | |
| # Done | |
| # -------------------------------------------------- | |
| echo "[qp-init] complete at $(date)" | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment