diff --git a/install_prerequisite.sh b/install_prerequisite.sh index d59c9666..988e5d1b 100755 --- a/install_prerequisite.sh +++ b/install_prerequisite.sh @@ -16,21 +16,33 @@ display_usage() { echo " --cleanup-tools Cleanup tools after REPLs installation" echo " --run-tests Run tests" echo " --help Display this help message" + echo " --username USERNAME Specify the username for installation" } cleanup_tools=0 run_tests=0 - -for arg in "$@"; do - case $arg in - --cleanup-tools) cleanup_tools=1 - ;; - --run-tests) run_tests=1 - ;; - --help) display_usage; exit 0 - ;; - *) echo "Invalid argument: $arg"; display_usage; exit 1 - ;; +username=$(whoami) + +# Parse command-line arguments +while [[ "$#" -gt 0 ]]; do + case $1 in + --cleanup-tools) cleanup_tools=1; shift ;; + --run-tests) run_tests=1; shift ;; + --help) display_usage; exit 0 ;; + --username) + if [[ -n "$2" && "$2" != --* ]]; then + username="$2"; shift 2 + else + echo "Error: --username requires a value" + display_usage + exit 1 + fi + ;; + *) + echo "Invalid argument: $1" + display_usage + exit 1 + ;; esac done @@ -95,7 +107,7 @@ npm install npm@8.5.1 -g #/usr/bin/cling 21321 .q > /dev/null 2>&1 & cd $GOTTY_DIR -if [[ -e "/usr/local/bin/cling" ]]; then +if [ -e "/usr/local/bin/cling" ]; then echo "File /usr/local/bin/cling exists." else echo "File /usr/local/bin/cling does not exist. installing..." @@ -107,6 +119,24 @@ else rm cling-Ubuntu-22.04-x86_64-1.0~dev-d47b49c.tar.bz2 fi +#install rust and set all the required env +RUSTUP_HOME="$GOTTY_DIR/rust" +CARGO_HOME="$GOTTY_DIR/rust" +if [ -e "$RUSTUP_HOME/bin/rustc" ]; then + echo "File $RUSTUP_HOME/bin/rustc exists." +else + echo "File $RUSTUP_HOME/bin/rustc does not exist. installing..." + mkdir -p $RUSTUP_HOME + curl https://sh.rustup.rs -sSf | env RUSTUP_HOME=$RUSTUP_HOME CARGO_HOME=$CARGO_HOME sh -s -- --default-toolchain stable --profile default -y + echo "export RUSTUP_HOME=$RUSTUP_HOME" | tee /etc/profile.d/rust.sh + echo "export CARGO_HOME=$CARGO_HOME" | tee -a /etc/profile.d/rust.sh + echo "export PATH=\$PATH:\$RUSTUP_HOME/bin" | tee -a /etc/profile.d/rust.sh + chmod +x /etc/profile.d/rust.sh + bash -c 'echo "if [ -f /etc/profile.d/rust.sh ]; then . /etc/profile.d/rust.sh; fi" >> /etc/bash.bashrc' + bash -c 'echo "if [ -f /etc/profile.d/rust.sh ]; then . /etc/profile.d/rust.sh; fi" >> /etc/profile' +fi + + #install gointerpreter git clone https://github.com/vickeykumar/Go-interpreter.git @@ -165,6 +195,9 @@ if [ $cleanup_tools -eq 1 ]; then apt-get -y autoremove fi +# finally give the ownership to username +chown -R username:username $GOTTY_DIR + #test if [ $run_tests -eq 1 ]; then test_commands=( @@ -187,6 +220,8 @@ if [ $run_tests -eq 1 ]; then "gdb --version" "jq --version" "echo 'puts [info patchlevel]' | tclsh" + "rustc --version" + "rust-gdb --version" )