#!/usr/bin/env bash echo "šŸ†™ Starting Availup..." while [ $# -gt 0 ]; do if [[ $1 = "--"* ]]; then v="${1/--/}" declare "$v"="$2" shift fi shift done # generate folders if missing if [ ! -d "$HOME/.avail" ]; then mkdir $HOME/.avail fi if [ ! -d "$HOME/.avail/identity" ]; then mkdir $HOME/.avail/identity fi # check if bash is current terminal shell, else check for zsh if [ -z "$BASH_VERSION" ]; then if [ -z "$ZSH_VERSION" ]; then echo "šŸš« Unable to locate a shell. Availup might not work as intended!" else CURRENT_TERM="zsh" fi else CURRENT_TERM="bash" fi if [ "$CURRENT_TERM" = "bash" -a -f "$HOME/.bashrc" ]; then PROFILE="$HOME/.bashrc" elif [ "$CURRENT_TERM" = "bash" -a -f "$HOME/.bash_profile" ]; then PROFILE="$HOME/.bash_profile" elif [ "$CURRENT_TERM" = "bash" -a -f "$HOME/.zshrc" ]; then PROFILE="$HOME/.zshrc" elif [ "$CURRENT_TERM" = "bash" -a -f "$HOME/.zsh_profile" ]; then PROFILE="$HOME/.zsh_profile" elif [ "$CURRENT_TERM" = "zsh" -a -f "$HOME/.zshrc" ]; then PROFILE="$HOME/.zshrc" elif [ "$CURRENT_TERM" = "zsh" -a -f "$HOME/.zsh_profile" ]; then PROFILE="$HOME/.zsh_profile" elif [ "$CURRENT_TERM" = "bash" ]; then PROFILE="$HOME/.bashrc" touch $HOME/.bashrc elif [ "$CURRENT_TERM" = "zsh" ]; then PROFILE="$HOME/.zshrc" touch $HOME/.zshrc else echo "šŸ«£ Unable to locate a compatible shell or 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 mainnet." NETWORK="mainnet" else NETWORK="$network" fi UPGRADE=0 if [ "$NETWORK" = "mainnet" ]; then echo "šŸ“Œ Mainnet selected." elif [ "$NETWORK" = "turing" ]; then echo "šŸ“Œ Turing testnet selected." elif [ "$NETWORK" = "local" ]; then echo "šŸ“Œ Local testnet selected." fi TURING_CONFIG_PARAMS="bootstraps=['/dns/bootnode.1.lightclient.turing.avail.so/tcp/37000/p2p/12D3KooWBkLsNGaD3SpMaRWtAmWVuiZg1afdNSPbtJ8M8r9ArGRT']\nfull_node_ws=['wss://turing-rpc.avail.so/ws','wss://avail-turing.public.blastapi.io','wss://turing-testnet.avail-rpc.com']\nconfidence=80.0\navail_path='$HOME/.avail/$NETWORK/data'\nkad_record_ttl=43200\not_collector_endpoint='http://otel.lightclient.turing.avail.so:4317'\ngenesis_hash='d3d2f3a3495dc597434a99d7d449ebad6616db45e4e4f178f31cc6fa14378b70'\n" MAINNET_CONFIG_PARAMS="bootstraps=['/dns/bootnode.1.lightclient.mainnet.avail.so/tcp/37000/p2p/12D3KooW9x9qnoXhkHAjdNFu92kMvBRSiFBMAoC5NnifgzXjsuiM']\nfull_node_ws=['wss://mainnet-rpc.avail.so/ws','wss://mainnet.avail-rpc.com','wss://avail-mainnet.public.blastapi.io']\nconfidence=80.0\navail_path='$HOME/.avail/$NETWORK/data'\nkad_record_ttl=43200\ngenesis_hash='b91746b45e0346cc2f815a520b9c6cb4d5c0902af848db0a80f85932d2e8276a'\not_collector_endpoint='http://otel.lightclient.mainnet.avail.so:4317'\n" AVAIL_BIN=$HOME/.avail/$NETWORK/bin/avail-light if [ ! -d "$HOME/.avail/$NETWORK" ]; then mkdir $HOME/.avail/$NETWORK fi if [ ! -d "$HOME/.avail/$NETWORK/bin" ]; then mkdir $HOME/.avail/$NETWORK/bin fi if [ ! -d "$HOME/.avail/$NETWORK/data" ]; then mkdir $HOME/.avail/$NETWORK/data fi if [ ! -d "$HOME/.avail/$NETWORK/config" ]; then mkdir $HOME/.avail/$NETWORK/config fi readonly MAINNET_VERSION="avail-light-client-v1.12.0-rc2" readonly TURING_VERSION="avail-light-client-v1.12.0-rc2" readonly LOCAL_VERSION="avail-light-client-v1.12.0-rc2" if [ "$NETWORK" = "mainnet" ]; then VERSION=$MAINNET_VERSION if [ -z "$config" ]; then CONFIG="$HOME/.avail/$NETWORK/config/config.yml" if [ -f "$CONFIG" ]; then echo "šŸ—‘ļø Wiping old config file at $CONFIG." rm $CONFIG else echo "šŸ¤· No configuration file set. This will be automatically generated at startup." fi touch $CONFIG echo -e $MAINNET_CONFIG_PARAMS >>$CONFIG else CONFIG="$config" fi elif [ "$NETWORK" = "turing" ]; then VERSION=$TURING_VERSION if [ -z "$config" ]; then CONFIG="$HOME/.avail/$NETWORK/config/config.yml" if [ -f "$CONFIG" ]; then echo "šŸ—‘ļø Wiping old config file at $CONFIG." rm $CONFIG else echo "šŸ¤· No configuration file set. This will be automatically generated at startup." fi touch $CONFIG echo -e $TURING_CONFIG_PARAMS >>$CONFIG else CONFIG="$config" fi elif [ "$NETWORK" = "local" ]; then echo "šŸ“Œ Local testnet selected." VERSION=$LOCAL_VERSION if [ -z "$config" ]; then echo "šŸš« No configuration file was provided for local testnet, exiting." exit 1 fi else echo "šŸš« Invalid network selected. Select one of the following: turing, local." exit 1 fi if [ -z "$app_id" ]; then echo "šŸ“² No app ID specified. Defaulting to light client mode." else APPID="$app_id" fi if [ -z "$identity" ]; then IDENTITY=$HOME/.avail/identity/identity.toml if [ -f "$IDENTITY" ]; then echo "šŸ”‘ Identity found at $IDENTITY." else echo "šŸ¤· No identity set. This will be automatically generated at startup." fi else IDENTITY="$identity" fi # handle WSL systems if uname -r | grep -qEi "(Microsoft|WSL)"; then # force remove IO lock if [ -d "$HOME/.avail/$NETWORK/data" ]; then rm -rf $HOME/.avail/$NETWORK/data mkdir $HOME/.avail/$NETWORK/data fi if [ "$force_wsl" != 'y' -a "$force_wsl" != 'yes' ]; then echo "šŸ‘€ WSL detected. This script is not fully compatible with WSL. Please download the Windows runner instead by clicking this link: https://github.com/availproject/avail-light/releases/download/$VERSION/avail-light-windows-runner.zip Alternatively, rerun the command with --force_wsl y" exit 1 else echo "šŸ‘€ WSL detected. The binary is not fully compatible with WSL but forcing the run anyway." fi fi # check if avail-light version matches! if [ ! -z "$upgrade" ] || [ "$UPGRADE" = 1 ]; then echo "šŸ”„ Checking for updates..." if [ -f $AVAIL_BIN ]; then CURRENT_VERSION="v$($HOME/.avail/$NETWORK/bin/avail-light --version | cut -d " " -f 2)" if [ "$CURRENT_VERSION" != "$VERSION" ]; then UPGRADE=1 echo "ā¬†ļø Avail binary is out of date. Upgrading..." else echo "āœ… Avail binary is up to date." if [ "$upgrade" = "y" -o "$upgrade" = "yes" ]; then UPGRADE=1 fi fi fi else if [ -f $AVAIL_BIN ]; then CURRENT_VERSION="v$($HOME/.avail/$NETWORK/bin/avail-light --version | cut -d " " -f 2)" if [ "$CURRENT_VERSION" = "$VERSION" ]; then UPGRADE=1 echo "ā¬†ļø Avail binary is out of date. Upgrading..." fi fi fi onexit() { chmod 600 $IDENTITY echo "šŸ”„ Avail stopped. Future instances of the light client can be started by invoking the avail-light binary or rerunning this script$EXTRAPROMPT" if [[ ":$PATH:" != *":$HOME/.avail/$NETWORK/bin:"* ]]; then if ! grep -q "export PATH=\"\$PATH:$HOME/.avail/$NETWORK/bin\"" "$PROFILE"; then echo -e "export PATH=\"\$PATH:$HOME/.avail/$NETWORK/bin\"\n" >>$PROFILE fi echo -e "šŸ“Œ Avail has been added to your profile. Run the following command to load it in the current session:\n. $PROFILE\n" fi exit 0 } run_binary() { trap onexit EXIT if [ -z "$APPID" ]; then $AVAIL_BIN --config $CONFIG --identity $IDENTITY else $AVAIL_BIN --config $CONFIG --app-id $APPID --identity $IDENTITY fi exit 0 } # check if avail-light binary is available and check if upgrade variable is set to 0 if [ -f $AVAIL_BIN -a "$UPGRADE" = 0 ]; then echo "āœ… Avail is already installed. Starting Avail..." trap onexit EXIT run_binary fi if [ "$UPGRADE" = 1 ]; then echo "šŸ”„ Resetting configuration and data..." if [ -f $AVAIL_BIN ]; then rm $AVAIL_BIN if [ -f $CONFIG ]; then rm $CONFIG touch $CONFIG if [ "$NETWORK" = "turing" ]; then echo -e $TURING_CONFIG_PARAMS >>$CONFIG fi fi if [ -d "$HOME/.avail/$NETWORK/data" ]; then rm -rf $HOME/.avail/$NETWORK/data mkdir $HOME/.avail/$NETWORK/data fi else echo "šŸ¤” Avail was not installed with availup. Attemping to uninstall with cargo..." cargo uninstall avail-light || echo "šŸ‘€ Avail was not installed with cargo, upgrade might not be required!" 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)" = "arm64" -a "$(uname -s)" = "Darwin" ]; then ARCH_STRING="apple-arm64" elif [ "$(uname -m)" = "x86_64" -a "$(uname -s)" = "Darwin" ]; then ARCH_STRING="apple-x86_64" elif [ "$(uname -m)" = "aarch64" -o "$(uname -m)" = "arm64" ]; then ARCH_STRING="linux-arm64" elif [ "$(uname -m)" = "x86_64" ]; then ARCH_STRING="linux-amd64" fi if [ -z "$ARCH_STRING" ]; then echo "šŸ“„ No binary available for this architecture, building from source instead. This can take a while..." # check if cargo is not available, else attempt to install through rustup if command -v cargo >/dev/null 2>&1; then echo "šŸ“¦ Cargo is available. Building from source..." else echo "šŸ‘€ Cargo is not available. Attempting to install with Rustup..." curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y EXTRAPROMPT="\nā„¹ļø Cargo env needs to be loaded by running source \$HOME/.cargo/env" echo "šŸ“¦ Cargo is now available. Reattempting to build from source..." fi # check if avail-light folder exists in home directory, if yes, pull latest changes, else clone the repo AVAIL_LIGHT_DIR=$HOME/avail-light if [ -d $AVAIL_LIGHT_DIR ]; then echo "šŸ”„ Updating avail-light repository and building..." cd $AVAIL_LIGHT_DIR git pull -q origin $VERSION git checkout -q $VERSION cargo build --release cp $AVAIL_LIGHT_DIR/target/release/avail-light $AVAIL_BIN else echo "šŸ“‚ Cloning avail-light repository and building..." git clone -q -c advice.detachedHead=false --depth=1 --single-branch --branch $VERSION https://github.com/availproject/avail-light.git $AVAIL_LIGHT_DIR cd $AVAIL_LIGHT_DIR cargo build --release mv $AVAIL_LIGHT_DIR/target/release/avail-light $AVAIL_BIN rm -rf $AVAIL_LIGHT_DIR fi else if command -v curl >/dev/null 2>&1; then curl -sLO https://github.com/availproject/avail-light/releases/download/$VERSION/avail-light-$ARCH_STRING.tar.gz elif command -v wget >/dev/null 2>&1; then wget -qO- https://github.com/availproject/avail-light/releases/download/$VERSION/avail-light-$ARCH_STRING.tar.gz else echo "šŸš« Neither curl nor wget are available. Please install one of these and try again." exit 1 fi # use tar to extract the downloaded file and move it to .avail/bin/ directory tar -xzf avail-light-$ARCH_STRING.tar.gz chmod +x avail-light-$ARCH_STRING mv avail-light-$ARCH_STRING $AVAIL_BIN rm avail-light-$ARCH_STRING.tar.gz fi echo "āœ… Availup exited successfully." echo "šŸ§± Starting Avail." run_binary