Skip to content

Commit

Permalink
feat: implement upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
QEDK committed Mar 7, 2024
1 parent fa4c0cc commit cc3cba2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
identity.toml
avail_path
52 changes: 36 additions & 16 deletions availup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ elif [ -f "$HOME/.zshrc" ]; then
elif [ -f "$HOME/.kshrc" ]; then
PROFILE="$HOME/.kshrc"
else
echo "🫣 Unable to locate a profile, availup might not work as intended!"
echo "🫣 Unable to locate a shell rc file, using POSIX default, availup might not work as intended!"
PROFILE="/etc/profile"
fi
if [ -z "$network" ]; then
echo "ℹ️ No network selected. Defaulting to goldberg."
echo "🛜 No network selected. Defaulting to goldberg."
NETWORK="goldberg"
else
NETWORK="$network"
Expand All @@ -38,40 +38,56 @@ else
exit 1
fi
if [ -z "$app_id" ]; then
echo "ℹ️ No app ID specified. Defaulting to 0."
echo "📲 No app ID specified. Defaulting to 0."
APPID="0"
else
APPID="$app_id"
fi
if [ ! -d "$HOME/.avail-light" ]; then
mkdir $HOME/.avail-light
fi
if [ ! -d "$HOME/.avail-light/$NETWORK" ]; then
mkdir $HOME/.avail-light/$NETWORK
if [ -z "$identity" ]; then
echo "🤷 No identity set. This will be automatically generated at startup."
else
IDENTITY="$identity"
fi
if [ -z "$config" ]; then
echo "ℹ️ No config file selected. Defaulting to $NETWORK config..."
if [ "$upgrade" == "y" ] || [ "$upgrade" == "yes" ]; then
UPGRADE=1
else
CONFIG=$config
UPGRADE=0
fi
onexit() {
echo "🔄 Avail stopped. Future instances of the light client can be started by invoking the avail-light binary directly$EXTRAPROMPT"
if [[ ":$PATH:" != *":$HOME/.availup:"* ]]; then
echo "📌 Adding Avail to your path. Please run the following command to load it in the current terminal session:\nsource $PROFILE"
echo "export PATH=\$PATH:$HOME/.availup" >> $PROFILE
echo "\nexport PATH=\$PATH:$HOME/.availup" >> $PROFILE
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"
fi
exit 0
}
if command -v avail-light >/dev/null 2>&1; then
if [ command -v avail-light >/dev/null 2>&1 ] && [ "$UPGRADE" = 0 ]; then
echo "✅ Avail is already installed. Starting Avail..."
trap onexit EXIT
if [ -z "$config" ]; then
if [ -z "$config" ] && [ ! -z "$identity" ]; then
$HOME/.availup/avail-light --network $NETWORK --app-id $APPID --identity $IDENTITY
elif [ -z "$config" ]; then
$HOME/.availup/avail-light --network $NETWORK --app-id $APPID
elif [ ! -z "$config" ] && [ ! -z "$identity" ]; then
$HOME/.availup/avail-light --config $CONFIG --app-id $APPID --identity $IDENTITY
else
$HOME/.availup/avail-light --config $CONFIG --app-id $APPID
fi
exit 0
fi
if [ "$UPGRADE" = 1 ]; then
echo "🔄 Upgrading Avail. This step might prompt for a password."
if [ -f "$HOME/.availup/avail-light" ]; then
sudo rm $HOME/.availup/avail-light
else
echo "🤔 Avail was not installed with availup. Attemping to uninstall with cargo..."
cargo uninstall avail-light
if command -v avail-light >/dev/null 2>&1; then
echo "🚫 Avail was not uninstalled. Please uninstall manually and try again."
exit 1
fi
fi
fi
if [ "$(uname -m)" = "x86_64" ]; then
ARCH_STRING="linux-amd64"
elif [ "$(uname -m)" = "arm64" -a "$(uname -s)" = "Darwin" ]; then
Expand Down Expand Up @@ -119,8 +135,12 @@ fi
echo "✅ Availup exited successfully."
echo "🧱 Starting Avail."
trap onexit EXIT
if [ -z "$config" ]; then
if [ -z "$config" ] && [ ! -z "$identity" ]; then
$HOME/.availup/avail-light --network $NETWORK --app-id $APPID --identity $IDENTITY
elif [ -z "$config" ]; then
$HOME/.availup/avail-light --network $NETWORK --app-id $APPID
elif [ ! -z "$config" ] && [ ! -z "$identity" ]; then
$HOME/.availup/avail-light --config $CONFIG --app-id $APPID --identity $IDENTITY
else
$HOME/.availup/avail-light --config $CONFIG --app-id $APPID
fi

0 comments on commit cc3cba2

Please sign in to comment.