Hello all,

It 6 am Sunday early morning, no sleep at all until now and I’m almost exhausted, this has been a great night! Let me tell you the story.

I’m doing a project 8000 miles away from home, now I’m living in Luanda, Angola (usually I live in Lisbon), and this weekend there was a party so I went, the singer wasn’t that bad, the place was crowed with nice Brazilian people (yes there are plenty of them in Luanda) and the food was great so I couldn’t wish for more, after dinner I had planned with some friends to hit a local disco,  But after 5 caipirinhas (a great Brazilian drink), I felt really bad from my stomach so I ended the night there and head back home. After a while in bed I still didn’t feel that good so I went to the laptop and thought in sorting some work things.

Now the fun part, being a bit drunk i did something like (i didn’t want to do it jut typed ENTER before the rest(someway i mistaken TAB with ENTER)):

sudo chown -R pedro:pedro /

I thought to myself… this is taking ages let me have another drink… and then i woke up but it was too late, I’m running to the lap but I have ext4 and an SSD so my entire file system had my UID and GID.

I have backups of everything I do, even the complete FS but the backups are 8000 Miles away and in Angola the best i can get in Internet access is 2Mb.

I felt a bit desperate, I say a bit so I don’t tell you I would like to drink a bottle of vodka to forget the stupidity I made, so before doing anything even more stupid went to the sofa and played angry birds on the tablet for 1 hour.

VOILÁ, I had an idea that will put my laptop running (I hoped)! I didn’t turn off the lap because I knew it was probable it wouldn’t turn on again, so i entered the command line and changed permissions on some critical files:

chown root:root /usr/bin/sudo
chown root:root /etc/sudoers
chmod u+x /usr/bin/sudo

afterwards I changed my home directory to the right permissions:

sudo chmod -R 750 /home/pedro
sudo chown -R pedro:pedro /home/pedro

With this i managed to have KDE and Firefox (although KDE was erratic)
With Firefox i managed to enter my backup server and choose the last backup I had, went to the log page (where the logs of all files are kept) and to my joy I saw i could get all the file owners and permissions from that page.
I just did a play text copy paste from the log into a file named FILE_LIST on my home folder (fortunately i also backup system files, applications, in sum…everything)
now with the list on my hand (I mean disk), i made a little script, it’s more a chain of commands but it worked well.
Here’s the command line:
nice -n -10 cat /home/pedro/FILE_LIST | cut -b 12- | tr -s " " | cut -d " " -f 2,4- | \
while read A ; do \
OWNER=`echo $A | cut -d " " -f 1 | cut -d "/" -f 1 `; \
GROUP=`echo $A | cut -d " " -f 1 | cut -d "/" -f 2` ; \
FILE=`echo $A | cut -d " " -f 2-` ; \
echo $FILE ; \
sudo chown $OWNER:$GROUP "$FILE" ; \
done

And here’s and excerpt of FILE_LIST:

create   755 0/0 2035616 bin/vim-normal
create d 755 0/0 3072 boot
create d 755 0/0 1024 boot/grub

For now I’m safe and a have my system up and running.
I knew that drinking and driving wasn’t safe, but now I know drinking and sudo should be avoid too 🙂
I’m going to bed! This all thing took 3 hours + 1 of angry birds and the day is coming out.
Cheers,
Pedro

P.S – I know the script isn’t ideal, but considering the state I’m now I fell really happy to have things working 🙂