-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
94 lines (82 loc) · 2.14 KB
/
setup.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
#!/bin/sh
origin_dir=`pwd`
mkdir -p ~/.zkm-toolchain
cd ~/.zkm-toolchain
cleanup() {
cd ${origin_dir}
}
trap cleanup EXIT
setpath() {
local newpath=`readlink -f ~/.zkm-toolchain/$1/bin`
echo "export PATH=$newpath:\$PATH" > ~/.zkm-toolchain/env
local q=`readlink -f ~/.zkm-toolchain/`
split_path=`echo $PATH | sed 's/:/ /g'`
for e in ${split_path};do
xxx=`echo $e | grep "^$q"`
if [ -n "$xxx" ];then
continue
fi
newpath="$newpath:$e"
done
export PATH=$newpath
}
os=`uname`
cpu=`uname -m`
reinstall=no
update=no
pkg="rust-toolchain"
rel=20241217
for i in $@;do
if [ "$i" = "--reinstall" ];then
reinstall=yes
continue
fi
if [ "$i" = "--update" ];then
update=yes
continue
fi
done
if [ "$update" = "yes" ];then
rel=`curl -s https://api.github.com/repos/zkMIPS/toolchain/releases | grep '"tag_name":' | sed 's/[^0-9]*//g' | sort -r | head -1`
if [ -z "$rel" ];then
echo "Failed to get release list from github"
exit 1
fi
fi
if [ "${os}-${cpu}" = "Linux-aarch64" ];then
pkg="${pkg}-aarch64-unknown-linux-gnu-${rel}.tar.xz"
elif [ "${os}-${cpu}" = "Linux-x86_64" ];then
pkg="${pkg}-x86-64-unknown-linux-gnu-${rel}.tar.xz"
elif [ "${os}-${cpu}" = "Darwin-arm64" ];then
pkg="${pkg}-aarch64-apple-darwin-${rel}.tar.bz2"
elif [ "${os}-${cpu}" = "Darwin-x86_64" ];then
pkg="${pkg}-x86-64-apple-darwin-${rel}.tar.bz2"
else
echo -n "Unsupported Platform: "
uname -a
exit 1
fi
dir=`echo $pkg | sed 's/.tar.*//'`
if [ ! -d "$dir" ] || [ "$reinstall" = "yes" ] ;then
if [ -e "$dir" ] && [ ! -d "$dir" ];then
echo "Error: $dir exists, while is not a diretory"
exit 1
fi
echo "Downloading... $pkg ..."
wget -c https://github.com/zkMIPS/toolchain/releases/download/$rel/$pkg -O ~/.zkm-toolchain/$pkg
tar xf $pkg
fi
echo_e=`echo -e`
echo_e_opt=-e
if [ "$echo_e" = "-e" ];then
echo_e_opt=
fi
if [ -d "$dir" ]; then
setpath $dir
echo ${echo_e_opt} "'\033[0;31m~/.zkm-toolcain/env\033[0m' created. Now you can add"
echo ${echo_e_opt} "\033[0;32m . ~/.zkm-toolchain/env\033[0m"
echo ${echo_e_opt} "to your .bashrc/.zshrc/.profile to use zkMIPS toolchain"
echo ${echo_e_opt} "Starting a new shell session..."
cd ${origin_dir}
$SHELL
fi