Find the answer to your Linux question:
Results 1 to 5 of 5
I'm writing an installation script that has many different parts that need to be installed by the user that is executing the script and certain parts need to be executed ...
  1. #1
    Just Joined!
    Join Date
    Jun 2011
    Posts
    10

    Store user name when executing a bash script as sudo?

    I'm writing an installation script that has many different parts that need to be installed by the user that is executing the script and certain parts need to be executed with sudo and other parts require me to install them as the user so that they end up installed in the correct location. The problem is that I have too many items being installed either way for me to pick either requiring a password for each sudo apt-get item (or anything that modifies system files). So ideally, I'd like the script to know how to go about doing this and have the user change temporarily for each menu option that requires it.


    Also, is there any way to carry this across multiple script files?

    tl;dr:

    Here's my code and the code I'm trying to install:
    #1 and #2 are mine, #3 is something that I'm trying to incorporate into my installer and having trouble because I can't get root to drop and his files are installed into the /home/root directory. Whenever I have it install I'd ideally want it to install into their /home/username/.... directory.

    #1 gist.github com/fe8760fa481b8b474601
    #2 gist.github com/2a6a0a5489d25924028b
    #3 gist.github com/663f586192245f055c40

  2. #2
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,789
    Is there no way that you can do all the root stuff at the start/end, and then all the user stuff so you only get asked once?

    If that's not the case, then you could maybe look into something like Expect. This will allow the user to specify a password in the script, and it will then automatically be able to use this as/when it needs.
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  3. #3
    Just Joined!
    Join Date
    Jun 2011
    Posts
    10
    Based on the nature of what I need to let the users choose from installing, I don't think I can do all the root installation parts first. My main goal is to make a very broad installation script for Android community themers / developers that lets them choose what they want to install depending on their needs at the time and to try to include as many things as possible in the script through menus for them. The problem with this is that I've begun assimilating other scripts that don't require root like mine did and that's where I'm getting confused. I've been asking the Android community what they use, then asking the script writers for their permission to include it in my script, and then trying to modify their scripts and just running into a few road blocks along the way with the permissions with root/normal user during the setup processes of their scripts.

  4. #4
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    I looked briefly over your three scripts.
    To be honest, I would approach that differently.

    Everything, that needs to be system wide should be packaged (deb in your case)
    Everything that shall live in a home directory should be available via a repository. svn/git/whatever
    You must always face the curtain with a bow.

  5. #5
    Linux Guru
    Join Date
    May 2011
    Posts
    1,842
    Quote Originally Posted by tahl View Post
    I'm writing an installation script that has many different parts that need to be installed by the user that is executing the script and certain parts need to be executed with sudo and other parts require me to install them as the user so that they end up installed in the correct location. The problem is that I have too many items being installed either way for me to pick either requiring a password for each sudo apt-get item (or anything that modifies system files). So ideally, I'd like the script to know how to go about doing this and have the user change temporarily for each menu option that requires it.


    Also, is there any way to carry this across multiple script files?

    tl;dr:

    Here's my code and the code I'm trying to install:
    #1 and #2 are mine, #3 is something that I'm trying to incorporate into my installer and having trouble because I can't get root to drop and his files are installed into the /home/root directory. Whenever I have it install I'd ideally want it to install into their /home/username/.... directory.

    #1 gist.github com/fe8760fa481b8b474601
    #2 gist.github com/2a6a0a5489d25924028b
    #3 gist.github com/663f586192245f055c40
    Have you looked at "runuser"? Not sure if it would work for your setup or not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...