1- #! /bin/sh
1+ #! /bin/bash
22set -e
33
44echo " Installing fuelup with provided toolchain: ${TOOLCHAIN} "
55
66export DEBIAN_FRONTEND=noninteractive
7- export PATH=$HOME /.fuelup/bin:$PATH
7+ export FUELUP_HOME=$HOME /.fuelup
8+ export REMOTE_FUELUP_HOME=$_REMOTE_USER_HOME /.fuelup
9+ export PATH=$FUELUP_HOME /bin:$PATH
810
911if [ " $( id -u) " -ne 0 ]; then
1012 echo -e ' Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
1113 exit 1
1214fi
1315
14- # Add fuelup the the path for all new login shells.
15- echo " export PATH=\$ PATH:\$ HOME/.fuelup/bin" > /etc/profile.d/00-fuelup.sh
16- chmod +x /etc/profile.d/00-fuelup.sh
16+ # Ensure that login shells get the correct path if the user updated the PATH using ENV.
17+ rm -f /etc/profile.d/00-restore-env.sh
18+ echo " export PATH=${PATH// $(sh -lc ' echo $PATH' )/ \$ PATH} " > /etc/profile.d/00-restore-env.sh
19+ chmod +x /etc/profile.d/00-restore-env.sh
20+
21+ # Updates bashrc and zshrc files with the given string if not already present.
22+ updaterc () {
23+ echo " Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
24+ if [[ " $( cat /etc/bash.bashrc) " != * " $1 " * ]]; then
25+ echo -e " $1 " >> /etc/bash.bashrc
26+ fi
27+ if [ -f " /etc/zsh/zshrc" ] && [[ " $( cat /etc/zsh/zshrc) " != * " $1 " * ]]; then
28+ echo -e " $1 " >> /etc/zsh/zshrc
29+ fi
30+ }
1731
1832# Updates apt-get if the cache is empty.
1933apt_get_update ()
@@ -33,7 +47,7 @@ check_packages() {
3347}
3448
3549# Install required packages to build if missing.
36- check_packages curl git-all sudo
50+ check_packages curl git-all
3751
3852# Install fuelup.
3953curl --proto ' =https' --tlsv1.2 -sSf https://install.fuel.network/fuelup-init.sh | sh -s -- --no-modify-path
@@ -45,11 +59,20 @@ if [ "${TOOLCHAIN}" != "latest" ]; then
4559 fuelup default ${TOOLCHAIN}
4660fi
4761
62+ # Ensure fuelup and forc are installed.
63+ fuelup --version
64+ forc --version
65+
4866# If the remote user is a different user, copy the fuelup directory to the remote user's home.
4967if [ " $HOME " != " $_REMOTE_USER_HOME " ]; then
50- sudo cp -r $HOME /.fuelup $_REMOTE_USER_HOME /.fuelup
68+ mv $FUELUP_HOME $REMOTE_FUELUP_HOME
69+ chmod 775 -R $REMOTE_FUELUP_HOME
70+ chown -R $_REMOTE_USER :$_REMOTE_USER $REMOTE_FUELUP_HOME
5171fi
5272
53- # Ensure fuelup and forc are installed.
54- fuelup --version
55- forc --version
73+ # Add FUELUP_HOME and bin directory into bashrc/zshrc files.
74+ updaterc " $( cat << EOF
75+ export FUELUP_HOME="${REMOTE_FUELUP_HOME} "
76+ if [[ "\$ {PATH}" != *"\$ {FUELUP_HOME}/bin"* ]]; then export PATH="\$ {FUELUP_HOME}/bin:\$ {PATH}"; fi
77+ EOF
78+ ) "
0 commit comments