DEV Community

Monica
Monica

Posted on

Yak Shaving My Way To Hacktoberfest - Day 2

On how an OS upgrade can kill your Terminal

I woke up to the upgrade to Catalina being completed. I had a couple of hours after work I could use to fix the setup.

I launched iTerm that with a very graceful popup tells me something-something command profile. As soon as I acknowledged the popup, the window closed. I tried another couple of times (monkey monkey), decided to close permanently the popup because brainfart. Probably I was hoping to be able to see the content of the iTerm window underneath. Unable to revert the behavior, I realized I have two profiles on iTerm. I opened the default profile and there it was, the popup in its splendor.

A session ended very soon after starting. Check that the command in profile “molli” is correct.
Enter fullscreen mode Exit fullscreen mode

Looking for the message online told me that something was wrong with the command that iTerm launches at start and that I should look at what the window behind the popup says. I couldn't move the popup around so I had to revert to reopen the window a few times and be reading very fast 🙄

It seemed that bash was causing the problem. I went to my bash_profile and commented out everything bash-related. Relaunching iTerm showed the same issue. I suddenly remembered that, with the last version of MacOS, Apple started suggesting devs to switch to zsh. I fired the OS terminal app that presented the same problem: I cannot use it because it's still looking for bash.

but-why.gif

In my skimming through internet pages and iTerm settings, I realized there was a Command setting under Profiles > General that was set to Login Shell. Finally a stable iTerm with, guess what?

/bin/zsh/
Enter fullscreen mode Exit fullscreen mode

Of course it wasn't enough, because to my subsequent brew doctor, the terminal replied with the equivalent of "I have no clue what you are talking about". But I knew the little rascal (...) was there. FINE. Maybe it was something in the path that zsh doesn't pick up. I tried to configure it properly, but this meant understanding the difference between .zprofile, .profile and .zshrc.

I ended up with a .zprofile that looks like this

emulate sh
. ~/.profile
emulate zsh
export PATH="/usr/local/sbin:$PATH"
export PATH=/usr/local/bin:$PATH
Enter fullscreen mode Exit fullscreen mode

but still no joy for my brewing.

I checked Terminal and lo and behold, it did indeed recognize homebrew. So I used it to launch homebrew and installed bash (sorry, zsh, we'll meet again soon).

I reverted iTerm to use bash too, but it would still close. I made sure I had the latest version of batch available on homebrew, but when I issue echo $SHELL, what I get is still bash 4.3.0. I couldn't figure out where it'd pick this up, because I was 100% sure at this point I had no version named anywhere.

Apparently, on Mac, you can set your PATH variable in multiple places, one of them will add an entry permanently for all users on the machine.

I dug my /etc/shell, changed the config, iTerm doesn't close anymore.

source ~/.bash_profile
-bash: __git_ps1: command not found
Enter fullscreen mode Exit fullscreen mode

FFUU.jpg

It was 9.15AM. I had a meeting at 10. I was still in my pijiama.

Well...

On my way to the subway, I realized I should save this knowledge somewhere. I was learning stuff. I should have a blog. I should actually have a self-hosted blog, because I would be sure that then the content would belong to me 100%.

I stopped. That would have added a WHOLE new yak to shave. What is the mantra of the agile ~daleks~ software engineers? Iterate! ITERATE!
So I went for the fastest thing I could get my hands on and I opened my DEV.TO profile. On my phone, I hacked the first lines of the first post of this series.

Fast forward to 7PM. I was finally home and decided to finish the first post. I had to search for all the sources and reconstruct in my memory what happened the day before. I also decided to note down what happened on that day (you don't want to see those notes, but as you can see, it was a good call, after a week I would have ZERO recollection of any of this).

Now back to my last problem of the day, __git_ps1.

I have my prompt configured in such a way that, when I am in a folder that is a git repository, it shows me the status of the files and the branch I am in. Since I had an old version of git and an old version of OSX, the former configuration wouldn't work. I updated .bash_profile to

export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export PS1="\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[01;33m\]\$(__git_ps1)\[\033[01;34m\] \$\[\033[00m\] "
Enter fullscreen mode Exit fullscreen mode

as described here and I had my git status on my prompt again, all cool.

I ran rake db:setup only to be told that - of course - the database server wasn't running. Because I'm lazy, I have an alias for that too

alias pgstart='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start'
Enter fullscreen mode Exit fullscreen mode

so I added it to .bash_profile and, when sourcing it, bash very nicely told me

-bash: pg_ctl: command not found
Enter fullscreen mode Exit fullscreen mode

I launched and initialized the Postgres app, same outcome. RTFM, Monica: on https://postgresapp.com/ they clearly say to add the Postgres app to the path permanently (remember?) with

sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
Enter fullscreen mode Exit fullscreen mode

This was the first time I was seeing tee, a command used to write to two different places at the same time (by default, to a file and to standard output).
But I questioned the permanent add to the path, so I added the postgres app location to the user PATH in .bash_profile and sourced it to pick up the changes.

An echo $PATH showed me that the changes are there, but the PATH itself was ever-growing and also full of duplicates because of the multiple sources. How could I get rid of the duplicates?

There are a bunch of suggestions out there on how to clean and reset PATH or avoid duplication completely, but it would take too long to do it properly, I was still far away from being able to start coding. So I decided to chop everything off, reset PATH to what I believed was a clean slate and sourced again (MVPs, right?!)

export PATH=/usr/bin:/bin:/usr/sbin:/sbin
source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

gave me back something sensible and clean. Noice.

Looking at my .bash_profile configuration for environment managers, I noticed and commented out some nonsense shit about rbenv that is not relevant and I realized that I didn't have exenv working anymore. But asdf did indeed work, so I removed the first one permanently.

With my brand new and shiny PATH, I could now try and call pgstart again. The command run but it couldn't start the server. I looked at the logs

2019-10-09 07:43:43.634 CEST [37155] FATAL:  database files are incompatible with server
2019-10-09 07:43:43.634 CEST [37155] DETAIL:  The data directory was initialized by PostgreSQL version 9.4, which is not compatible with this version 12.0.
2019-10-09 07:54:17.196 CEST [49284] FATAL:  database files are incompatible with server
2019-10-09 07:54:17.196 CEST [49284] DETAIL:  The data directory was initialized by PostgreSQL version 9.4, which is not compatible with this version 12.0.
Enter fullscreen mode Exit fullscreen mode

O. K.

I removed current installation, reinstalled everything with homebrew, because it was the fastest option. I could then also upgrade the data with homebrew.

 brew postgresql-upgrade-database
Enter fullscreen mode Exit fullscreen mode

A pgstart later, the terminal still tried to start pg_ctl from the Postegre.app installation directory. I needed to check where the aliases where defined and which where currently available on my machine. I cleaned the aliases and resourced again the profile for bash, now which pg_ctl gave me the correct directory, I can start the postgres server.

The moment of truth, running rake db:setup again.

ActiveRecord::NoDatabaseError: FATAL:  role "postgres" does not exist
Enter fullscreen mode Exit fullscreen mode

It was an error, but I had never been happier to see one. I dug again how to create a role within postgres.

I issued psql to check the current roles and users available, but

psql: FATAL:  database "molli" does not exist
Enter fullscreen mode Exit fullscreen mode

I proceeded to create the db from the command line.

I had no idea which password my molli user has, so I proceeded to look for how to reset user password in postgres and set a new one.

I finally was able to create the role for postgres with the same privileges as my main one.

db:setup works! db:test:prepare works!

8:50AM, time to go to work... I might finally be able to code.

Top comments (0)