My Perl Script

Talk about anything related to Gentoox or Gentoo.
Post Reply
Code-X
Novice
Posts: 36
Joined: Tue Jan 27, 2004 11:36 pm
Location: UK
Contact:

My Perl Script

Post by Code-X » Tue Feb 24, 2004 1:04 am

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 
Last edited by Code-X on Tue Feb 24, 2004 4:36 pm, edited 1 time in total.
Code The Future

User avatar
nobspangle
Gentoox Guru!
Posts: 1681
Joined: Sun Sep 28, 2003 11:59 am
Location: Manchester, UK

Post by nobspangle » Tue Feb 24, 2004 8:14 am

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.
If you keep an open mind, will your brain fall out?

Code-X
Novice
Posts: 36
Joined: Tue Jan 27, 2004 11:36 pm
Location: UK
Contact:

Post by Code-X » Tue Feb 24, 2004 10:00 am

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
Code The Future

User avatar
rocketeer
Pro
Posts: 75
Joined: Sun Aug 17, 2003 12:05 am

Post by rocketeer » Tue Feb 24, 2004 1:29 pm

It's not a Perl script. It's a bash script.

Code-X
Novice
Posts: 36
Joined: Tue Jan 27, 2004 11:36 pm
Location: UK
Contact:

Post by Code-X » Tue Feb 24, 2004 1:37 pm

Opp's, My mistake :oops: .
Still learning Linux, :D, Hopefull i can fix this now i know what script it is.
Code The Future

User avatar
ShALLaX
Site Admin
Posts: 1973
Joined: Sun Aug 10, 2003 9:25 pm
Location: England
Contact:

Post by ShALLaX » Tue Feb 24, 2004 6:28 pm

Still, why would you want to shutdown? Also.. why wouldnt you just "emerge blah && shutdown" ?
The original Xbox adaptation of Gentoo

Code-X
Novice
Posts: 36
Joined: Tue Jan 27, 2004 11:36 pm
Location: UK
Contact:

Post by Code-X » Tue Feb 24, 2004 6:33 pm

Learning, Make it as complex as possible to learn as much as possible :D
Code The Future

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest