Skip to content

Commit cebdc64

Browse files
committed
feat: fix path detection and profile modificaation
1 parent a4ac7bf commit cebdc64

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

availup.sh

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,35 @@ else
4141
PROFILE="/etc/profile"
4242
fi
4343
if [ -z "$network" ]; then
44-
echo "🛜 No network selected. Defaulting to goldberg."
44+
echo "🛜 No network selected. Defaulting to goldberg testnet."
4545
NETWORK="goldberg"
4646
else
4747
NETWORK="$network"
4848
fi
4949
if [ "$NETWORK" = "goldberg" ]; then
50-
echo "📌 Goldberg network selected."
50+
echo "📌 Goldberg testnet selected."
5151
VERSION="v1.7.9"
5252
elif [ "$NETWORK" = "local" ]; then
53-
echo "📌 Local network selected."
53+
echo "📌 Local testnet selected."
5454
VERSION="v1.7.9"
5555
else
56-
echo "🚫 Invalid network selected. Please select one of the following: goldberg, kate, local."
56+
echo "🚫 Invalid network selected. Select one of the following: goldberg, local."
5757
exit 1
5858
fi
5959
if [ -z "$app_id" ]; then
60-
echo "📲 No app ID specified. Defaulting to 0."
60+
echo "📲 No app ID specified. Defaulting to light client mode."
6161
APPID="0"
6262
else
6363
APPID="$app_id"
6464
fi
6565
if [ -z "$identity" ]; then
6666
IDENTITY=$HOME/.avail/identity/identity.toml
67-
if [ -f "$HOME/.avail/identity/identity.toml" ]; then
67+
if [ -f "$IDENTITY" ]; then
6868
echo "🔑 Identity found at $IDENTITY."
6969
else
7070
echo "🤷 No identity set. This will be automatically generated at startup."
7171
fi
72-
else
72+
else
7373
IDENTITY="$identity"
7474
fi
7575
if [ ! -d "$HOME/.avail" ]; then
@@ -85,44 +85,41 @@ fi
8585
UPGRADE=0
8686
if [ ! -z "$upgrade" ]; then
8787
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)"
88+
if [ -f $HOME/.avail/bin/avail-light ]; then
89+
CURRENT_VERSION="v$($HOME/.avail/bin/avail-light --version | cut -d " " -f 2)"
9090
if [ "$CURRENT_VERSION" = "v1.7.8" ] && [ "$VERSION" = "v1.7.9" ]; then
9191
UPGRADE=0
9292
echo "✨ Avail binary is up to date. Skipping upgrade."
9393
elif [ "$CURRENT_VERSION" != "$VERSION" ]; then
9494
UPGRADE=1
9595
echo "✨ Avail binary is up to date. Skipping upgrade."
9696
else
97-
if [ "$upgrade" = "y" ] || [ "$upgrade" = "yes" ]; then
97+
if [ "$upgrade" = "y" -o "$upgrade" = "yes" ]; then
9898
UPGRADE=1
9999
fi
100100
fi
101101
fi
102102
fi
103103

104104
onexit() {
105+
chmod 600 $IDENTITY
105106
echo "🔄 Avail stopped. Future instances of the light client can be started by invoking the avail-light binary or rerunning this script$EXTRAPROMPT"
106107
if [[ ":$PATH:" != *":$HOME/.avail/bin:"* ]]; then
107108
if ! grep -q "export PATH=\"\$PATH:$HOME/.avail/bin\"" "$PROFILE"; then
108109
echo -e "export PATH=\"\$PATH:$HOME/.avail/bin\"\n" >> $PROFILE
109110
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"
111+
echo -e "📌 Avail has been added to your profile. Run the following command to load it in the current session:\n. $PROFILE\n"
111112
fi
112113
exit 0
113114
}
114115
# 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
116+
if [ -f $HOME/.avail/bin/avail-light -a "$UPGRADE" = 0 ]; then
116117
echo "✅ Avail is already installed. Starting Avail..."
117118
trap onexit EXIT
118-
if [ -z "$config" ] && [ ! -z "$identity" ]; then
119+
if [ -z "$config" ]; then
119120
$HOME/.avail/bin/avail-light --network $NETWORK --app-id $APPID --identity $IDENTITY
120-
elif [ -z "$config" ]; then
121-
$HOME/.avail/bin/avail-light --network $NETWORK --app-id $APPID
122-
elif [ ! -z "$config" ] && [ ! -z "$identity" ]; then
123-
$HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID --identity $IDENTITY
124121
else
125-
$HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID
122+
$HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID --identity $IDENTITY
126123
fi
127124
exit 0
128125
fi
@@ -174,7 +171,7 @@ else
174171
echo "🚫 Neither curl nor wget are available. Please install one of these and try again."
175172
exit 1
176173
fi
177-
# use tar to extract the downloaded file and move it to /usr/local/bin
174+
# use tar to extract the downloaded file and move it to .avail/bin/ directory
178175
tar -xzf avail-light-$ARCH_STRING.tar.gz
179176
chmod +x avail-light-$ARCH_STRING
180177
mv avail-light-$ARCH_STRING $HOME/.avail/bin/avail-light
@@ -183,12 +180,8 @@ fi
183180
echo "✅ Availup exited successfully."
184181
echo "🧱 Starting Avail."
185182
trap onexit EXIT
186-
if [ -z "$config" ] && [ ! -z "$identity" ]; then
183+
if [ -z "$config" ]; then
187184
$HOME/.avail/bin/avail-light --network $NETWORK --app-id $APPID --identity $IDENTITY
188-
elif [ -z "$config" ]; then
189-
$HOME/.avail/bin/avail-light --network $NETWORK --app-id $APPID
190-
elif [ ! -z "$config" ] && [ ! -z "$identity" ]; then
191-
$HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID --identity $IDENTITY
192185
else
193-
$HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID
186+
$HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID --identity $IDENTITY
194187
fi

0 commit comments

Comments
 (0)