View previous topic :: View next topic |
Author |
Message |
sr20seth n00b
Joined: 04 Nov 2003 Posts: 55 Location: Carrollton, VA
|
Posted: Fri Dec 12, 2003 5:23 am Post subject: GRIS (Gentoo Router Install Script) |
|
|
Hello all, below I have included my first perl script. I install quite a few linux routers and thought the script might be useful to others. I don't claim that everything in it works, but it seems to work for me. The purpose of this script is to install a gentoo router, it may work for other things, but this was my goal. When I get the chance I would like to get the script to put defaults into shorewall, bind, and squid to make a working firewall, transparent proxy, and dns caching server out of the box. This script requires booting from knoppix, as the LiveCD does not seem to include perl. Please either email me or post here if you have any good/bad experiences with the script. Since I am installing to mostly PII's I haven't done much testing yet. Enough talking, here is the script:
EDIT*:*: I fixed a few formatting errors. Also I am currently trying to track down a bug, so I have added a logging feature.
Code: | #!/usr/bin/perl
# GRIS (Gentoo Router Install Script)
# Version 0.1.7
# Written by Chris Busillo
# Released to public on 12/12/03
# Please contact me via chris@cksystem.com to suggest changes
# Boot of off Knoppix to use the script. The LiveCD does not include perl
$LOG="/log"; #/dev/null for no logs; also this location must exist in both the chroot and the real drive.
$TMPDIR="/root";
system("clear");
open(LFTP,">$TMPDIR/lftp");
print LFTP "ls";
close(LFTP);
print "Hostname?([host]): ";
$HOST = <STDIN>;
chop $HOST;
if ($HOST eq "")
{
$HOST = "host";
}
print "Domain name?([domain]): ";
$DOMAIN = <STDIN>;
chop $DOMAIN;
if ($DOMAIN eq "")
{
$DOMAIN = "host";
}
print "Root password?([1234]): ";
$PASSWD = <STDIN>;
chop $PASSWD;
if ($PASSWD eq "")
{
$PASSWD = "1234";
}
print "How many interfaces?([1]): ";
$IF = <STDIN>;
chop $IF;
if ($IF eq "")
{
$IF = "1";
}
for ($i = 0; $i< $IF; $i++)
{
print "IP of interface $i([dhcp]): ";
$IFIP = <STDIN>;
chop @IFIP[$i];
if (@IFIP[$i] eq "")
{
@IFIP[$i] = dhcp;
}
push(@IFIP,$IFIP);
print "BC of interface $i([dhcp]): ";
$IFBC = <STDIN>;
chop @IFBC[$i];
if (@IFBC[$i] eq "")
{
@IFBC[$i] = dhcp;
}
push(@IFBC,$IFBC);
print "Subnet of interface $i([dhcp]): ";
$IFSN = <STDIN>;
chop @IFSN[$i];
if (@IFSN[$i] eq "")
{
@IFSN[$i] = dhcp;
}
push(@IFSN,$IFSN);
}
print "What is the gateway?([dhcp],ethx/\$IP): ";
$IFGW = <STDIN>;
chop $IFGW;
if ($IFGW eq "")
{
$IFGW = "dhcp";
}
$SQUID = 1;
while ($SQUID ne "n" && $SQUID ne "y" && $SQUID ne "")
{
print "Squid?([y],n): ";
$SQUID = <STDIN>;
chop $SQUID;
}
if ($SQUID eq "")
{
$SQUID = "y";
}
$WEB = 1;
while ($WEB ne "n" && $WEB ne "y" && $WEB ne "")
{
print "Web-based admin?([y],n): ";
$WEB = <STDIN>;
chop $WEB;
}
if ($WEB eq "")
{
$WEB = "y";
}
$SHORE = 1;
while ($SHORE ne "n" && $SHORE ne "y" && $SHORE ne "")
{
print "Shorewall?([y],n): ";
$SHORE = <STDIN>;
chop $SHORE;
}
if ($SHORE eq "")
{
$SHORE = "y";
}
$BIND = 1;
while ($BIND ne "n" && $BIND ne "y" && $BIND ne "")
{
print "Bind?([y],n): ";
$BIND = <STDIN>;
chop $BIND;
}
if ($BIND eq "")
{
$BIND = "y";
}
$PARTITION = 1;
while ($PARTITION ne "n" && $PARTITION ne "y" && $PARTITION ne "")
{
print "Repartition?([y],n): ";
$PARTITION = <STDIN>;
chop $PARTITION;
}
if ($PARTITION eq "")
{
$PARTITION = "y";
}
$FORMAT = 1;
while ($FORMAT ne "n" && $FORMAT ne "y" && $FORMAT ne "")
{
print "Reformat?([y],n): ";
$FORMAT = <STDIN>;
chop $FORMAT;
}
if ($FORMAT eq "")
{
$FORMAT = "y";
}
$STAGEI = -1;
while ($STAGEI ne "1" && $STAGEI ne "2" && $STAGEI ne "3" && $STAGEI ne "4" && $STAGEI ne "")
{
print "Which Stage Install (4=updated stage 3)?([1],2,3,4): ";
$STAGEI = <STDIN>;
chop $STAGEI;
}
if ($STAGEI eq "")
{
$STAGEI = "1";
}
$PROC = 1;
while ($PROC ne "athlon-xp" && $PROC ne "i686" && $PROC ne "pentium3" && $PROC ne pentium4 && $PROC ne "x86" && $PROC ne "")
{
print "Which Processor stage image?([x86],athlon-xp, i686, pentium3, pentium4): ";
$PROC = <STDIN>;
chop $PROC;
}
if ($PROC eq "")
{
$PROC = "x86";
}
$PROCCFLAG = -1;
print "Which Processor?([pentium2]): ";
$PROCCFLAG = <STDIN>;
chop $PROCCFLAG;
if ($PROCCFLAG eq "")
{
$PROCCFLAG = "pentium2";
}
$XFREE = 1;
while ($XFREE ne "n" && $XFREE ne "y" && $XFREE && $XFREE ne "")
{
print "Install X?([n],y): ";
$XFREE = <STDIN>;
chop $XFREE;
}
if ($XFREE eq "y" || $XFREE eq "Y")
{
$XFREEUSE = "3dfx dga gtk gtk2 matrox opengl qt radeon tcltk X";
}
else
{
$XFREEUSE = "-3dfx -dga -gnome -gtk -gtk2 -kde -matrox -opengl -qt -radeon -tcltk -X";
}
if ($PARTITION eq "y")
{
print "Creating Partitions";
open(PART,">$TMPDIR/part");
print PART "d\n1\nd\n2\nd\n3\nd\n4\nn\np\n1\n\n+32M\nn\np\n2\n\n+512M\nt\n2\n82\nn\np\n3\n\n\nw\n";
close(PART);
system(`fdisk /dev/hda < $TMPDIR/part >> $LOG 2>&1`);
print "\t\t\t\t[DONE]\n";
system("rm $TMPDIR/part >> $LOG 2>&1");
}
if ($FORMAT eq "y")
{
print "Formatting Partitions";
system(`mke2fs -j /dev/hda1 >> $LOG 2>&1`);
system(`mke2fs -j /dev/hda3 >> $LOG 2>&1`);
system(`mkswap /dev/hda2 >> $LOG 2>&1`);
system(`tune2fs -c -1 -i 0 /dev/hda1 >> $LOG 2>&1`);
system(`tune2fs -c -1 -i 0 /dev/hda3 >> $LOG 2>&1`);
system(`swapon /dev/hda2 >> $LOG 2>&1`);
print "\t\t\t\t[DONE]\n";
}
print "Mounting Partitions";
system("mkdir /mnt/gentoo >> $LOG 2>&1");
system(`mount /dev/hda3 /mnt/gentoo >> $LOG 2>&1`);
system("mkdir /mnt/gentoo/boot >> $LOG 2>&1");
system(`mount /dev/hda1 /mnt/gentoo/boot >> $LOG 2>&1`);
print "\t\t\t\t[DONE]\n";
print "Wgetting Stage image";
system(`lftp http://gentoo.oregonstate.edu/releases/x86/1.4/stages/$PROC < $TMPDIR/lftp > $TMPDIR/stages`);
open(STAGES,"$TMPDIR/stages");
@_=<STAGES>;
system(`rm $TMPDIR/lftp >> $LOG 2>&1`);
foreach $i (@_)
{
$_=$i;
if (/bz2$/ && /stage$STAGEI/)
{
/(stage$STAGEI.+bz2)/;
chdir "/mnt/gentoo";
system(`wget -c http://gentoo.oregonstate.edu/releases/x86/1.4/stages/$PROC/$1 >> $LOG 2>&1`);
print "\t\t\t\t[DONE]\n";
print "Untarbzip2ing Stage image";
system(`tar -xvjpf $1`);
system(`rm $1`);
print "\t\t\t[DONE]\n";
}
}
close(STAGES);
system(`rm $TMPDIR/stages >> $LOG 2>&1`);
print "Chrooting";
system(`mount -t proc /proc /mnt/gentoo/proc >> $LOG 2>&1`);
system(`cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf`);
chroot "/mnt/gentoo";
chdir "/";
system(`env-update >> $LOG 2>&1`);
system(`source /etc/profile `);
print "\t\t\t\t\t[DONE]\n";
print "Updating Portage Tree";
system(`emerge rsync >> $LOG 2>&1`);
print "\t\t\t\t[DONE]\n";
open(MAKE,">/etc/make.conf");
$USE="aalib acpi -alsa -apache2 apm -arts -avi -cdr crypt -cups -directfb -dvd -emacs -encode -esd -fam -fbcon gif -gnome gpm -imlib java jpeg -kde -mpeg mmx ncurses -oggvorbis -oss perl png pnp python -sdl -spell sse ssl svga";
$_=$PROCCFLAG;
$DNOW = "";
if (/athlon/i)
{
$DNOW="3dnow";
}
else
{
$DNOW="-3dnow";
}
print MAKE "USE=\"$USE $XFREEUSE $DNOW\"\n";
print MAKE "CHOST=\"i686-pc-linux-gnu\"\n";
print MAKE "CFLAGS=\"-O2 -march=$PROCCFLAG -pipe -ffast-math -fomit-frame-pointer\"\n";
print MAKE "CXXFLAGS=\"-O2 -march=$PROCCFLAG -pipe -ffast-math -fomit-frame-pointer\"\n";
print MAKE "ACCEPT_KEYWORDS=\"x86\"\n";
print MAKE "PORTAGE_TMPDIR=\"/var/tmp\"\n";
print MAKE "PORTDIR=\"/usr/portage\"\n";
print MAKE "DISTDIR=\"\${PORTDIR}/distfiles\"\n";
print MAKE "PKDIR=\"\${PORTDIR}/packages\"\n";
print MAKE "PORTDIR_OVERLAY=\"/usr/local/portage\"\n";
print MAKE "MAKEOPTS=\"-j2\"\n";
print MAKE "AUTOCLEAN=\"yes\"\n";
close(MAKE);
system("mkdir /usr/local/portage >> $LOG 2>&1");
if ($STAGEI eq "1")
{
print "Bootstrapping";
chdir "/usr/portage >> $LOG 2>&1";
system("/usr/portage/scripts/bootstrap.sh >> $LOG 2>&1");
print "\t\t\t\t\t[DONE]\n";
}
if ($STAGEI eq "1" || STAGEI eq "2")
{
print "Building System";
system("emerge system >> $LOG 2>&1");
print "\t\t\t\t\t[DONE]\n";
}
if ($STAGEI eq "4")
{
print "Updating System";
system("emerge -UD system >> $LOG 2>&1");
print "\t\t\t\t[DONE]\n";
}
system("ln -sf /usr/share/zoneinfo/EST /etc/localtime >> $LOG 2>&1");
open(FSTAB,"/etc/fstab");
print FSTAB "/dev/hda1 /boot ext3 noauto,noatime 1 2";
print FSTAB "/dev/hda2 none swap noauto 0 0";
print FSTAB "/dev/hda3 / ext3 noauto,noatime 1 2";
print FSTAB "none /proc proc defaults 0 0";
print FSTAB "none /dev/shm tmpfs defaults 0 0";
close(FSTAB);
print "Emerging kernel";
system("emerge gentoo-sources >> $LOG 2>&1");
print "\t\t\t\t\t[DONE]\n";
print "Building kernel";
open(KERN,">$TMPDIR/kern");
print KERN "n\n";
close(KERN);
system("emerge genkernel >> $LOG 2>&1");
system("genkernel >> $LOG 2>&1");
chdir "/usr/src/linux";
system("make install < $TMPDIR/kern >> $LOG 2>&1");
system("rm $TMPDIR/kern >> $LOG 2>&1");
print "\t\t\t\t\t[DONE]\n";
print "Installing PnP";
system("emerge hotplug >> $LOG 2>&1");
system("rc-update add hotplug default >> $LOG 2>&1");
print "\t\t\t\t\t[DONE]\n";
print "Installing system services";
system("emerge syslog-ng >> $LOG 2>&1");
system("rc-update add syslog-ng default >> $LOG 2>&1");
system("emerge vcron >> $LOG 2>&1");
system("rc-update add vcron default >> $LOG 2>&1");
print "\t\t\t[DONE]\n";
print "Setup Networking";
open(PASSWD,">$TMPDIR/pass");
print PASSWD "$PASSWD\n$PASSWD\n";
close(PASSWD);
system("passwd <$TMPDIR/pass >> $LOG 2>&1");
system("rm $TMPDIR/pass >> $LOG 2>&1");
system("echo $HOST > /etc/hostname");
system("echo $DOMAIN > /etc/dnsdomainname >> $LOG 2>&1");
system("rc-update add domainname default >> $LOG 2>&1");
system("echo \"\n@IFIP[0] $HOST.$DOMAIN $HOST\" >> /etc/hosts");
open(NET,">/etc/conf.d/net");
$COUNTER = 0;
foreach $i ($IFIP)
{
if ($i eq "dhcp")
{
print NET "iface_eth$COUNTER=\"dhcp\"\n";
}
else
{
print NET "iface_eth$COUNTER=\"@IFIP[$COUNTER] broadcast @IFBC[$COUNTER] netmask @IFSN[$COUNTER]\"\n";
}
$COUNTER++;
}
if ($IFGW ne "dhcp")
{
print NET "gateway=\"$IFGW\"\n";
}
close(NET);
for ($i = 1; $i < $IF; $i++)
{
system("ln -s /etc/init.d/net.eth0 /etc/init.d/net.eth$i");
}
for ($i = 0;$i < $IF; $i++)
{
system("rc-update add net.eth$i default");
}
print "\t\t\t\t\t[DONE]\n";
print "Installing bootloader";
system("emerge grub >> $LOG 2>&1");
open(GRUB,">$TMPDIR/grubs");
print GRUB 'root (hd0,0)\nsetup (hd0)\nquit\n';
close(GRUB);
system("grub < $TMPDIR/grubs >> $LOG 2>&1");
system("rm $TMPDIR/grubs >> $LOG 2>&1");
open(GRUB, ">/boot/grub/grub.conf");
print GRUB << "EOF";
default 0
timeout 5
title $hostname Linux
root (hd0,0)
kernel (hd0,0)/vmlinuz root=/dev/hda3
EOF
print "\t\t\t\t[DONE]\n";
if ($XFREE eq "y")
{
print "Installing enlightenment";
system("emerge enlightenment >> $LOG 2>&1");
print "\t\t\t[DONE]\n";
}
if ($WEB eq "y")
{
print "Installing webmin";
system("emerge webmin >> $LOG 2>&1");
system("rc-update add webmin default >> $LOG 2>&1");
print "\t\t\t\t[DONE]\n";
}
if ($SHORE eq "y")
{
print "Installing shorewall";
system("emerge shorewall >> $LOG 2>&1");
system("rc-update add shorewall default >> $LOG 2>&1");
print "\t\t\t\t[DONE]\n";
}
if ($SQUID eq "y")
{
print "Installing squid";
system("emerge squid >> $LOG 2>&1");
system("rc-update add squid default >> $LOG 2>&1");
print "\t\t\t\t[DONE]\n";
}
if ($BIND eq "y")
{
print "Installing bind";
system("emerge bind >> $LOG 2>&1");
system("rc-update add named default >> $LOG 2>&1");
print "\t\t\t\t[DONE]\n";
}
system("etc-update");
system("exit");
system("umount /mnt/gentoo/boot >> $LOG 2>&1");
system("umount /mnt/gentoo/proc >> $LOG 2>&1");
system("umount /mnt/gentoo >> $LOG 2>&1");
|
Last edited by sr20seth on Thu Dec 18, 2003 2:35 pm; edited 4 times in total |
|
Back to top |
|
|
carambola5 Apprentice
Joined: 10 Jul 2002 Posts: 214
|
Posted: Fri Dec 12, 2003 3:28 pm Post subject: |
|
|
methinks you can grab the CPU type from /proc/cpuinfo
one less step to worry about |
|
Back to top |
|
|
sr20seth n00b
Joined: 04 Nov 2003 Posts: 55 Location: Carrollton, VA
|
Posted: Fri Dec 12, 2003 3:30 pm Post subject: |
|
|
I thought about that, but I didnt know if the info from proc/cpuinfo matched up with cflags. |
|
Back to top |
|
|
sr20seth n00b
Joined: 04 Nov 2003 Posts: 55 Location: Carrollton, VA
|
Posted: Thu Dec 18, 2003 2:34 pm Post subject: |
|
|
I just wanted to update anyone interested. I am currently testing in a vmware machine, so i can do a full install (-X) in under 8 hours. I have worked out most of the bugs. I get an installed system. I cannot figure out how to set the passwd though, maybe someone can help with that. Also I need help in setting up a few config files. I want to add a few lines to shorewall and squid. If no one is interested in this I will stop posting and updating, and just use it in-house like I was planning originally. I figured there might be someone out there that would benefit from this. |
|
Back to top |
|
|
dol-sen Retired Dev
Joined: 30 Jun 2002 Posts: 2805 Location: Richmond, BC, Canada
|
Posted: Sun Dec 21, 2003 11:52 pm Post subject: |
|
|
When you get the bugs fixed post it in documentation, tips & tricks. I am sure that others would find it usefull. I may be creating a new firewall/router with a DMZ again soon. I don't much care for the linksys wireless gateway I am using at the moment. I liked the logging available from linux, snort. _________________ Brian
Porthole, the Portage GUI frontend irc@freenode: #gentoo-guis, #porthole, Blog
layman, gentoolkit, CoreBuilder, esearch... |
|
Back to top |
|
|
sr20seth n00b
Joined: 04 Nov 2003 Posts: 55 Location: Carrollton, VA
|
Posted: Mon Dec 22, 2003 1:20 pm Post subject: |
|
|
Thanks, my life has been hectic lately. As soon as I get some free time, I will work out the last 2 bugs. I will also add functunality, so that after the install shorewall, named, and squid will work without fuss. Also I will prolly add portsentry and snort to the list of available programs. |
|
Back to top |
|
|
etnoy Apprentice
Joined: 29 Aug 2003 Posts: 255 Location: Västerås, Sweden
|
Posted: Tue Dec 23, 2003 12:40 am Post subject: |
|
|
No...Please!
"Gris" in swedish translates to "Pig" _________________ The md5sum of the above post is 06280ccd85ef9deb49c336e7945f4b5c
God is dead! - Nietzsche
Nietzsche is dead! -God |
|
Back to top |
|
|
Lovechild Advocate
Joined: 17 May 2002 Posts: 2858 Location: Århus, Denmark
|
Posted: Tue Dec 23, 2003 12:53 am Post subject: |
|
|
as well as it danish... you little piggy..
You might want to roll this onto a livecd with Catalyst once its ready.
ps.
is it the forums or do you not like indentation very much? |
|
Back to top |
|
|
etnoy Apprentice
Joined: 29 Aug 2003 Posts: 255 Location: Västerås, Sweden
|
Posted: Tue Dec 23, 2003 8:55 am Post subject: |
|
|
Nah, I said it about the name. Nothing wrong with either the forums, the idea or the script. _________________ The md5sum of the above post is 06280ccd85ef9deb49c336e7945f4b5c
God is dead! - Nietzsche
Nietzsche is dead! -God |
|
Back to top |
|
|
frippz Guru
Joined: 22 Aug 2002 Posts: 460 Location: Sweden
|
Posted: Tue Dec 23, 2003 9:01 am Post subject: |
|
|
First thought that struck me as well...
About indentation; it should work while inside the code-brackets, just like he has done here. So I'm guessing sr20seth doesn't like indentation very much. |
|
Back to top |
|
|
geoffwa n00b
Joined: 05 Nov 2003 Posts: 6 Location: AU
|
Posted: Wed Dec 24, 2003 12:02 am Post subject: |
|
|
Is USE="java" really necessary for a router? It does pad out the bootstrapping time considerably...
Otherwise it's quite neat |
|
Back to top |
|
|
sr20seth n00b
Joined: 04 Nov 2003 Posts: 55 Location: Carrollton, VA
|
Posted: Thu Dec 25, 2003 2:35 pm Post subject: |
|
|
hey guys. Like I said in the 1st post, this is my first real perl script, so I indented like I though I should. I will probally take java out of the use statement.
I like my GRIS! It reminds me of grits, and i miss me some grits.
Does someone want to point me to a link that shows proper indentation?
I will try to finish this up by the new year, and post it in tips a tricks. Like I said earlier, if anyone wants to suggest code or other things, be my guest. |
|
Back to top |
|
|
Instinct82 n00b
Joined: 16 Aug 2003 Posts: 42 Location: Trier, Germany
|
Posted: Sat Jan 10, 2004 5:52 pm Post subject: |
|
|
Is there any reason why you are using gentoo-sources as kernel-sources, which contain many improvments for desktop systems?
No offense here - I am looking for the right sources for my router which is running gs-sources ATM but they are missing the h323 connection tracking patch.
Maybe I'll try 2.6.1 sources because of the option to remove features for embedded systems. _________________ my gentoo boxes
Desktop:
AMD Athlon XP 2000+
512MB DDR
GeForce3 Ti200
Samsung SyncMaster 193T
Laptop:
Asus M6800N 1,5GHz
768MB DDR
Radeon 9600 Mobility
Router:
Intel Pentium 90, 128MB RAM, True Headless |
|
Back to top |
|
|
sr20seth n00b
Joined: 04 Nov 2003 Posts: 55 Location: Carrollton, VA
|
Posted: Sat Jan 10, 2004 8:00 pm Post subject: |
|
|
no reason. I am currently running 2.6 on my router. I havent had any free time from work lately. Im sure the script is only in a half working state right now anyway. Oh well. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|