1

I know this is kinda off-topic, but since I've found the code I'm talking about here on SO I hope that someone can help me.

I was dealing with a POSTGRES error and read here: Can not connect to local PostgreSQL an answer, the one from vvdpzz that lead me to run that code in my terminal. After that, my mac stopped working and since then it doens't reboot, it comes till the apple logo that keeps flashing and switching with a folder with a question mark.

I've checked the code that curl execute and it's the following:

    #!/bin/sh

BREW_POSTGRES_DIR=`brew info postgres | awk '{print $1"/bin"}' | grep "/postgresql/"`
LION_POSTGRES_DIR=`which postgres | xargs dirname`
LION_PSQL_DIR=`which psql | xargs dirname`

sudo mkdir -p $LION_POSTGRES_DIR/archive
sudo mkdir -p $LION_PSQL_DIR/archive

for i in `ls $BREW_POSTGRES_DIR`
do
    if [ -f $LION_POSTGRES_DIR/$i ] 
    then
        sudo mv $LION_POSTGRES_DIR/$i $LION_POSTGRES_DIR/archive/$i
        sudo ln -s $BREW_POSTGRES_DIR/$i $LION_POSTGRES_DIR/$i
    fi

    if [ -f $LION_PSQL_DIR/$i ] 
    then
        sudo mv $LION_PSQL_DIR/$i $LION_PSQL_DIR/archive/$i
        sudo ln -s $BREW_POSTGRES_DIR/$i $LION_PSQL_DIR/$i
    fi  
done

What happened? I'm not an expert. How can I solve this. I've tried to start in secure mode by pressing the shift key while booting but it doesn't work.

Community
  • 1
  • 1
Giorgio
  • 1,603
  • 5
  • 29
  • 52
  • 1
    Sounds like `BREW_POSTGRES_DIR` and/or one of the other variables evaluated to an empty string, and you moved the stuff in your root directory to `/archive`. – tripleee Aug 22 '12 at 19:29
  • And? How can I undo that? Is there a way? – Giorgio Aug 22 '12 at 19:33
  • I'm worried because safe mode doens't work, and if I press apple+s while booting it appears a black screen that ends with a: Could not open file 'mach_kernel' Error loading kernel 'mach_kernel' – Giorgio Aug 22 '12 at 19:34
  • Well, it cannot find the file it needs, because it was moved to a different location. Boot from a DVD and move it back? – tripleee Aug 22 '12 at 19:53
  • sounds like you moved your kernel file out of the way.. no boot for you – nielsbot Aug 23 '12 at 02:12

1 Answers1

2

This is a good example of why you shouldn't run scripts without understanding what they do. My guess is that one or both of LION_PSQL_DIR and LION_POSTGRES_DIR came out as empty and the script ended up moving things around in your root directory. You should be able to recover your system by following these steps:

  1. Boot your OS X installation disc by putting it in the drive and holding the C key while booting.
  2. From the Utilities menu, choose Terminal
  3. Run the command cd /Volumes
  4. Run the command ls which should show an entry corresponding to the name of your Mac's hard drive
  5. Run the command cd "<name of your hard drive>"
  6. Run the command ls. If the problem is that things got moved from the root of your drive, there will be an archive entry, if there isn't then stop since this will not fix your problem.
  7. Run the command cd archive to enter the archive directory
  8. Run the command mv * .. to move everything in the archive directory back to the root of your harddrive
  9. Close the terminal
  10. Run Disk Utility from the Utilities menu and use repair permissions on your drive.
  11. Reboot your computer and hopefully it will work right now
  12. Never run random scripts like that again.

The 10th step might not be strictly necessary. I haven't tried to do these steps myself, but they should be pretty close to correct. If you get any errors during them stop and put a comment and I will try and figure out how to proceed.

Geoff Reedy
  • 34,891
  • 3
  • 56
  • 79
  • gonna try in a while. Hope this help. – Giorgio Aug 22 '12 at 19:52
  • Command-R doens't work as expected :( – Giorgio Aug 22 '12 at 19:56
  • maybe because I'm using OSX 10.4 – Giorgio Aug 22 '12 at 20:02
  • 2
    Of course not. You need to use the CD/DVD to boot 10.4, the recovery partition only exists if you have lion, and even then not on all systems. By the way: why did you run a script that is for lion only on a 10.4? Why did you give admin access (you did type the password or sudo would not work) without first reading and understanding the script? Never give root access to something that does not come from Apple unless you fully understand what it's doing. – Analog File Aug 22 '12 at 22:22
  • 1
    If you have a CD/DVD, you can boot to that by holding [option] to get the boot disk picker, or, just hold [c] on boot to boot via CD/DVD – nielsbot Aug 23 '12 at 02:11
  • If I'm booting with cd, even if I hold c or option key, it brings me to the first menu to instal a new os «chose your language»...if I hold command it recognize only hd as bootable option. – Giorgio Aug 23 '12 at 06:37
  • I didn't solved the problem yet. However I figured out that I could access the DVD booted mode. I've opened terminal from the Utilities menu and ran the command you posted above. Everything worked as expected. The problem is I can't click with touchpad in this DVD-booted mode. So I couldn't repair permissions from there but I did from terminal: diskutil repairPermissions partition . And it run as expected too. BUT when I'm rebooting it gives the same flashing apple/folder and doens't load. What can I do now? Thank you in advance for your efforts, really appreciate. – Giorgio Aug 23 '12 at 08:11