forked from wasienv/wasienv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·135 lines (115 loc) · 4.43 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh
# This install script is intended to download and install the latest available
# release of wasienv.
# You can install using this script:
# $ curl https://raw.githubusercontent.com/wasienv/wasienv/master/install.sh | sh
set -e
reset="\033[0m"
blue="\033[44m"
m="\033[34;1m"
bold="\033[1m"
green="\033[32m"
red="\033[31m"
cyan="\033[36m"
white="\033[37m"
dim="\033[2m"
wasienv_detect_profile() {
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
echo "${PROFILE}"
return
fi
local DETECTED_PROFILE
DETECTED_PROFILE=''
local SHELLTYPE
SHELLTYPE="$(basename "/$SHELL")"
if [ "$SHELLTYPE" = "bash" ]; then
if [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
fi
elif [ "$SHELLTYPE" = "zsh" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
elif [ "$SHELLTYPE" = "fish" ]; then
DETECTED_PROFILE="$HOME/.config/fish/config.fish"
fi
if [ -z "$DETECTED_PROFILE" ]; then
if [ -f "$HOME/.profile" ]; then
DETECTED_PROFILE="$HOME/.profile"
elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
elif [ -f "$HOME/.config/fish/config.fish" ]; then
DETECTED_PROFILE="$HOME/.config/fish/config.fish"
fi
fi
if [ ! -z "$DETECTED_PROFILE" ]; then
echo "$DETECTED_PROFILE"
fi
}
wasienv_link() {
printf "${green}${bold}> Adding wasienv to bash profile...${reset}\n"
WASIENV_PROFILE="$(wasienv_detect_profile)"
LOAD_STR="\n# Wasienv\nexport WASIENV_DIR=\"$INSTALL_DIRECTORY\"\n[ -s \"\$WASIENV_DIR/wasienv.sh\" ] && source \"\$WASIENV_DIR/wasienv.sh\"\n"
SOURCE_STR="# Wasienv config\nexport WASIENV_DIR=\"$INSTALL_DIRECTORY\"\nexport PATH=\"\$WASIENV_DIR/bin:\$PATH\"\n"
# We create the wasienv.sh file
printf "$SOURCE_STR" > "$INSTALL_DIRECTORY/wasienv.sh"
if [ -z "${WASIENV_PROFILE-}" ] ; then
printf "${red}Profile not found. Tried:\n* ${WASIENV_PROFILE} (as defined in \$PROFILE)\n* ~/.bashrc\n* ~/.bash_profile\n* ~/.zshrc\n* ~/.profile.\n"
echo "\nHow to solve this issue?\n* Create one of them and run this script again"
echo "* Create it (touch ${WASIENV_PROFILE}) and run this script again"
echo " OR"
printf "* Append the following lines to the correct file yourself:$reset\n"
command printf "${SOURCE_STR}"
else
if ! grep -q 'wasienv.sh' "$WASIENV_PROFILE"; then
# if [[ $WASIENV_PROFILE = *"fish"* ]]; then
# command fish -c 'set -U fish_user_paths $fish_user_paths ~/.wasienv/bin'
# else
command printf "$LOAD_STR" >> "$WASIENV_PROFILE"
# fi
fi
printf "\033[1A${green}${bold}> Adding wasienv to bash profile... ✓${reset}\n"
version=`$INSTALL_DIRECTORY/bin/wasienv --version` || (
printf "$red> wasienv was installed, but doesn't seem to be working :($reset\n"
exit 1;
)
fi
}
if [ -z "$INSTALL_DIRECTORY" ]; then
if [ -z "$WASIENV_DIR" ]; then
# If WASMER_DIR is not present
INSTALL_DIRECTORY="$HOME/.wasienv"
else
# If WASMER_DIR is present
INSTALL_DIRECTORY="${WASIENV_DIR}"
fi
fi
echo "
${m}┏━━━━━━━━━┓${reset}
${m}┃ ┃${reset}
${m}┃ ${reset}${bold}wasi${m} (${reset} ${bold}env${reset}
${m}┃ ┃${reset}
${m}┗━━━━━━━━━┛${reset}
"
echo "${green}${bold}> Installing wasienv${reset}"
# Create wasienv directory
mkdir -p $INSTALL_DIRECTORY/bin
# Uninstall in case it exists
pip uninstall wasienv -y || true
# Install wasienv in the ~/.wasienv/bin directory
pip install wasienv --install-option="--install-scripts=$INSTALL_DIRECTORY/bin" --upgrade --user
wasienv_link
echo "\n${green}${bold}> Installing a WebAssembly WASI Runtime${reset}"
curl https://get.wasmer.io -sSfL | sh
echo "\n${green}${bold}> Installing the required WASI SDKs${reset}"
# unstable is the most stable version of the WASI sdk for now
$INSTALL_DIRECTORY/bin/wasienv install-sdk unstable
$INSTALL_DIRECTORY/bin/wasienv default-sdk unstable
printf "\n${reset}${dim}wasienv will be available the next time you open the terminal.\n"
printf "${reset}${dim}If you want to have the commands available now please execute:\n${reset}source $INSTALL_DIRECTORY/wasienv.sh$reset\n"
# Delete the variables from shell
unset -f wasienv_link wasienv_detect_profile