Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

2020-04-10

profile bash_profile bashrc on Ubuntu Linux, Macs, and Windows

I'm trying to get the same script to run and also set the $PATH for the login and non-login terminal shell on all 3 OSs: Windows, Mac, and Linux.

There's 3 parts to making it work:

Does the shell start in login or non-login mode?

  1. Mac's Terminal.app by default starts bash as a login shell.
  2. Ubuntu graphically logs in as a GUI shell (i.e. your desktop environment, gnome-session, etc.), so it's just not bash at all.  But if you then open a terminal in the desktop environment, your manually opened bash shell on Ubuntu may well start as a non-login (i.e. interactive) shell.
  3. Debian LXDE graphically logs in with bash and runs as a login shell by default.
  4. Windows Git Bash (MINGW64) seems to start as a login shell by default as well.

Which script runs on shell startup: .profile, .bash_profile, .bashrc?

  1. Gnome-session or whatever is your desktop environment (DE) is not bash, but the script that starts your DE is supposed to source ~/.profile but NOT ~/.bash_profile.  However, it's possible with Debian LXDE that it'll prefer ~/.bash_profile if it exists over the fallback that is ~/.profile.
  2. Bash as a login mode shell sources ~/.bash_profile and if that's missing then ~/.profile as a fallback.
  3. Bash as a non-login (interactive) shell sources ~/.bashrc and NOT those other two.

Where should scripts go to run on shell startup?

  1. So scripts that run only when your desktop environment or graphical shell starts goes into ~/.profile.
  2. Scripts that run only when you start bash in login mode --- e.g. started with bash -l, via the text console mode in Debian or Ubuntu e.g. via Ctrl + Alt + F2, when Mac's Terminal.app opens, or when Git's MINGW Bash opens on Windows --- goes into ~/.bash_profile.
  3. Scripts that run only when you start bash interactively (non-login mode) --- e.g. started by clicking the terminal icon having graphically logged in to Ubuntu's DE --- goes into ~/.bashrc.  This assumes you didn't configure your terminal emulator to run as a login shell!

Want the script to always run however shell starts up?

Suppose you want a bit of code to run when your shell starts.  It doesn't matter if it's a login, non-login (i.e. interactively started), graphical login from your desktop environment, on Macs, on Windows MINGW, etc.

In principle, I think ~/.bash_profile and ~/.profile both should source in ~/.bashrc as well, so scripts in ~/.bashrc should run whichever way you get your hands into a terminal UI in Ubuntu.  But Macs and Windows Git Bash doesn't have a proper .bash_profile to start.

Thus for Macs and Windows, favor ~/.bash_profile.

For Ubuntu Linux, favor ~/.bashrc.

A single method that works on all 3 platforms would be to put the code in ~/.bashrc, then make sure ~/.bash_profile sources in bashrc.



Bibliography

Why ~/.bash_profile is not getting sourced when opening a terminal?

DotFiles

2012-08-27

OpenShift My Python Django Project

Red Hat's OpenShift platform-as-a-service is easy to set up and start using if you have a Python Django project (I haven't tried the other platforms supported, e.g. Java).  It's just 9 (longish) steps!

The django-example they offer gives a good idea of what the completed Django on OpenShift project should look like, but I thought I'd jot some notes down on how to get there from an existing Django project on Ubuntu Linux.

There are two main parts to this process, (A) OpenShift Tools Set-up, and (B) Set-up Python Django Project for OpenShift.


(A) OpenShift Tools Set-up
 
(0) Go to OpenShift and sign up for an account.

(1) Install the rhc client tool on your local computer.
 There's some instructions provided, but it boils down to running on your command line:

$ sudo apt-get install ruby-full rubygems git-core
$ sudo gem install rhc
$ rhc  #this should now run without errors

(2)  Setup your computer to connect to the OpenShift servers.
This should be easy. Just do on the command line: rhc setup and follow the on-screen instructions.

That should really be all it takes, but note that that will upload your default public encryption key for your computer to OpenShift, namely: ~/.ssh/id_rsa.pub so you should know the password to that key pair or else you won't be able to connect to OpenShift.

If you don't want to use your default key, or some other reason, you can always create a new public/private encryption key pair and upload that (just delete the default one from OpenShift, which you can do through their web interface or on the command line).  I'll describe that next.

2012-08-05

Github HTTPS Read and Write Push URL Broken

It's good to use Git's own protocol to push and pull repositories, but sometimes that's blocked by your company's IT department.  In that case, you may use the HTTPS protocol

To pull, copy the HTTP URL from the Github project page.  It should be in the form of https://github.com/theUserName/theProjectName.git.

Then in your terminal, do a git clone https://github.com/theUserName/theProjectName.git to get the project repository.

After making and committing some changes, you may wish to push the changes to Github again.  Of course, you should do something like git pull origin theDesiredBranchName to ensure you've gotten the latest changes from Github first.  Then you'd do a git push origin theDesiredBranchName.

If it works properly, it should prompt you for your Github username and password.  Or it doesn't work, you run into a problem, and git gives you this error:

error: The requested URL returned error: 403 while accessing https://github.com/theUserName/theProjectName.git/info/refs

fatal: HTTP request failed


Solution? No guarantees, but this worked for me.  In terminal, do:

git remote set-url origin https://YourUserName@github.com/theUserName/Booking.git

Obviously, change "YourUserName" to your Github username.

Then again do git push origin theDesiredBranchName. If it works properly, it should prompt you for only your Github password.

For some reason Github denies HTTPS access sometimes if the username isn't sent along with the project URL.