Posts Tagged ‘sudo’

2011w30

Sunday, July 31st, 2011

Hacking the shell

I’ve scratched some itches this week, some by pure luck, others by seeking these itches out and scratching them with a vengeance ;)

Added to my ~/.bash_aliases is now alias pwd='pwd -P' which tells pwd to resolve the real path when you have cd’d in to a symlinked directory.

Not really a hack, but I discovered Meta-BackSpc / ESC-BackSpc which will, unlike Ctrl-w, delete parts of a path, instead of the entire path.

This thread was of great help in finding that key combination.

Also, thanks to Rikard I got hold of this document which outlines how I would go about getting a word, after the cursor, deleted. Before the cursor is eash (Ctrl-w), but after has always eluded me. Turns out it is Meta-d (or, as in my case, if that is overridden by your window manager, “ESC d”). VERY nice!

I did update my PS1 variable, both for root and my ordinary user. I don’t really know why I hadn’t thought of adding a time indicator before.

There have been times when I have started a long running process, and half an hour or so into it realized that it would have been nice to time the process. Now, this wouldn’t exactly be able to fully replace time, but could do in a pinch so to speak.

root: PS1='\n\[\e[0;33m\][\t] \[\e[0;31;5m\]\u@\h\e[25m\] \[\e[01;34m\]$(pwd)\n\[\e[0m\]# '

which will create the prompt:

[HH:MM:SS] root@host /present/working/directory
#

(yes, root@host IS blinking. root can haz be seriuz bizness!)

user: PS1='\n\[\e[0;33m\][\t] \[\e[0;37m\]\u@\h \[\e[01;34m\]$(pwd)\[\e[0m\]\n\$ '

and this produces

[HH:MM:SS] patrik@host /present/working/directory
$

ImageMagick and Animations

I kindof just assumed imagemagick would have some sort of way of creating an animated gif, and of course imagemagick didn’t let me down.

What surprised me was how incredibly easy it was.

Duck Duck Go (as I am attempting a google-free week) gave me this result, and once I had tweaked the parameters somewhat I ended up with this: $ convert -delay 50 -loop 0 root*.gif rootshell.gif

Zenity and passtore

I also managed to convince (nagged him until his ears risked falling off ;) ) Rikard to try out my password management system passtore.

He did have one counter-demand however: he’d need a GUI for day-to-day operations. Me, being a wmii acolyte, can do without it, but I can see how he would feel different, and seeing as it would be a fun exercise, and I’d get him to give it a shot, I sat down and had at it.

Zenity was my first thought, and as it worked out well, it was my only thought ;) The working name for that code is “Heaven ZENt”. Yes I know, I am a stupid wanker, I can live with that ;D

I am however pondering whether I should release this code as a separate project (it depends on passtore, and is useless without it, which should indicate “no”) or not (it does introduce a dependency on zenity, which isn’t strictly needed to operate passtore).

At present time it is only a wrapper around the getpass script from passtore. In essence, “heaven ZENt” is “wyrd” to “passtore’s” “remind”. I am unsure as how to proceed. Input would, as always, be appreciated.

Musings

I’ve given myself the mission to move one of my (spam-trap) email accounts from Thunderbird to mutt. I really want to be able to use mutt as that would be one less thing I’d need to start X for.

So I am looking at other peoples .muttrc files, and came across the index_format setting. This controls how your list of emails in an “inbox” is presented. In Thunderbird this view (simplified) is “some flags, subject, some more flags, author name, even more flags, date”, and what I realize from the .muttrc files I’m viewing, is that at least some people place the date before author, before subject.

That got me thinking about whether this is some sort of brain hack, to force the brain into working in a different way. Coming from Thunderbird, when a new message arrives in a conversation my reaction is to either open it, or let it be for now, depending on whether it is a discussion I am interested in.

At that point I don’t bother to look at the author field, if the conversation is uninteresting (to me) I will simply defer it to later, and if it is interesting I will simply open the new mail and read it, thereby getting to know who wrote it.

Putting the author in front of the subject could let you filter on people rather than on subject, as we all have some people we listen more intently to than others, so whatever discussion they’re in, it might be worth while to read it.

But that still didn’t explain why they’d put date and time before author. The only idea I have about this is that some mails will be urgent and thus it is good to see when they arrived. But I don’t know. I think I will try out “flags, author, subject, datetime” and see how that goes.

Revelation

If you mess up the datetime settings in BIOS (because you have powered down and unplugged your system during a thunderstorm, AND your motherboard is so old that the CMOS battery is dead) you may experience some problems when booting.

In my particular case, FSCK (or whatever binary it is that is performing a quick check on the file system during boot) reported that the datetime was now 2011-07-11 (because I fucked that up), but the last check had been performed in 2011-07-22.

This made it confused and prompted me to manually repair the file system, by entering the root password (which I have unset, -1 for sudo / me) and doing some operations.

That was actually not such a fun night trying to get to the bottom of that.

:wq

And now I know…

Sunday, August 15th, 2010

… why it is a good idea, nay a must, to keep a live cd around.

After a system upgrade earlier tonight I got a message about an new sudoers file (placed in /etc/sudoers.pacnew) that had been downloaded and wanted me to take a look at it.

So I made a couple of mistakes here:

  1. I didn’t stop to think it through enough, which lead to…
  2. I didn’t edit the new sudoers file first before moving it in place, but also…
  3. I MOVED the original file to a backup spot, instead of COPYING it
  4. Of course, none of this would have mattered, had I logged into the root account before doing stuff, instead of relying on sudo… for tampering with sudoers… I’m so smart! S-M-R-T.

So, instead of doing things the right way, i.e.:

$ sudo su
# cp /etc/sudoers /etc/sudoers.bak
# vim -p /etc/sudoers.pacnew /etc/sudoers.bak
# mv /etc/sudoers.pacnew /etc/sudoers

what I did was (NEVER EVER DO THIS!):

$ sudo mv /etc/sudoers /etc/sudoers.bak

The instant I hit enter, I got a sinking feeling, knowing I’d frakked up. Attempting to undo the damage

$ sudo mv /etc/sudoers.bak /etc/sudoers

only resulted in an error message:

sudo: can’t stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting

There might have been a root password set, but if so I couldn’t for the life of me remember it. Great! What now?

I knew of course I could access the filesystem from a live-cd but I hadn’t actually needed to do this before, so I was unsure about how to proceed once in the live-session (I had a vague notion about having to fiddle with chroot, something I have not done much of) but as luck would have it, hesa was online and helped me out (no need for chroot, just mount the partition, move some files, unmount, restart.)

Upon booting into Knoppix it was a small matter of

  1. remembering which of the disk, and partitions which housed the root-partition, and
  2. mounting it:

$ sudo mount /dev/sdb3 /media/sdb3
$ cd /media/sdb3/etc/
$ sudo mv sudoers.bak sudoers
$ cd /
$ sudo umount /media/sdb3
$ sudo reboot

Now, this would have been the sane thing to do, and start over from inside Arch… but instead I moved sudoers.pacnew into sudoers, forgot to edit it, rebooted, realized my new mistake, rebooted again (a hassle, since sudo reboot wasn’t available), remounted sdb3, edited sudoers adding myself again, and finally rebooted. And all was well.

So now I know, first hand… Live-CDs FTW!

:wq