Thursday, March 19, 2015

solaris 10 zone creation script

i love you, too.
 #!/usr/bin/perl  
    
 # default values  
 $basedir="/opt/zones";  
    
 system(clear);  
    
 print "\nsol 10 zone creation script\n";  
 print "\n............................\n\n";  
 print "\nnote: base directory is $basedir \n";  
   
 print "\nenter name of new zone ";  
    
 $newzone = <STDIN>;  
   
 chomp($newzone);  
    
 print "\nenter directory name for new zone [$newzone] ";  
 $zonedir = <STDIN>;  
   
 chomp($zonedir);  
    
 if (!$zonedir) {  
  $zonedir = $newzone;  
    
 }  
    
 print "enter zone ip address ";  
 $newip = <STDIN>;  
    
 chomp($newip);  
    
 print "\nenter shared physical ethernet interface [e.g. e1000g0] ";  
 $ethint = <STDIN>;  
    
 chomp($ethint);  
    
 print "\ninherit standard directories (lib, platform, sbin, usr) from the global zone? [yN] ";  
 $inh = <STDIN>;  
    
 chomp($inh);  
 if (!$inh) {  
    
  $inh = "n";  
 }  
    
 if (($inh eq "y") || ($inh eq "Y")) {  
  $isw = "1";  
    
 } else {  
  $isw = "0";  
    
 }  
   
 print "\nadd dedicated cpu? [yN] ";  
 $dedicatedcpu = <STDIN>;  
    
 chomp($dedicatedcpu);  
 if (!$dedicatedcpu) {  
    
  $inh = "n";  
 }  
    
 if (($dedicatedcpu eq "y") || ($dedicatedcpu eq "Y")) {  
  $dedicatedcpu = "1";  
    
 } else {  
  $dedicatedcpu = "0";  
    
 }   
    
 print "\n\npsummary:\n\n";  
 print "   zone name: $newzone\n";  
    
 print "   zone directory: $zonedir\n";  
 print "   zone ip address: $newip\n";  
    
 print "   ethernet interface: $ethint\n";  
 print "   inherit directories: $inh\n";  
 print "   dedicated cpu: $dedicatedcpu\n";  
    
 print "\nare these entries correct? [Yn] ";  
    
 $yn = <STDIN>;  
 chomp($yn);  
    
 if (!$yn) { $yn = "y"; }  
 if (($yn == "y") || ($yn == "Y")) {  
    
  $of = "/tmp/zccfs10.tmp";  
    
  # create the zonecfg input file  
    
  `echo "create -b" > $of`;  
  `echo "set zonepath=$basedir/$zonedir" >> $of`;  
    
  `echo "set autoboot=true" >> $of`;  
    
  if ($isw == "1") {  
    
   `echo "add inherit-pkg-dir" >> $of`;  
   `echo "set dir=/lib" >> $of`;  
    
   `echo "end" >> $of`;  
   `echo "add inherit-pkg-dir" >> $of`;  
    
   `echo "set dir=/platform" >> $of`;  
   `echo "end" >> $of`;  
    
   `echo "add inherit-pkg-dir" >> $of`;  
   `echo "set dir=/sbin" >> $of`;  
    
   `echo "end" >> $of`;  
   `echo "add inherit-pkg-dir" >> $of`;  
    
   `echo "set dir=/usr" >> $of`;  
   `echo "end" >> $of`;  
    
  }  
    
  `echo "add net" >> $of`;  
  `echo "set address=$newip" >> $of`;  
  `echo "set physical=$ethint" >> $of`;  
  `echo "end" >> $of`;  
   
  if ($dedicatedcpu == "1") {  
    
   `echo "add dedicated-cpu" >> $of`;  
   `echo "set ncpus=1" >> $of`;  
   `echo "end" >> $of`;  
    
  }  
    
  # Make the dir that the zone will live in  
  `mkdir $basedir/$zonedir`;  
   
  # because sun is a punkass   
  `chmod 700 $basedir/$zonedir`;  
    
  # make me happy  
  print "\npatience patience \n";  
    
  `zonecfg -z $newzone -f $of`;  
  print "configuration file templatized\n";  
    
  # zone install  
  print "go get a cup of coffee \n";  
  `zoneadm -z $newzone install`;  
  print "zone installation complete\n";  
    
  # boot newly created zone  
  print "zone boot \n";  
    
  `zoneadm -z $newzone boot`;  
  print "booted\n";  
    
  # remove configuration file  
  `rm $of`;  
    
  print "\nconnect to the virtual console and complete installation \n";  
  print " -> zlogin -C -e\\@ $newzone \n";  
    
 } else {  
    
  die("ffs there is an error\n");  
 }  

No comments: