Skip to content

Commit 9701c72

Browse files
authored
Making shell scripts POSIX compliant (#2015)
* feat: usage of rsync for backups * refactor: making scripts POSIX compliant
1 parent c64f31f commit 9701c72

File tree

10 files changed

+184
-162
lines changed

10 files changed

+184
-162
lines changed

scripts/linux-aarch64/install.sh

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
ALBYHUB_URL="https://getalby.com/install/hub/server-linux-aarch64.tar.bz2"
44
VERIFIER_URL="https://getalby.com/install/hub/verify.sh"
@@ -8,18 +8,19 @@ echo "⚡️ Welcome to Alby Hub"
88
echo "-----------------------------------------"
99
echo "Installing Alby Hub"
1010
echo ""
11-
read -p "Absolute install directory path (default: $HOME/albyhub): " USER_INSTALL_DIR
11+
printf "Absolute install directory path (default: %s/albyhub): " "$HOME"
12+
read USER_INSTALL_DIR
1213

1314
INSTALL_DIR="${USER_INSTALL_DIR:-$HOME/albyhub}"
1415

1516
# create installation directory
16-
mkdir -p $INSTALL_DIR
17-
cd $INSTALL_DIR
17+
mkdir -p "$INSTALL_DIR"
18+
cd "$INSTALL_DIR" || exit 1
1819

1920
# download and extract the Alby Hub executable
20-
wget $ALBYHUB_URL
21+
wget "$ALBYHUB_URL"
2122

22-
if [[ ! -f "verify.sh" ]]; then
23+
if [ ! -f "verify.sh" ]; then
2324
echo "Downloading the verification script..."
2425
if ! wget -q "$VERIFIER_URL"; then
2526
echo "❌ Failed to download the verification script." >&2
@@ -28,53 +29,54 @@ if [[ ! -f "verify.sh" ]]; then
2829
chmod +x verify.sh
2930
fi
3031

31-
./verify.sh server-linux-aarch64.tar.bz2 albyhub-Server-Linux-aarch64.tar.bz2
32-
if [[ $? -ne 0 ]]; then
32+
if ! ./verify.sh server-linux-aarch64.tar.bz2 albyhub-Server-Linux-aarch64.tar.bz2; then
3333
echo "❌ Verification failed, aborting installation"
3434
exit 1
3535
fi
3636

37-
tar xvf server-linux-aarch64.tar.bz2
38-
if [[ $? -ne 0 ]]; then
37+
if ! tar xvf server-linux-aarch64.tar.bz2; then
3938
echo "Failed to unpack Alby Hub. Potentially bzip2 is missing"
4039
echo "Install it with sudo apt-get install bzip2"
41-
exit
40+
exit 1
4241
fi
4342

4443
rm server-linux-aarch64.tar.bz2
4544

4645
# prepare the data directory. this is pesistent and will hold all important data
47-
mkdir -p $INSTALL_DIR/data
46+
mkdir -p "$INSTALL_DIR/data"
4847

4948
# create a simple start script that sets the default configuration variables
50-
tee $INSTALL_DIR/start.sh > /dev/null << EOF
51-
#!/bin/bash
49+
tee "$INSTALL_DIR/start.sh" > /dev/null << EOF
50+
#!/bin/sh
5251
5352
echo "Starting Alby Hub"
5453
WORK_DIR="$INSTALL_DIR/data" LDK_GOSSIP_SOURCE="" $INSTALL_DIR/bin/albyhub
5554
EOF
56-
chmod +x $INSTALL_DIR/start.sh
55+
chmod +x "$INSTALL_DIR/start.sh"
5756

5857
# add an update script to keep the Hub up to date
5958
# run this to update the hub
6059
wget https://raw.githubusercontent.com/getAlby/hub/master/scripts/linux-aarch64/update.sh
61-
chmod +x $INSTALL_DIR/update.sh
60+
chmod +x "$INSTALL_DIR/update.sh"
6261

6362
echo ""
6463
echo ""
6564
echo "✅ Installation done."
6665
echo ""
6766

6867
# optionally create a systemd service to start alby hub
69-
read -p "Do you want to setup a systemd service (requires sudo permission)? (y/n): " -n 1 -r
70-
if [[ ! $REPLY =~ ^[Yy]$ ]]
71-
then
72-
echo ""
73-
echo ""
74-
echo "Run $INSTALL_DIR/start.sh to start Alby Hub"
75-
echo "✅ DONE"
76-
exit
77-
fi
68+
printf "Do you want to setup a systemd service (requires sudo permission)? (y/n): "
69+
read REPLY
70+
case "$REPLY" in
71+
[Yy]*) ;;
72+
*)
73+
echo ""
74+
echo ""
75+
echo "Run $INSTALL_DIR/start.sh to start Alby Hub"
76+
echo "✅ DONE"
77+
exit
78+
;;
79+
esac
7880

7981
sudo tee /etc/systemd/system/albyhub.service > /dev/null << EOF
8082
[Unit]

scripts/linux-aarch64/update.sh

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
ALBYHUB_URL="https://getalby.com/install/hub/server-linux-aarch64.tar.bz2"
44
echo ""
@@ -10,65 +10,67 @@ echo "You will have to unlock Alby Hub after the update."
1010
echo ""
1111
echo "Make sure you have your unlock password available and a backup of your seed."
1212

13-
read -p "Do you want continue? (y/n):" -n 1 -r
14-
if [[ ! $REPLY =~ ^[Yy]$ ]]
15-
then
16-
exit
17-
fi
13+
printf "Do you want continue? (y/n): "
14+
read REPLY
15+
case "$REPLY" in
16+
[Yy]*) ;;
17+
*) exit ;;
18+
esac
1819
echo ""
1920

20-
sudo systemctl list-units --type=service --all | grep -Fq albyhub.service
21-
if [[ $? -eq 0 ]]; then
21+
if sudo systemctl list-units --type=service --all | grep -Fq albyhub.service; then
2222
echo "Stopping Alby Hub"
2323
sudo systemctl stop albyhub
2424
fi
2525

26-
if pgrep -x "albyhub" > /dev/null
27-
then
26+
if pgrep -x "albyhub" > /dev/null; then
2827
echo "Alby Hub process is still running, stopping it now."
2928
pkill -f albyhub
3029
fi
3130

3231
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
33-
read -p "Absolute install directory path (default: $SCRIPT_DIR): " USER_INSTALL_DIR
32+
printf "Absolute install directory path (default: %s): " "$SCRIPT_DIR"
33+
read USER_INSTALL_DIR
3434
echo ""
3535

3636
INSTALL_DIR="${USER_INSTALL_DIR:-$SCRIPT_DIR}"
3737

38-
if ! test -f $INSTALL_DIR/data/nwc.db; then
38+
if ! test -f "$INSTALL_DIR/data/nwc.db"; then
3939
echo "Could not find Alby Hub in this directory"
4040
exit 1
4141
fi
4242

4343

4444
echo "Running in $INSTALL_DIR"
4545
# make sure we run this in the install directory
46-
cd $INSTALL_DIR
46+
cd "$INSTALL_DIR" || exit 1
4747

4848
echo "Cleaning up old backup"
4949
rm -rf albyhub-backup
5050
mkdir albyhub-backup
5151

5252
echo "Creating current backup"
53-
mv bin albyhub-backup
54-
mv lib albyhub-backup
55-
cp -r data albyhub-backup
53+
if command -v rsync > /dev/null 2>&1; then
54+
rsync -av data bin lib albyhub-backup/
55+
else
56+
mv bin albyhub-backup
57+
mv lib albyhub-backup
58+
cp -r data albyhub-backup
59+
fi
5660

5761

5862
echo "Downloading latest version"
59-
wget $ALBYHUB_URL
63+
wget "$ALBYHUB_URL"
6064

61-
./verify.sh server-linux-aarch64.tar.bz2 albyhub-Server-Linux-aarch64.tar.bz2
62-
if [[ $? -ne 0 ]]; then
65+
if ! ./verify.sh server-linux-aarch64.tar.bz2 albyhub-Server-Linux-aarch64.tar.bz2; then
6366
echo "❌ Verification failed, aborting installation"
6467
exit 1
6568
fi
6669

6770
tar -xvf server-linux-aarch64.tar.bz2
6871
rm server-linux-aarch64.tar.bz2
6972

70-
sudo systemctl list-units --type=service --all | grep -Fq albyhub.service
71-
if [[ $? -eq 0 ]]; then
73+
if sudo systemctl list-units --type=service --all | grep -Fq albyhub.service; then
7274
echo "Starting Alby Hub"
7375
sudo systemctl start albyhub
7476
fi

scripts/linux-x86_64/install.sh

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
ALBYHUB_URL="https://getalby.com/install/hub/server-linux-x86_64.tar.bz2"
44
VERIFIER_URL="https://getalby.com/install/hub/verify.sh"
@@ -8,18 +8,19 @@ echo "⚡️ Welcome to Alby Hub"
88
echo "-----------------------------------------"
99
echo "Installing Alby Hub"
1010
echo ""
11-
read -p "Absolute install directory path (default: $HOME/albyhub): " USER_INSTALL_DIR
11+
printf "Absolute install directory path (default: %s/albyhub): " "$HOME"
12+
read USER_INSTALL_DIR
1213

1314
INSTALL_DIR="${USER_INSTALL_DIR:-$HOME/albyhub}"
1415

1516
# create installation directory
16-
mkdir -p $INSTALL_DIR
17-
cd $INSTALL_DIR
17+
mkdir -p "$INSTALL_DIR"
18+
cd "$INSTALL_DIR" || exit 1
1819

1920
# download and extract the Alby Hub executable
20-
wget $ALBYHUB_URL
21+
wget "$ALBYHUB_URL"
2122

22-
if [[ ! -f "verify.sh" ]]; then
23+
if [ ! -f "verify.sh" ]; then
2324
echo "Downloading the verification script..."
2425
if ! wget -q "$VERIFIER_URL"; then
2526
echo "❌ Failed to download the verification script." >&2
@@ -28,53 +29,54 @@ if [[ ! -f "verify.sh" ]]; then
2829
chmod +x verify.sh
2930
fi
3031

31-
./verify.sh server-linux-x86_64.tar.bz2 albyhub-Server-Linux-x86_64.tar.bz2
32-
if [[ $? -ne 0 ]]; then
32+
if ! ./verify.sh server-linux-x86_64.tar.bz2 albyhub-Server-Linux-x86_64.tar.bz2; then
3333
echo "❌ Verification failed, aborting installation"
3434
exit 1
3535
fi
3636

37-
tar xvf server-linux-x86_64.tar.bz2
38-
if [[ $? -ne 0 ]]; then
37+
if ! tar xvf server-linux-x86_64.tar.bz2; then
3938
echo "Failed to unpack Alby Hub. Potentially bzip2 is missing"
4039
echo "Install it with sudo apt-get install bzip2"
41-
exit
40+
exit 1
4241
fi
4342

4443
rm server-linux-x86_64.tar.bz2
4544

4645
# prepare the data directory. this is pesistent and will hold all important data
47-
mkdir -p $INSTALL_DIR/data
46+
mkdir -p "$INSTALL_DIR/data"
4847

4948
# create a simple start script that sets the default configuration variables
50-
tee $INSTALL_DIR/start.sh > /dev/null << EOF
51-
#!/bin/bash
49+
tee "$INSTALL_DIR/start.sh" > /dev/null << EOF
50+
#!/bin/sh
5251
5352
echo "Starting Alby Hub"
5453
WORK_DIR="$INSTALL_DIR/data" LDK_GOSSIP_SOURCE="" $INSTALL_DIR/bin/albyhub
5554
EOF
56-
chmod +x $INSTALL_DIR/start.sh
55+
chmod +x "$INSTALL_DIR/start.sh"
5756

5857
# add an update script to keep the Hub up to date
5958
# run this to update the hub
6059
wget https://raw.githubusercontent.com/getAlby/hub/master/scripts/linux-x86_64/update.sh
61-
chmod +x $INSTALL_DIR/update.sh
60+
chmod +x "$INSTALL_DIR/update.sh"
6261

6362
echo ""
6463
echo ""
6564
echo "✅ Installation done."
6665
echo ""
6766

6867
# optionally create a systemd service to start alby hub
69-
read -p "Do you want to setup a systemd service (requires sudo permission)? (y/n): " -n 1 -r
70-
if [[ ! $REPLY =~ ^[Yy]$ ]]
71-
then
72-
echo ""
73-
echo ""
74-
echo "Run $INSTALL_DIR/start.sh to start Alby Hub"
75-
echo "✅ DONE"
76-
exit
77-
fi
68+
printf "Do you want to setup a systemd service (requires sudo permission)? (y/n): "
69+
read REPLY
70+
case "$REPLY" in
71+
[Yy]*) ;;
72+
*)
73+
echo ""
74+
echo ""
75+
echo "Run $INSTALL_DIR/start.sh to start Alby Hub"
76+
echo "✅ DONE"
77+
exit
78+
;;
79+
esac
7880

7981
sudo tee /etc/systemd/system/albyhub.service > /dev/null << EOF
8082
[Unit]

0 commit comments

Comments
 (0)