update.sh raw
1 #!/bin/sh
2
3 ALBYHUB_URL="https://getalby.com/install/hub/server-linux-aarch64.tar.bz2"
4
5 # Default values
6 INSTALL_DIR=""
7 NON_INTERACTIVE=false
8 SKIP_VERIFY=false
9
10 # Parse command-line arguments
11 while [ $# -gt 0 ]; do
12 case "$1" in
13 -d|--install-dir)
14 if [ -z "$2" ] || [ "${2#-}" != "$2" ]; then
15 echo "Error: --install-dir requires a non-empty directory path"
16 exit 1
17 fi
18 INSTALL_DIR="$2"
19 shift 2
20 ;;
21 -y|--yes)
22 NON_INTERACTIVE=true
23 shift
24 ;;
25 --skip-verify)
26 SKIP_VERIFY=true
27 shift
28 ;;
29 -h|--help)
30 echo "Usage: $0 [OPTIONS]"
31 echo ""
32 echo "Options:"
33 echo " -d, --install-dir DIR Set installation directory (auto-detected by default)"
34 echo " -y, --yes Non-interactive mode (skip confirmation prompt)"
35 echo " --skip-verify Skip package signature verification"
36 echo " -h, --help Show this help message"
37 echo ""
38 echo "Examples:"
39 echo " $0 # Interactive mode"
40 echo " $0 -y # Skip confirmation prompt"
41 echo " $0 -y -d /opt/albyhub # Non-interactive with specific directory"
42 exit 0
43 ;;
44 *)
45 echo "Unknown option: $1"
46 echo "Use -h or --help for usage information"
47 exit 1
48 ;;
49 esac
50 done
51
52 echo ""
53 echo ""
54 echo "⚡️ Updating Alby Hub"
55 echo "-----------------------------------------"
56 echo "This will download the latest version of Alby Hub."
57 echo "You will have to unlock Alby Hub after the update."
58 echo ""
59 echo "Make sure you have your unlock password available and a backup of your seed."
60
61 # Confirmation prompt
62 if [ "$NON_INTERACTIVE" = false ]; then
63 printf "Do you want to continue? (y/n): "
64 read REPLY
65 case "$REPLY" in
66 [Yy]*) ;;
67 *) exit ;;
68 esac
69 echo ""
70 fi
71
72 if sudo systemctl list-units --type=service --all | grep -Fq albyhub.service; then
73 echo "Stopping Alby Hub"
74 sudo systemctl stop albyhub
75 fi
76
77 if pgrep -x "albyhub" > /dev/null; then
78 echo "Alby Hub process is still running, stopping it now."
79 pkill -f albyhub
80 fi
81
82 SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
83
84 # Determine install directory
85 if [ -z "$INSTALL_DIR" ]; then
86 if [ "$NON_INTERACTIVE" = true ]; then
87 INSTALL_DIR="$SCRIPT_DIR"
88 else
89 printf "Absolute install directory path (default: %s): " "$SCRIPT_DIR"
90 read USER_INSTALL_DIR
91 echo ""
92 INSTALL_DIR="${USER_INSTALL_DIR:-$SCRIPT_DIR}"
93 fi
94 fi
95
96 if ! test -f "$INSTALL_DIR/data/nwc.db"; then
97 echo "Could not find Alby Hub in this directory"
98 exit 1
99 fi
100
101
102 echo "Running in $INSTALL_DIR"
103 # make sure we run this in the install directory
104 cd "$INSTALL_DIR" || exit 1
105
106 echo "Cleaning up old backup"
107 rm -rf albyhub-backup
108 mkdir albyhub-backup
109
110 echo "Creating current backup"
111 if command -v rsync > /dev/null 2>&1; then
112 rsync -a data bin lib albyhub-backup/
113 else
114 mv bin albyhub-backup
115 mv lib albyhub-backup
116 cp -r data albyhub-backup
117 fi
118
119
120 echo "Downloading latest version"
121 wget -q "$ALBYHUB_URL"
122
123 if [ "$SKIP_VERIFY" = false ]; then
124 if ! ./verify.sh server-linux-aarch64.tar.bz2 albyhub-Server-Linux-aarch64.tar.bz2; then
125 echo "❌ Verification failed, aborting installation"
126 exit 1
127 fi
128 fi
129
130 tar -xf server-linux-aarch64.tar.bz2
131 rm server-linux-aarch64.tar.bz2
132
133 if sudo systemctl list-units --type=service --all | grep -Fq albyhub.service; then
134 echo "Starting Alby Hub"
135 sudo systemctl start albyhub
136 fi
137
138 echo ""
139 echo ""
140 echo "✅ Update finished! Please unlock your wallet."
141 echo ""
142