I want to add my own ~/bin directory to the beginning of the PATH

Forum Forums Official Releases antiX-19 “Marielle Franco, Hannie Schaft, Manolis Glezos, Grup Yorum” I want to add my own ~/bin directory to the beginning of the PATH

  • This topic has 22 replies, 5 voices, and was last updated Oct 28-11:05 pm by BobC.
Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #28610
    Moderator
    BobC

    Ok, so I need to figure out where to add it…

    I found out that ~/.desktop-session/startup never runs. I was surprised by that.

    I also found out that ~/.profile never runs. I was also surprised by that, especially since it seems to include the code I was hoping would run:

    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
    fi
    

    Ok, so then, what DOES run? I added echo statements to all the logical programs to find out by adding to a file I created as ~/startup.log by adding an echo statement to tell me which ones ran:

    echo "$(date): $0 Starting from $HOME/.profile" >> $HOME/startup.log &
    

    The resulting log file tells me which are actually running:

    Sat 26 Oct 2019 12:36:55 PM CDT: /home/bobc/.icewm/startup Starting from /home/bobc/.icewm/startup
    Sat 26 Oct 2019 12:36:57 PM CDT: /bin/bash Starting from /home/bobc/.bashrc
    Sat 26 Oct 2019 12:37:00 PM CDT: /bin/bash Starting from /home/bobc/.bashrc

    I’m only running IceWM. I guess that means the code needs to be in ~/.icewm/startup. So here is the code I came up with, is it ok? Or should I put it into ~/.bashrc in case I switch to Fluxbox or JWM instead of IceWM?

    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
        # Add $HOME/bin directory to PATH if not already there.
        [ -z "${PATH##*$HOME/bin*}" ] || PATH=$HOME/bin:$PATH
    fi

    Thanks for any ideas or suggestions…

    • This topic was modified 1 year, 7 months ago by BobC.
    #28613
    Moderator
    Brian Masinick
    Helpful
    Up
    0
    :D

    Bob, when you start an interactive shell such as /bin/bash, you can put specific commands in .bashrc. Logging in alone doesn’t start .bashrc.

    I’ll look into the specific details.

    You can explicitly issue the command source ~/. bashrc and then the things in the file will be there for certain as long as they are accurate.

    Brian Masinick

    #28614
    Moderator
    BobC
    Helpful
    Up
    0
    :D

    Is there a better place then, back in slim, or somewhere else, maybe?

    My purpose is to avoid needing to modify things outside of my /home directory to make upgrades and updates as easy as possible.

    #28615
    Moderator
    Brian Masinick
    Helpful
    Up
    0
    :D

    I’d say that putting your own programs and scripts in your~/bin directory and explicitly executing them once logged in is a good practice.

    I’ll try to get specific details of exactly what typically initiates various actions.

    Brian Masinick

    #28616
    Moderator
    Brian Masinick
    Helpful
    Up
    0
    :D

    The file /etc/login.defs describes what happens when you login; the administrator of the system can modify this file as needed.

    I’ll see what we have in there and make additional suggestions. There are various login files, including .profile, .bashrc, .bash_aliases, etc. that can be used for various purposes. What we really need to know is precisely what happens when you login to the system without necessarily opening a shell or terminal window. I’ll examine the various resources and provide specific details unless someone else beats me to it.

    Slim, lightdm, and other login resource managers ought to have files that can have specific instructions, commands, executable scripts, etc. included in them; I’ll look for those details.

    Brian Masinick

    #28617
    Moderator
    Brian Masinick
    Helpful
    Up
    0
    :D

    The file /etc/slim.conf contains the default path, default X server, info for altering the numlock and mouse cursor details.

    It also has hooks for login command shell script information.

    Lightdm and other display manager programs should have similar capabilities if they are used instead of slim.

    • This reply was modified 1 year, 7 months ago by Brian Masinick.

    Brian Masinick

    #28619
    Moderator
    BobC
    Helpful
    Up
    0
    :D

    It sounds like the easy answer is to add it in slim.conf if it will be true for all users and all desktops. I will give that a try and see what happens under su and sudo. I’m trying to find a way to keep my program changes under /home to make updates and migrations easier.

    Thanks for the info.

    #28621
    Member
    skidoo
    Helpful
    Up
    0
    :D

    I want to add my own ~/bin directory to the beginning of the PATH

    Do as you please, just understand that doing this makes your system ripe for exploitation by malware (or by a well-intended, but misbehaving same-named program, which will overshadow its native counterpart).

    see what happens under su and sudo

    zackly.
    Any ol’ myprog running as your user will be able to place in your ~/bin/ an executable scriptfile named “sudo”…
    …and next time ya “sudo whatever” — BOOM — you’ll never know what hit ya.

    #28623
    Moderator
    BobC
    Helpful
    Up
    0
    :D

    Ok, skidoo, I appreciate you giving warning. Have you got any ideas that are less worse?

    How about I add one directory as root in the path by changing slim.conf and limit access to changing that directory to root.

    That way I can run my programs, but keep them separate, and therefore they are at least easier to maintain, ie I can only maintain them if I intend to, or do something under su or sudo.

    #28625
    Forum Admin
    Dave
    Helpful
    Up
    0
    :D

    Not skidoo but…

    How about I add one directory as root in the path by changing slim.conf and limit access to changing that directory to root.

    That way I can run my programs, but keep them separate, and therefore they are at least easier to maintain, ie I can only maintain them if I intend to, or do something under su or sudo.

    Hmm one directory owned and maintained by root (system admin) but executable by the user and is not supposed to change in an update. /usr/local/bin/?

    Computers are like air conditioners. They work fine until you start opening Windows. ~Author Unknown

    #28628
    Moderator
    BobC
    Helpful
    Up
    0
    :D

    Yes, but that is the problem that I have now. For example, antiX wallpaper script needs to be modified after each update to record the filename of the wallpaper currently on display so that my flip, flip, mirror, rotate, delete and save options will know what image I want them to work on.

    I want to put my tweaked versions of programs in a different directory in front of /usr/local/bin so that my version runs and doesn’t get overlaid by an update. It could be called /usr/local/bin/userpgms or something. It would be owned by root. I basically only change them if I find a bug or make an improvement or need to merge in changes from an update.

    Just thinking aloud….

    #28631
    Moderator
    Brian Masinick
    Helpful
    Up
    0
    :D

    How about something else then?

    Create a new directory, have it owned by root, managed by you through root, saved and restored as needed any time you need a system change?

    sudo mkdir -p /Bob/bin would do that. You could also have /bobc/data and any other useful directory in the same place.

    Brian Masinick

    #28634
    Moderator
    BobC
    Helpful
    Up
    0
    :D

    I don’t pretend to know that much about Linux. I am hitting problems, trying to see how I could solve them, and if I find something already there I try to imitate. I may or may not understand the why or why not behind things, as skidoo illustrated, and that shows my question was valid.

    Maybe Linux has an “expected or normal place” for me to put programs that I want to run in addition to or in place of (yes,, that means I need to maintain it) the things packages I or the OS installed are maintaining. I found the code installed by antiX where it was looking to see if $HOME/bin had been created, and if so to add it to the front of the path, and thought I had found that place, but noticed it didn’t run, and that didn’t make sense, and therefore I was questioning it all.

    Yes, I would agree, the name of the folder probably isn’t very important as long as it isn’t something that would cause a conflict, but I was trying to find out if there was a normal way or place to do it in a good way. I don’t know how many times since I started programming that I have tripped over unusually named or located things that caused trouble another day, a year, a decade, or even 30 or 40 years later (as recently as last week), and I cringe at the thought of those future messes having my name on them…

    #28637
    Moderator
    Brian Masinick
    Helpful
    Up
    0
    :D

    Bob, what is normal for Linux distributions is that the individual has choice, even the choice between locking down the system with every precaution or taking a widely diverse, even “risky” decision to open a system to potential intrusive activities.

    Regarding directory path choices, the main risk is to expose information if you are not careful with file and directory permission.

    There’s nothing to prevent you from choosing any in your directory tree and include it in your executable path. If you want to keep these directories as secure as possible, make them writable only by root and limit their execution to the root and your account. Using only directory permission you can’t get very specific and utterly secure. If you add access control lists (ACL) you can get much finer access control with the greater maintenance and knowledge they require. That’s probably something to put on a list of things to learn. Simply reducing file and directory access is a good start.

    Brian Masinick

    #28639
    Member
    model99
    Helpful
    Up
    0
    :D

    If you created a “~/bin” directory that’s all you need to do to have “~/bin” put
    at the beginning of your $PATH variable when you login.

    To prove it.

    After you login, bring up a virtual console window by pressing “ctrl+alt+F3”.
    Login with your user id and password.
    Enter the command “echo $PATH”
    You should see /home/”your user id”/bin at the front of the path.
    Enter “exit” to logout.
    Press “ctrl+alt+F7” to return back to your window manager session.

    Now you may be asking how come I did not see this when I entered the
    “echo $PATH” command from a terminal window (ROXTerm)?

    You need to change your preferences in ROXTerm to make it work.

    From RoxTerm’s menu bar, click Preferences -> Edit Current Profile.
    From the “ROXTerm Profile “Default” window”, click “Command” located on the left side of window.
    From the Command subwindow of “ROXTerm Profile “Default” window”,
    click the check box labeled “Login shell” to where it shows a check mark.
    Click the “Close” button to exit.

    Bring up a new ROXTerm window and do the “echo $PATH” command and you see /home/”your user id”/bin at the front of the path.

    Now this $PATH is in effect when you are logged in as you. It has no effect on other processes running under root or other system use ids.

Viewing 15 posts - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.