diff --git a/dist/init_rc.sh b/dist/init_rc.sh index 1d56070..52b21a6 100644 --- a/dist/init_rc.sh +++ b/dist/init_rc.sh @@ -2,24 +2,31 @@ # detect if either .bashrc or .zshrc is present -if [ -f "$HOME/.bashrc" ]; then - SHELL_RC="$HOME/.bashrc" -elif [ -f "$HOME/.zshrc" ]; then - SHELL_RC="$HOME/.zshrc" + +# check if user is root and change user to builder +TEMP_USER="builder" + +if [ "$EUID" -eq 0 ]; then + BUILD_USER="$TEMP_USER" else - touch "$HOME/.bashrc" - SHELL_RC="$HOME/.bashrc" + BUILD_USER="$USER" +fi + + +if [ -f "/home/$BUILD_USER/.bashrc" ]; then + SHELL_RC="/home/$BUILD_USER/.bashrc" +elif [ -f "/home/$BUILD_USER/.zshrc" ]; then + SHELL_RC="/home/$BUILD_USER/.zshrc" +else + touch "/home/$BUILD_USER/.bashrc" + SHELL_RC="/home/$BUILD_USER/.bashrc" fi echo "Using shell rc file: $SHELL_RC" # Check if content already exists in the shell rc file and if not, append it -if ! grep -q "export PATH=\$PATH:\$HOME/.local/bin" "$SHELL_RC"; then - echo "Adding .local/bin to PATH in $SHELL_RC" - echo 'export PATH=$PATH:$HOME/.local/bin' >> "$SHELL_RC" -else - echo ".local/bin is already in PATH in $SHELL_RC" -fi +cat /home/"$BUILD_USER"/"$SHELL_RC" | if ! grep -q "ANDROID_HOME" ; then + cat dist/.baserc >> /home/"$BUILD_USER"/"$SHELL_RC" fi -source "$SHELL_RC" +source /home/"$BUILD_USER"/"$SHELL_RC"