Results 1 to 6 of 6

Thread: How to effectively use "konsole"

  1. #1

    Thumbs up How to effectively use "konsole"

    Where I work they use apple computers but for my personal use I have Leap for developing from home. I'm porting a script over from the work computer to my Leap setup.

    On the apple computer I use the following:
    Code:
    osascript<<EOF
        tell application "Terminal"
            do script "$1 $2 $3 $4"
        end tell
    EOF
    and it will open up a new bash window and execute whatever I want. When it does, the new window inherits quite a few things and even
    Code:
    who am I
    will return the user I sudo'ed from.

    The equivalent in KDE as far as I can tell, from root user, is:
    Code:
    xauth add $(xauth -f /home/$USER_USER/.Xauthority list|tail -1)
    export DISPLAY=:0.0
    export XDG_RUNTIME_DIR='/tmp/runtime-root'
    konsole --noclose -e "$1 $2 $3 $4"
    however doing this loses
    Code:
    who am I
    's ability to know who the user that was originally sudo'ed from.

    While it's possible I could pass this information in parameters I was wondering there is a way for the new konsole window bash script to figure out the original sudoer that started the whole process without passing the information as a parameter?

  2. #2

    Default Re: How to effectively use "konsole"

    It seems to be more than just
    Code:
    who am i/sudoer
    information that gets lost. All my variables that were setup don't get passed either. Is there way to have a new terminal window inherit all the variables you setup in the terminal window that launched it?

  3. #3
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    2,349

    Default Re: How to effectively use "konsole"

    Quote Originally Posted by Reg_gie View Post
    's ability to know who the user that was originally sudo'ed from.
    Linux 'sudo' is normally set up to use the real and effective user and group IDs of the target user:
    Code:
     > sudo whoami
    root's password:
    root
     >
    If you need to use a different behaviour then, the security policy has to be changed.

  4. #4
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,009
    Blog Entries
    3

    Default Re: How to effectively use "konsole"

    Quote Originally Posted by Reg_gie View Post
    When it does, the new window inherits quite a few things and even
    Code:
    who am I
    will return the user I sudo'ed from.
    I'm pretty sure that "who am i" is just reporting the owner of the terminal device that you are using.

    When you use "konsole", a new pseudo-tty device is assigned, and set to be owned by whoever is running the KDE session. So that's what the answer to "who am i" will show.
    openSUSE Leap 15.1; KDE Plasma 5;

  5. #5
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    10,634
    Blog Entries
    1

    Default Re: How to effectively use "konsole"

    There is appparently a Python wrapper for osascript so you can run those scripts on Linux

    https://code.activestate.com/pypm/osascript/

    Otherwise...
    I'd recommend you simply look up the functionality of each of the special shell extensions you want to implement and see if a shell framework already supports...
    I'd also recommend you modify Xterm instead of Konsole...
    Konsole is already modified by openSUSE and I don't know if you should tinker with it, there might be unexpected consequences...
    Xterm on the other hand is basic and default so not likely to conflict with whatever you want to do to it.
    (or you can install another shell).

    Examples of shell extenders...

    BASH-it
    https://github.com/Bash-it/bash-it

    Awesome-shell
    https://github.com/alebcay/awesome-shell

    Terminals-are-sexy
    https://terminalsare.sexy/
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  6. #6

    Default Re: How to effectively use "konsole"

    So ultimately I ended up doing it like this:

    File: spawn.sh

    Code:
    #!/bin/bash
    
    TX_FILE_FOR_BG_PROCESSES="$LOG_DIR/varsToTx.sh"
    function save_vars_and_join_display() {
      xauth add $(xauth -f /home/$USER_USER/.Xauthority list|tail -1)
      export DISPLAY=:0.0
      export XDG_RUNTIME_DIR='/tmp/runtime-root'
      # The information to derive USER_GROUP & USER_USER gets lost when spawning
      # which we get from "who am i" in bash.
      set |grep -P '^(USER_(USER|GROUP)|PROJECT_NAME_QUERY)=' > "$TX_FILE_FOR_BG_PROCESSES"
      chmod 775 "$TX_FILE_FOR_BG_PROCESSES"
      chown $USER_USER:$USER_GROUP "$TX_FILE_FOR_BG_PROCESSES" # Just to make it easier to delete if we want.
    }
    
    case "$(uname -s)" in
        Linux*)
          case $(echo "$XDG_DATA_DIRS" | grep -Po 'gnome|kde|xfce' | head -n1) in
            gnome) 
              save_vars_and_join_display
              gnome-terminal -e "./includes/spawned.sh $1 $2 $3 $4 $5 $6 $7 $8 $9" & # Not yet tested
            ;;
            kde)
              save_vars_and_join_display
              konsole --noclose -e "./includes/spawned.sh $1 $2 $3 $4 $5 $6 $7 $8 $9" &
            ;;
            xfce) echo 'Not implemented.' ;;
          esac
        ;;
    
        Darwin*)
    osascript<<EOF
      tell application "Terminal"
        do script "cd \"`pwd`\"; $1 $2 $3 $4 $5 $6 $7 $8 $9"
      end tell
    EOF
        ;;
    #    CYGWIN*) ;;
    #    MINGW*)  ;;
    #    *)       ;;
    esac
    File: spawned.sh
    Code:
    #!/bin/bash
    
    TX_FILE_FOR_BG_PROCESSES="logs/varsToTx.sh" # This we have to hard code since this is a spawned process and all variables have been lost.
    if [ -e "$TX_FILE_FOR_BG_PROCESSES" ]; then
      . "./$TX_FILE_FOR_BG_PROCESSES"
    fi
    . $1 $2 $3 $4 $5 $6 $7 $8 $9

Posting Permissions

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