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 »

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
nobspangle
Gentoox Guru!
Posts: 1681
Joined: Sun Sep 28, 2003 11:59 am
Location: Manchester, UK

Post 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.
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 »

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
rocketeer
Pro
Posts: 75
Joined: Sun Aug 17, 2003 12:05 am

Post by rocketeer »

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 »

Opp's, My mistake :oops: .
Still learning Linux, :D, Hopefull i can fix this now i know what script it is.
Code The Future
ShALLaX
Site Admin
Posts: 1973
Joined: Sun Aug 10, 2003 9:25 pm
Location: England
Contact:

Post by ShALLaX »

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 »

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