upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/install-bitflash-wine.sh
diff options
context:
space:
mode:
Diffstat (limited to 'install-bitflash-wine.sh')
-rw-r--r--install-bitflash-wine.sh211
1 files changed, 0 insertions, 211 deletions
diff --git a/install-bitflash-wine.sh b/install-bitflash-wine.sh
deleted file mode 100644
index 91fef59..0000000
--- a/install-bitflash-wine.sh
+++ /dev/null
@@ -1,211 +0,0 @@
1#!/usr/bin/env bash
2# Bitflash GUI installer for Linux (via Wine) — hardened
3set -euo pipefail
4
5INSTALL_DIR="$HOME/.btf-wine"
6WINE_DATA="$HOME/.wine/drive_c/users/$USER/AppData/Roaming/Bitflash"
7LINUX_DATA="$HOME/.bitflash"
8BIN_DIR="$HOME/.local/bin"
9REPO="Bitflash-sh/bitflash"
10
11echo "==> Bitflash GUI installer"
12echo
13
14# ---- Safety: don't run as root (breaks Wine + pollutes /root)
15if [ "$(id -u)" -eq 0 ]; then
16 echo "ERROR: do not run this as root. Run as your normal user (it will call sudo only when needed)." >&2
17 exit 1
18fi
19
20need() { command -v "$1" >/dev/null 2>&1; }
21
22# ---- Wine
23echo "==> Checking Wine..."
24if ! need wine; then
25 echo " Installing Wine..."
26 if ! need apt-get; then
27 echo "ERROR: apt-get not found. Install 'wine' manually, then re-run." >&2
28 exit 1
29 fi
30 sudo apt-get update -qq
31 sudo apt-get install -y wine
32fi
33echo " Wine: $(wine --version)"
34
35# ---- db-util (db_dump / db_load for wallet conversion)
36echo "==> Checking db-util..."
37if ! need db_dump; then
38 echo " Installing db-util..."
39 sudo apt-get install -y db-util
40fi
41echo " db_dump: $(command -v db_dump)"
42
43# ---- unzip + sha256sum must exist
44for tool in unzip sha256sum curl; do
45 if ! need "$tool"; then
46 echo " Installing $tool..."
47 sudo apt-get install -y "$tool"
48 fi
49done
50
51# ---- Resolve latest release (single API call)
52echo "==> Fetching latest release metadata from GitHub..."
53API_JSON=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest")
54
55RELEASE_URL=$(printf '%s\n' "$API_JSON" | grep '"browser_download_url"' \
56 | grep -iE 'win|windows|gui' | head -1 | cut -d '"' -f 4 || true)
57[ -z "$RELEASE_URL" ] && RELEASE_URL=$(printf '%s\n' "$API_JSON" | grep '"browser_download_url"' \
58 | grep -iE '\.zip"?$' | head -1 | cut -d '"' -f 4 || true)
59
60if [ -z "$RELEASE_URL" ]; then
61 echo "ERROR: no downloadable release asset found at https://github.com/$REPO/releases" >&2
62 exit 1
63fi
64ASSET_NAME=$(basename "$RELEASE_URL")
65echo " Asset: $ASSET_NAME"
66
67# checksum manifest published alongside the release (SHA256SUMS)
68SUMS_URL=$(printf '%s\n' "$API_JSON" | grep '"browser_download_url"' \
69 | grep -iE 'sha256sums|checksums|\.sha256"?$' | head -1 | cut -d '"' -f 4 || true)
70
71# ---- Download the release
72TMPZIP=$(mktemp /tmp/bitflash-XXXXXX.zip)
73cleanup() { rm -f "$TMPZIP" "${TMPSUMS:-}"; }
74trap cleanup EXIT
75echo "==> Downloading release..."
76curl -fL --retry 3 --retry-delay 2 -o "$TMPZIP" "$RELEASE_URL"
77echo " Downloaded: $(du -h "$TMPZIP" | cut -f1)"
78
79# ---- MANDATORY integrity check
80echo "==> Verifying integrity..."
81GOT=$(sha256sum "$TMPZIP" | awk '{print $1}')
82if [ -n "${EXPECTED_SHA256:-}" ]; then
83 # Strongest: user pinned a known-good hash out-of-band.
84 if [ "$GOT" != "$EXPECTED_SHA256" ]; then
85 echo "ERROR: checksum mismatch. expected $EXPECTED_SHA256, got $GOT" >&2
86 exit 1
87 fi
88 echo " OK (matches pinned EXPECTED_SHA256)"
89elif [ -n "$SUMS_URL" ]; then
90 TMPSUMS=$(mktemp /tmp/bitflash-sums-XXXXXX)
91 curl -fsSL --retry 3 -o "$TMPSUMS" "$SUMS_URL"
92 WANT=$(grep -iF "$ASSET_NAME" "$TMPSUMS" | awk '{print $1}' | head -1 || true)
93 if [ -z "$WANT" ]; then
94 echo "ERROR: no checksum for $ASSET_NAME in published SHA256SUMS." >&2
95 exit 1
96 fi
97 if [ "$GOT" != "$WANT" ]; then
98 echo "ERROR: checksum mismatch. published $WANT, got $GOT" >&2
99 exit 1
100 fi
101 echo " OK (matches published SHA256SUMS)"
102else
103 echo "ERROR: no checksum available for this release." >&2
104 echo " Publish a SHA256SUMS asset with the release, or re-run with" >&2
105 echo " EXPECTED_SHA256=<hash> to verify against a known-good value." >&2
106 echo " (To bypass at your own risk: ALLOW_UNVERIFIED=1)" >&2
107 if [ "${ALLOW_UNVERIFIED:-0}" != "1" ]; then
108 exit 1
109 fi
110 echo " WARNING: proceeding UNVERIFIED (ALLOW_UNVERIFIED=1). sha256=$GOT"
111fi
112
113# ---- Extract
114echo "==> Extracting to $INSTALL_DIR..."
115rm -rf "$INSTALL_DIR"
116mkdir -p "$INSTALL_DIR"
117unzip -j -o "$TMPZIP" -d "$INSTALL_DIR" >/dev/null
118
119# ---- Rename backslash-mangled entries (Windows zip paths)
120count=0
121for f in "$INSTALL_DIR"/*; do
122 [ -f "$f" ] || continue
123 base=$(basename "$f")
124 newname=$(printf '%s' "$base" | sed 's/.*\\//')
125 if [ "$newname" != "$base" ]; then
126 mv "$f" "$INSTALL_DIR/$newname"
127 count=$((count+1))
128 fi
129done
130echo " Renamed $count files; total: $(ls "$INSTALL_DIR" | wc -l)"
131
132# Locate the Bitflash exe case-insensitively (zip may ship Bitflash.exe or bitflash.exe)
133EXE=$(find "$INSTALL_DIR" -maxdepth 1 -iname 'bitflash.exe' | head -1)
134if [ -z "$EXE" ]; then
135 echo "ERROR: bitflash exe not found after extract. Contents:" >&2
136 ls "$INSTALL_DIR" >&2
137 exit 1
138fi
139echo " Found $(basename "$EXE")"
140
141# ---- Init Wine data dir
142echo "==> Initializing Wine data directory..."
143WINEDLLOVERRIDES="libdb_cxx-6.2=n" wine "$EXE" &
144WINE_PID=$!
145created=0
146for i in $(seq 1 30); do
147 sleep 1
148 if [ -f "$WINE_DATA/wallet.dat" ]; then
149 echo " wallet.dat created after ${i}s"
150 created=1
151 break
152 fi
153done
154kill "$WINE_PID" 2>/dev/null || true
155wait "$WINE_PID" 2>/dev/null || true
156sleep 1
157mkdir -p "$WINE_DATA"
158[ "$created" -eq 1 ] || echo " NOTE: Wine did not create wallet.dat in 30s; continuing."
159
160# ---- Optional wallet import (with backup)
161echo
162if [ -f "$LINUX_DATA/wallet.dat" ]; then
163 echo "==> Found existing Linux wallet at $LINUX_DATA/wallet.dat"
164 read -r -p " Import it into the GUI wallet? [Y/n] " ans
165 ans=${ans:-Y}
166 if [[ "$ans" =~ ^[Yy] ]]; then
167 if [ -f "$WINE_DATA/wallet.dat" ]; then
168 BK="$WINE_DATA/wallet.dat.bak.$(date +%Y%m%d%H%M%S)"
169 cp "$WINE_DATA/wallet.dat" "$BK"
170 echo " Backed up existing GUI wallet -> $BK"
171 fi
172 DUMP=$(mktemp); CONVERTED=$(mktemp); rm -f "$CONVERTED"
173 echo " Converting Linux wallet format..."
174 db_dump -p "$LINUX_DATA/wallet.dat" > "$DUMP"
175 db_load -f "$DUMP" "$CONVERTED"
176 cp "$CONVERTED" "$WINE_DATA/wallet.dat"
177 rm -f "$DUMP" "$CONVERTED"
178 echo " Wallet imported."
179 else
180 echo " Skipped. Re-run to import later."
181 fi
182else
183 echo "==> No Linux wallet found, starting fresh."
184fi
185
186# ---- Launcher
187echo "==> Creating 'bitflash' command..."
188mkdir -p "$BIN_DIR"
189LAUNCHER_FILE="$BIN_DIR/bitflash"
190cat > "$LAUNCHER_FILE" <<EOF
191#!/usr/bin/env bash
192RELAY="\${BTF_RELAY:-}"
193ANNOUNCE=""
194[ -n "\$RELAY" ] && ANNOUNCE="-announcerelay=\$RELAY"
195WINEDLLOVERRIDES="libdb_cxx-6.2=n" wine "$EXE" \$ANNOUNCE "\$@"
196EOF
197chmod +x "$LAUNCHER_FILE"
198
199if [[ ":$PATH:" != *":$BIN_DIR:"* ]] && ! grep -qF 'export PATH="$HOME/.local/bin:$PATH"' "$HOME/.bashrc" 2>/dev/null; then
200 echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.bashrc"
201 echo " Added ~/.local/bin to PATH (restart shell or: source ~/.bashrc)"
202fi
203
204echo
205echo "=================================================================="
206echo " DONE."
207echo " Launch: bitflash"
208echo " Mine: bitflash -gen"
209echo " Relay: bitflash -announcerelay=YOUR_HOST:8434"
210echo " Data: $WINE_DATA"
211echo "=================================================================="