RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Use of __user variable

    Scheduled Pinned Locked Moved Ideas and Development
    retropie-setupshell script
    3 Posts 3 Posters 615 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • MileSaculM
      MileSacul
      last edited by

      I am working on a user management strategy for my RetroPieWebConsole.

      The plan is to allow the ability to swap RetroArch configs for whatever user is logged in, but I have to overcome the installation hurdles first.

      When looking over retropie_packages.sh, I see it uses this code to install for each user:

      # if __user is set, try and install for that user, else use SUDO_USER
      if [[ -n "$__user" ]]; then
          user="$__user"
          if ! id -u "$__user" &>/dev/null; then
              echo "User $__user not exist"
              exit 1
          fi
      else
          user="$SUDO_USER"
          [[ -z "$user" ]] && user="$(id -un)"
      fi
      

      Right now my application hits the SUDO_USER code and for the life of me, I can't figure out how to set the __user variable using my NodeJS app.

      I've tried everything, but it seems my export command does not stick when calling one shell script, then another.

      So I had an idea on how I can throw a solution into retropie_packages.sh; we can incorporate this getopts command:

      while getopts ":p:u:c:" opt; do
        case $opt in
          p)
            package=$OPTARG
            ;;
          u)
            __user=$OPTARG
            ;;
          c)
            command=$OPTARG
            ;;
          \?)
            echo "Invalid option: -$OPTARG" >&2
            exit 1
            ;;
          :)
            echo "Option -$OPTARG requires an argument." >&2
            exit 1
            ;;
        esac
      done
      
      if [[ -n "$__user" ]]; then
          user="$__user"
          if ! id -u "$__user" &>/dev/null ; then
              echo "User $__user not exist"
              exit 1
          fi
      else
          user="$SUDO_USER"
          [[ -z "$user" ]] && user="$(id -un)"
      fi
      
      if [[ -z "$package" ]]; then
          package="$1"
      fi
      
      if [[ -z "$c" ]]; then
          command="$2"
      fi
      
      echo "package: $package"
      echo "user: $user"
      echo "command: $command"
      

      That will allow both support for arg input like -p <package> -u <user> -c <command> and still supports the existing inputs. EX:

      pi@gameberry:~/ $ ./testOpts.sh retroarch install_bin
      package: retroarch
      user: pi
      command: install_bin
      pi@gameberry:~/ $ ./testOpts.sh -p retroarch -c install_bin -u gamer
      package: retroarch
      user: gamer
      command: install_bin
      

      Any thoughts on this? I would like to get opinions or other options before I make a pull request.

      Lucas Showerman
      The true sign of intelligence is not knowledge, but imagination. -Albert Einstein

      1 Reply Last reply Reply Quote 0
      • mituM
        mitu Global Moderator
        last edited by

        I don't think the RetroPie setup script supports multiple users. As long as your NodeJS app runs as the user for which RetroPie is installed, you should be fine.

        1 Reply Last reply Reply Quote 0
        • BuZzB
          BuZz administrators
          last edited by BuZz

          We don't - lots of hurdles to support multiple users. I don't want to add additional script parameters btw so no need to do a pr at this time. Thanks.

          You can set vars with sudo __blah= ./retropie_packages.sh

          To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

          Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.