Skip to content

Commit

Permalink
Merge pull request #9 from FuelLabs/sophie/pathFix
Browse files Browse the repository at this point in the history
Fix fuelup path and permissions
  • Loading branch information
sdankel authored Mar 17, 2023
2 parents 32aae67 + 07aea0e commit d20fa27
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/fuelup/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Install Fuel Toolchain",
"id": "fuelup",
"version": "1.0.0",
"version": "1.0.1",
"description": "Install the Fuel toolchain using fuelup",
"options": {
"toolchain": {
Expand Down
43 changes: 33 additions & 10 deletions src/fuelup/install.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
#!/bin/sh
#!/bin/bash
set -e

echo "Installing fuelup with provided toolchain: ${TOOLCHAIN}"

export DEBIAN_FRONTEND=noninteractive
export PATH=$HOME/.fuelup/bin:$PATH
export FUELUP_HOME=$HOME/.fuelup
export REMOTE_FUELUP_HOME=$_REMOTE_USER_HOME/.fuelup
export PATH=$FUELUP_HOME/bin:$PATH

if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi

# Add fuelup the the path for all new login shells.
echo "export PATH=\$PATH:\$HOME/.fuelup/bin" > /etc/profile.d/00-fuelup.sh
chmod +x /etc/profile.d/00-fuelup.sh
# Ensure that login shells get the correct path if the user updated the PATH using ENV.
rm -f /etc/profile.d/00-restore-env.sh
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
chmod +x /etc/profile.d/00-restore-env.sh

# Updates bashrc and zshrc files with the given string if not already present.
updaterc() {
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then
echo -e "$1" >> /etc/bash.bashrc
fi
if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then
echo -e "$1" >> /etc/zsh/zshrc
fi
}

# Updates apt-get if the cache is empty.
apt_get_update()
Expand All @@ -33,7 +47,7 @@ check_packages() {
}

# Install required packages to build if missing.
check_packages curl git-all sudo
check_packages curl git-all

# Install fuelup.
curl --proto '=https' --tlsv1.2 -sSf https://install.fuel.network/fuelup-init.sh | sh -s -- --no-modify-path
Expand All @@ -45,11 +59,20 @@ if [ "${TOOLCHAIN}" != "latest" ]; then
fuelup default ${TOOLCHAIN}
fi

# Ensure fuelup and forc are installed.
fuelup --version
forc --version

# If the remote user is a different user, copy the fuelup directory to the remote user's home.
if [ "$HOME" != "$_REMOTE_USER_HOME" ]; then
sudo cp -r $HOME/.fuelup $_REMOTE_USER_HOME/.fuelup
mv $FUELUP_HOME $REMOTE_FUELUP_HOME
chmod 775 -R $REMOTE_FUELUP_HOME
chown -R $_REMOTE_USER:$_REMOTE_USER $REMOTE_FUELUP_HOME
fi

# Ensure fuelup and forc are installed.
fuelup --version
forc --version
# Add FUELUP_HOME and bin directory into bashrc/zshrc files.
updaterc "$(cat << EOF
export FUELUP_HOME="${REMOTE_FUELUP_HOME}"
if [[ "\${PATH}" != *"\${FUELUP_HOME}/bin"* ]]; then export PATH="\${FUELUP_HOME}/bin:\${PATH}"; fi
EOF
)"
4 changes: 2 additions & 2 deletions test/fuelup/beta-1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "execute command" fuelup --version | grep 'fuelup'
check "execute command" forc --version | grep 'forc'
check "execute command" fuelup --version | grep 'fuelup [0-9].'
check "execute command" forc --version | grep 'forc [0-9].'
check "execute command" fuelup default | grep 'beta-1'

reportResults
4 changes: 2 additions & 2 deletions test/fuelup/beta-2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "execute command" fuelup --version | grep 'fuelup'
check "execute command" forc --version | grep 'forc'
check "execute command" fuelup --version | grep 'fuelup [0-9].'
check "execute command" forc --version | grep 'forc [0-9].'
check "execute command" fuelup default | grep 'beta-2'

reportResults
4 changes: 2 additions & 2 deletions test/fuelup/beta-3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "execute command" fuelup --version | grep 'fuelup'
check "execute command" forc --version | grep 'forc'
check "execute command" fuelup --version | grep 'fuelup [0-9].'
check "execute command" forc --version | grep 'forc [0-9].'
check "execute command" fuelup default | grep 'beta-3'

reportResults
4 changes: 2 additions & 2 deletions test/fuelup/default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "execute command" fuelup --version | grep 'fuelup'
check "execute command" forc --version | grep 'forc'
check "execute command" fuelup --version | grep 'fuelup [0-9].'
check "execute command" forc --version | grep 'forc [0-9].'
check "execute command" fuelup default | grep 'latest'

# If any of the checks above exited with a non-zero exit code, the test will fail.
Expand Down
4 changes: 2 additions & 2 deletions test/fuelup/latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "execute command" fuelup --version | grep 'fuelup'
check "execute command" forc --version | grep 'forc'
check "execute command" fuelup --version | grep 'fuelup [0-9].'
check "execute command" forc --version | grep 'forc [0-9].'
check "execute command" fuelup default | grep 'latest'

reportResults
4 changes: 2 additions & 2 deletions test/fuelup/nightly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "execute command" fuelup --version | grep 'fuelup'
check "execute command" forc --version | grep 'forc'
check "execute command" fuelup --version | grep 'fuelup [0-9].'
check "execute command" forc --version | grep 'forc [0-9].'
check "execute command" fuelup default | grep 'nightly'

reportResults
6 changes: 3 additions & 3 deletions test/fuelup/root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "execute command" fuelup --version | grep 'fuelup'
check "execute command" forc --version | grep 'forc'
check "execute command" fuelup default | grep 'latest'
check "execute command" whoami | grep 'root'
check "execute command" fuelup --version | grep 'fuelup [0-9].'
check "execute command" forc --version | grep 'forc [0-9].'
check "execute command" fuelup default | grep 'latest'

reportResults
4 changes: 2 additions & 2 deletions test/fuelup/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib.
check "execute command" fuelup --version | grep 'fuelup'
check "execute command" forc --version | grep 'forc'
check "execute command" fuelup --version | grep 'fuelup [0-9].'
check "execute command" forc --version | grep 'forc [0-9].'
check "execute command" fuelup default | grep 'latest'

# Report result
Expand Down
6 changes: 3 additions & 3 deletions test/fuelup/vscode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "execute command" fuelup --version | grep 'fuelup'
check "execute command" forc --version | grep 'forc'
check "execute command" fuelup default | grep 'latest'
check "execute command" whoami | grep 'vscode'
check "execute command" fuelup --version | grep 'fuelup [0-9].'
check "execute command" forc --version | grep 'forc [0-9].'
check "execute command" fuelup default | grep 'latest'

reportResults

0 comments on commit d20fa27

Please sign in to comment.