|
1 | | -#!/usr/bin/env sh |
| 1 | +#!/usr/bin/env bash |
2 | 2 | echo "🆙 Starting Availup..." |
3 | 3 | while [ $# -gt 0 ]; do |
4 | | - if [[ $1 == "--"* ]]; then |
| 4 | + if [[ $1 = "--"* ]]; then |
5 | 5 | v="${1/--/}" |
6 | 6 | declare "$v"="$2" |
7 | 7 | shift |
8 | 8 | fi |
9 | 9 | shift |
10 | 10 | 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 |
12 | 22 | 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 |
14 | 26 | 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 |
17 | 39 | 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!" |
19 | 41 | PROFILE="/etc/profile" |
20 | 42 | fi |
21 | 43 | if [ -z "$network" ]; then |
|
27 | 49 | if [ "$NETWORK" = "goldberg" ]; then |
28 | 50 | echo "📌 Goldberg network selected." |
29 | 51 | VERSION="v1.7.9" |
30 | | -elif [ "$NETWORK" = "kate" ]; then |
31 | | - echo "📌 Kate network selected." |
32 | | - VERSION="v1.7.9" |
33 | 52 | elif [ "$NETWORK" = "local" ]; then |
34 | 53 | echo "📌 Local network selected." |
35 | 54 | VERSION="v1.7.9" |
|
44 | 63 | APPID="$app_id" |
45 | 64 | fi |
46 | 65 | 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 |
49 | 68 | echo "🔑 Identity found at $IDENTITY." |
50 | 69 | else |
51 | 70 | echo "🤷 No identity set. This will be automatically generated at startup." |
52 | 71 | fi |
53 | 72 | else |
54 | 73 | IDENTITY="$identity" |
55 | 74 | 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 |
60 | 102 | fi |
| 103 | + |
61 | 104 | 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" |
66 | 111 | fi |
67 | 112 | exit 0 |
68 | 113 | } |
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 |
70 | 116 | echo "✅ Avail is already installed. Starting Avail..." |
71 | 117 | trap onexit EXIT |
72 | 118 | 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 |
74 | 120 | 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 |
76 | 122 | 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 |
78 | 124 | else |
79 | | - $HOME/.availup/avail-light --config $CONFIG --app-id $APPID |
| 125 | + $HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID |
80 | 126 | fi |
81 | 127 | exit 0 |
82 | 128 | fi |
83 | 129 | if [ "$UPGRADE" = 1 ]; then |
84 | 130 | 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 |
87 | 133 | else |
88 | 134 | echo "🤔 Avail was not installed with availup. Attemping to uninstall with cargo..." |
89 | 135 | cargo uninstall avail-light || echo "👀 Avail was not installed with cargo, upgrade might not be required!" |
@@ -131,21 +177,18 @@ else |
131 | 177 | # use tar to extract the downloaded file and move it to /usr/local/bin |
132 | 178 | tar -xzf avail-light-$ARCH_STRING.tar.gz |
133 | 179 | 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 |
138 | 181 | rm avail-light-$ARCH_STRING.tar.gz |
139 | 182 | fi |
140 | 183 | echo "✅ Availup exited successfully." |
141 | 184 | echo "🧱 Starting Avail." |
142 | 185 | trap onexit EXIT |
143 | 186 | 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 |
145 | 188 | 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 |
147 | 190 | 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 |
149 | 192 | else |
150 | | - $HOME/.availup/avail-light --config $CONFIG --app-id $APPID |
| 193 | + $HOME/.avail/bin/avail-light --config $CONFIG --app-id $APPID |
151 | 194 | fi |
0 commit comments