Skip to content

Commit a4ac7bf

Browse files
committed
feat: revamp upgrade paths
1 parent 10aa3ec commit a4ac7bf

File tree

1 file changed

+78
-35
lines changed

1 file changed

+78
-35
lines changed

availup.sh

Lines changed: 78 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22
echo "🆙 Starting Availup..."
33
while [ $# -gt 0 ]; do
4-
if [[ $1 == "--"* ]]; then
4+
if [[ $1 = "--"* ]]; then
55
v="${1/--/}"
66
declare "$v"="$2"
77
shift
88
fi
99
shift
1010
done
11-
if [ -f "$HOME/.bashrc" ]; then
11+
# check if bash is current terminal shell, else check for zsh
12+
if [ -z "$BASH_VERSION" ]; then
13+
if [ -z "$ZSH_VERSION" ]; then
14+
echo "🚫 Unable to locate a shell. Availup might not work as intended!"
15+
else
16+
CURRENT_TERM="zsh"
17+
fi
18+
else
19+
CURRENT_TERM="bash"
20+
fi
21+
if [ "$CURRENT_TERM" = "bash" -a -f "$HOME/.bashrc" ]; then
1222
PROFILE="$HOME/.bashrc"
13-
elif [ -f "$HOME/.zshrc" ]; then
23+
elif [ "$CURRENT_TERM" = "bash" -a -f "$HOME/.bash_profile" ]; then
24+
PROFILE="$HOME/.bash_profile"
25+
elif [ "$CURRENT_TERM" = "bash" -a -f "$HOME/.zshrc" ]; then
1426
PROFILE="$HOME/.zshrc"
15-
elif [ -f "$HOME/.kshrc" ]; then
16-
PROFILE="$HOME/.kshrc"
27+
elif [ "$CURRENT_TERM" = "bash" -a -f "$HOME/.zsh_profile" ]; then
28+
PROFILE="$HOME/.zsh_profile"
29+
elif [ "$CURRENT_TERM" = "zsh" -a -f "$HOME/.zshrc" ]; then
30+
PROFILE="$HOME/.zshrc"
31+
elif [ "$CURRENT_TERM" = "zsh" -a -f "$HOME/.zsh_profile" ]; then
32+
PROFILE="$HOME/.zsh_profile"
33+
elif [ "$CURRENT_TERM" = "bash" ]; then
34+
PROFILE="$HOME/.bashrc"
35+
touch $HOME/.bashrc
36+
elif [ "$CURRENT_TERM" = "zsh" ]; then
37+
PROFILE="$HOME/.zshrc"
38+
touch $HOME/.zshrc
1739
else
18-
echo "🫣 Unable to locate a shell rc file, using POSIX default, availup might not work as intended!"
40+
echo "🫣 Unable to locate a compatible shell or rc file, using POSIX default, availup might not work as intended!"
1941
PROFILE="/etc/profile"
2042
fi
2143
if [ -z "$network" ]; then
@@ -27,9 +49,6 @@ fi
2749
if [ "$NETWORK" = "goldberg" ]; then
2850
echo "📌 Goldberg network selected."
2951
VERSION="v1.7.9"
30-
elif [ "$NETWORK" = "kate" ]; then
31-
echo "📌 Kate network selected."
32-
VERSION="v1.7.9"
3352
elif [ "$NETWORK" = "local" ]; then
3453
echo "📌 Local network selected."
3554
VERSION="v1.7.9"
@@ -44,46 +63,73 @@ else
4463
APPID="$app_id"
4564
fi
4665
if [ -z "$identity" ]; then
47-
if [ -f "$HOME/.availup/identity.toml" ]; then
48-
IDENTITY=$HOME/.availup/identity.toml
66+
IDENTITY=$HOME/.avail/identity/identity.toml
67+
if [ -f "$HOME/.avail/identity/identity.toml" ]; then
4968
echo "🔑 Identity found at $IDENTITY."
5069
else
5170
echo "🤷 No identity set. This will be automatically generated at startup."
5271
fi
5372
else
5473
IDENTITY="$identity"
5574
fi
56-
if [ "$upgrade" == "y" ] || [ "$upgrade" == "yes" ]; then
57-
UPGRADE=1
58-
else
59-
UPGRADE=0
75+
if [ ! -d "$HOME/.avail" ]; then
76+
mkdir $HOME/.avail
77+
fi
78+
if [ ! -d "$HOME/.avail/bin" ]; then
79+
mkdir $HOME/.avail/bin
80+
fi
81+
if [ ! -d "$HOME/.avail/identity" ]; then
82+
mkdir $HOME/.avail/identity
83+
fi
84+
# check if avail-light version matches!
85+
UPGRADE=0
86+
if [ ! -z "$upgrade" ]; then
87+
echo "🔄 Checking for updates..."
88+
if command -v avail-light >/dev/null 2>&1; then
89+
CURRENT_VERSION="v$(avail-light --version | cut -d " " -f 2)"
90+
if [ "$CURRENT_VERSION" = "v1.7.8" ] && [ "$VERSION" = "v1.7.9" ]; then
91+
UPGRADE=0
92+
echo "✨ Avail binary is up to date. Skipping upgrade."
93+
elif [ "$CURRENT_VERSION" != "$VERSION" ]; then
94+
UPGRADE=1
95+
echo "✨ Avail binary is up to date. Skipping upgrade."
96+
else
97+
if [ "$upgrade" = "y" ] || [ "$upgrade" = "yes" ]; then
98+
UPGRADE=1
99+
fi
100+
fi
101+
fi
60102
fi
103+
61104
onexit() {
62-
echo "🔄 Avail stopped. Future instances of the light client can be started by invoking the avail-light binary directly$EXTRAPROMPT"
63-
if [[ ":$PATH:" != *":$HOME/.availup:"* ]]; then
64-
echo "\nexport PATH=\$PATH:$HOME/.availup" >> $PROFILE
65-
echo "📌 Avail has been added to your profile. Please run the following command to load it in the current terminal session:\nsource $PROFILE\n👉 Alternatively, you can add it for this session by running the following command:\nexport PATH=\$PATH:$HOME/.availup"
105+
echo "🔄 Avail stopped. Future instances of the light client can be started by invoking the avail-light binary or rerunning this script$EXTRAPROMPT"
106+
if [[ ":$PATH:" != *":$HOME/.avail/bin:"* ]]; then
107+
if ! grep -q "export PATH=\"\$PATH:$HOME/.avail/bin\"" "$PROFILE"; then
108+
echo -e "export PATH=\"\$PATH:$HOME/.avail/bin\"\n" >> $PROFILE
109+
fi
110+
echo -e "📌 Avail has been added to your profile. Run the following command to load it in the current terminal session:\n. $PROFILE\n"
66111
fi
67112
exit 0
68113
}
69-
if [ command -v avail-light >/dev/null 2>&1 ] && [ "$UPGRADE" = 0 ]; then
114+
# check if avail-light binary is available and check if upgrade variable is set to 0
115+
if command -v avail-light >/dev/null 2>&1 && [ "$UPGRADE" = 0 ]; then
70116
echo "✅ Avail is already installed. Starting Avail..."
71117
trap onexit EXIT
72118
if [ -z "$config" ] && [ ! -z "$identity" ]; then
73-
$HOME/.availup/avail-light --network $NETWORK --app-id $APPID --identity $IDENTITY
119+
$HOME/.avail/bin/avail-light --network $NETWORK --app-id $APPID --identity $IDENTITY
74120
elif [ -z "$config" ]; then
75-
$HOME/.availup/avail-light --network $NETWORK --app-id $APPID
121+
$HOME/.avail/bin/avail-light --network $NETWORK --app-id $APPID
76122
elif [ ! -z "$config" ] && [ ! -z "$identity" ]; then
77-
$HOME/.availup/avail-light --config $CONFIG --app-id $APPID --identity $IDENTITY
123+
$HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID --identity $IDENTITY
78124
else
79-
$HOME/.availup/avail-light --config $CONFIG --app-id $APPID
125+
$HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID
80126
fi
81127
exit 0
82128
fi
83129
if [ "$UPGRADE" = 1 ]; then
84130
echo "🔄 Upgrading Avail..."
85-
if [ -f "$HOME/.availup/avail-light" ]; then
86-
rm $HOME/.availup/avail-light
131+
if [ -f "$HOME/.avail/bin/avail-light" ]; then
132+
rm $HOME/.avail/bin/avail-light
87133
else
88134
echo "🤔 Avail was not installed with availup. Attemping to uninstall with cargo..."
89135
cargo uninstall avail-light || echo "👀 Avail was not installed with cargo, upgrade might not be required!"
@@ -131,21 +177,18 @@ else
131177
# use tar to extract the downloaded file and move it to /usr/local/bin
132178
tar -xzf avail-light-$ARCH_STRING.tar.gz
133179
chmod +x avail-light-$ARCH_STRING
134-
if [ ! -d "$HOME/.availup" ]; then
135-
mkdir $HOME/.availup
136-
fi
137-
mv avail-light-$ARCH_STRING $HOME/.availup/avail-light
180+
mv avail-light-$ARCH_STRING $HOME/.avail/bin/avail-light
138181
rm avail-light-$ARCH_STRING.tar.gz
139182
fi
140183
echo "✅ Availup exited successfully."
141184
echo "🧱 Starting Avail."
142185
trap onexit EXIT
143186
if [ -z "$config" ] && [ ! -z "$identity" ]; then
144-
$HOME/.availup/avail-light --network $NETWORK --app-id $APPID --identity $IDENTITY
187+
$HOME/.avail/bin/avail-light --network $NETWORK --app-id $APPID --identity $IDENTITY
145188
elif [ -z "$config" ]; then
146-
$HOME/.availup/avail-light --network $NETWORK --app-id $APPID
189+
$HOME/.avail/bin/avail-light --network $NETWORK --app-id $APPID
147190
elif [ ! -z "$config" ] && [ ! -z "$identity" ]; then
148-
$HOME/.availup/avail-light --config $CONFIG --app-id $APPID --identity $IDENTITY
191+
$HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID --identity $IDENTITY
149192
else
150-
$HOME/.availup/avail-light --config $CONFIG --app-id $APPID
193+
$HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID
151194
fi

0 commit comments

Comments
 (0)