Skip to content

Commit 102f1d7

Browse files
committed
install rust
1 parent 7fad387 commit 102f1d7

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

install_prerequisite.sh

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ GOTTY_DIR=/opt/gotty
66
mkdir -p $GOTTY_DIR || true
77
chmod -R 644 $GOTTY_DIR
88
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
9-
echo "running script from : " $SCRIPT_DIR
109

1110
retVal=0
1211

@@ -16,24 +15,38 @@ display_usage() {
1615
echo " --cleanup-tools Cleanup tools after REPLs installation"
1716
echo " --run-tests Run tests"
1817
echo " --help Display this help message"
18+
echo " --username USERNAME Specify the username for installation"
1919
}
2020

2121
cleanup_tools=0
2222
run_tests=0
23-
24-
for arg in "$@"; do
25-
case $arg in
26-
--cleanup-tools) cleanup_tools=1
27-
;;
28-
--run-tests) run_tests=1
29-
;;
30-
--help) display_usage; exit 0
31-
;;
32-
*) echo "Invalid argument: $arg"; display_usage; exit 1
33-
;;
23+
username=$(whoami)
24+
25+
# Parse command-line arguments
26+
while [[ "$#" -gt 0 ]]; do
27+
case $1 in
28+
--cleanup-tools) cleanup_tools=1; shift ;;
29+
--run-tests) run_tests=1; shift ;;
30+
--help) display_usage; exit 0 ;;
31+
--username)
32+
if [[ -n "$2" && "$2" != --* ]]; then
33+
username="$2"; shift 2
34+
else
35+
echo "Error: --username requires a value"
36+
display_usage
37+
exit 1
38+
fi
39+
;;
40+
*)
41+
echo "Invalid argument: $1"
42+
display_usage
43+
exit 1
44+
;;
3445
esac
3546
done
3647

48+
echo "running script from : " $SCRIPT_DIR
49+
echo "username: " $username
3750

3851
cd ~
3952

@@ -95,7 +108,7 @@ npm install npm@8.5.1 -g
95108
#/usr/bin/cling 21321 .q > /dev/null 2>&1 &
96109
cd $GOTTY_DIR
97110

98-
if [[ -e "/usr/local/bin/cling" ]]; then
111+
if [ -e "/usr/local/bin/cling" ]; then
99112
echo "File /usr/local/bin/cling exists."
100113
else
101114
echo "File /usr/local/bin/cling does not exist. installing..."
@@ -107,6 +120,24 @@ else
107120
rm cling-Ubuntu-22.04-x86_64-1.0~dev-d47b49c.tar.bz2
108121
fi
109122

123+
#install rust and set all the required env
124+
RUSTUP_HOME="$GOTTY_DIR/rust"
125+
CARGO_HOME="$GOTTY_DIR/rust"
126+
if [ -e "$RUSTUP_HOME/bin/rustc" ]; then
127+
echo "File $RUSTUP_HOME/bin/rustc exists."
128+
else
129+
echo "File $RUSTUP_HOME/bin/rustc does not exist. installing..."
130+
mkdir -p $RUSTUP_HOME
131+
curl https://sh.rustup.rs -sSf | env RUSTUP_HOME=$RUSTUP_HOME CARGO_HOME=$CARGO_HOME sh -s -- --default-toolchain stable --profile default -y
132+
echo "export RUSTUP_HOME=$RUSTUP_HOME" | tee /etc/profile.d/rust.sh
133+
echo "export CARGO_HOME=$CARGO_HOME" | tee -a /etc/profile.d/rust.sh
134+
echo "export PATH=\$PATH:\$RUSTUP_HOME/bin" | tee -a /etc/profile.d/rust.sh
135+
chmod +x /etc/profile.d/rust.sh
136+
bash -c 'echo "if [ -f /etc/profile.d/rust.sh ]; then . /etc/profile.d/rust.sh; fi" >> /etc/bash.bashrc'
137+
bash -c 'echo "if [ -f /etc/profile.d/rust.sh ]; then . /etc/profile.d/rust.sh; fi" >> /etc/profile'
138+
fi
139+
140+
110141

111142
#install gointerpreter
112143
git clone https://github.com/vickeykumar/Go-interpreter.git
@@ -165,6 +196,9 @@ if [ $cleanup_tools -eq 1 ]; then
165196
apt-get -y autoremove
166197
fi
167198

199+
# finally give the ownership to username
200+
chown -R $username:$username $GOTTY_DIR
201+
168202
#test
169203
if [ $run_tests -eq 1 ]; then
170204
test_commands=(
@@ -187,6 +221,8 @@ if [ $run_tests -eq 1 ]; then
187221
"gdb --version"
188222
"jq --version"
189223
"echo 'puts [info patchlevel]' | tclsh"
224+
"rustc --version"
225+
"rust-gdb --version"
190226
)
191227

192228

0 commit comments

Comments
 (0)