Page 1 of 1

My Perl Script

Posted: Tue Feb 24, 2004 1:04 am
by Code-X
I was bored and decided to try and make a User Friendly Script that would Emerge EBuilds then either Shutdown or Reboot after.

The Script works but is real nasty, Any one that can help.
The main problem is with the Checking, I could not get "or" statements to work.

btw, I named it SMERGE for Shutdown Emerge :D

Code: Select all

#!/bin/bash
#Emerge Runner with Shutdown or Reboot After
#My first ever BASH Script for Linux ;-)

  echo -e "Please Enter an E-Build to Emerge"
  read EBuild
  if [ $EBuild == "" ]; then
    echo -e "Please Enter an E-Build"
    sleep 4
    exit 1
  fi

OpClose(){
  echo -e "Please Choose an Option"
  sleep 4
  exit 1
}
  clear
  echo -e "Please choose an Option to Execute after emerge"
  echo -e "s or S = Shutdown"
  echo -e "r or R = Reboot"
  read Option
#Real Nasty here, Could not get "Or" to work ;-(
  export Valid="FALSE"
  if [ $Option == "r" ]; then
    export Valid="TRUE"
  fi
  if [ $Option == "R" ]; then
    export Valid="TRUE"
  fi
  if [ $Option == "s" ]; then
    export Valid="TRUE"
  fi
  if [ $Option == "S" ]; then
    export Valid="TRUE"
  fi
  if [ $Valid = "FALSE" ]; then
    OpClose
  fi

ConClose(){
  echo -e "Please use Y for Yes and N for No"
  sleep 4
  exit 1
}
  clear
  echo -e "Confirm Emerge and Options"
  echo -e "E-Build: $EBuild" 
  echo -e "Option: $Option" 
  echo -e "Continue Y or N"
  read Confirm
  export Valid="FALSE"
  if [ $Confirm == "" ]; then
    export Valid="TRUE"
  fi 
  if [ $Confirm != "Y" ]; then 
    export Valid="TRUE" 
  fi
  if [ $Confirm != "y" ]; then
    export Valid="TRUE"
  fi
  if [ $Confirm != "N" ]; then
    export Valid="TRUE"
  fi
  if [ $Confirm != "n" ]; then
    export Valid="TRUE"
  fi
  if [ $Valid = "FALSE" ]; then
    ConClose
  fi

  export Yes="FALSE"
  if [ $Confirm == "Y" ]; then
    export Yes="TRUE"
  fi
  if [ $Confirm == "y" ]; then
    export Yes="TRUE"
  fi
  if [ $Yes == "TRUE" ]; then
    echo -e "SMERGING, Please Stand By"
    sleep 2
    clear
    emerge $EBuild
    export Op="R"
    if [ $Option == "r" ]; then
      export Op="R" 
    fi
    if [ $Option == "R" ]; then
      export Op="R"
    fi
    if [ $Op == "R" ]; then
      reboot
      exit 1
    else
      halt
      exit 1
    fi
  else
    exit 1
  fi 

Posted: Tue Feb 24, 2004 8:14 am
by nobspangle
intresting,
why would you want to reboot or shutdown after emerging anything, what happens when the emerge fails and you've selected shutdown, you come back load your box up and it doesn't work, and you've got no idea why.

and a reboot is even more pointless as I've not found a situation (apart from a kernel upgrade) where you have to reboot a linux box.

Posted: Tue Feb 24, 2004 10:00 am
by Code-X
I Done it for learning mainly,
Reboot is kind of pointless but a shutdown after emerge would be helpful. I don't want to wait until an emerge finishes to shutdown after, So this does it for me, so i can leave it do to its thing :D

Posted: Tue Feb 24, 2004 1:29 pm
by rocketeer
It's not a Perl script. It's a bash script.

Posted: Tue Feb 24, 2004 1:37 pm
by Code-X
Opp's, My mistake :oops: .
Still learning Linux, :D, Hopefull i can fix this now i know what script it is.

Posted: Tue Feb 24, 2004 6:28 pm
by ShALLaX
Still, why would you want to shutdown? Also.. why wouldnt you just "emerge blah && shutdown" ?

Posted: Tue Feb 24, 2004 6:33 pm
by Code-X
Learning, Make it as complex as possible to learn as much as possible :D