ruby: fix permissions and ln for oryx (#43)

* ruby: fix permissions and ln for oryx

* add sudo_if
This commit is contained in:
Samruddhi Khandale 2022-06-10 11:37:11 -07:00 committed by GitHub
parent a81ff33fda
commit a71a223511
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -167,6 +167,14 @@ check_packages() {
fi fi
} }
sudo_if() {
COMMAND="$*"
if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then
su - "$USERNAME" -c "$COMMAND"
else
"$COMMAND"
fi
}
# Ensure apt is in non-interactive to avoid prompts # Ensure apt is in non-interactive to avoid prompts
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
@ -271,11 +279,15 @@ if [ "${SKIP_RBENV_RBUILD}" != "true" ]; then
if [ "${USERNAME}" != "root" ]; then if [ "${USERNAME}" != "root" ]; then
mkdir -p /home/${USERNAME}/.rbenv/plugins mkdir -p /home/${USERNAME}/.rbenv/plugins
chown -R ${USERNAME} /home/${USERNAME}/.rbenv sudo_if chown -R ${USERNAME} /home/${USERNAME}/.rbenv
sudo_if chown -R ${USERNAME} /usr/local/rvm/
if [[ ! -d "/home/${USERNAME}/.rbenv/plugins/ruby-build" ]]; then if [[ ! -d "/home/${USERNAME}/.rbenv/plugins/ruby-build" ]]; then
ln -s /usr/local/share/ruby-build /home/${USERNAME}/.rbenv/plugins/ruby-build ln -s /usr/local/share/ruby-build /home/${USERNAME}/.rbenv/plugins/ruby-build
fi fi
ln -s /usr/local/rvm/rubies/default/bin/ruby /usr/local/rvm/gems/default/bin
fi fi
fi fi