Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support Us

Top Posters

Gentoo auto installer script

dragonkeeperdragonkeeper Banned
edited February 2016 in Gentoo Linux
This is an attempt at automating the 1st stage of gentoo install (up to allowing boot)


This post is the 1st Script - named: Host-Script
#!/bin/bash
file="/mnt/gentoo/stage3-*.tar.bz2"
####################iknow all arent needed in both parts but wth c+p
dragon_tmp=./configuration
USER1=`head -1 $dragon_tmp | tail -1`
SHELL1=`head -2 $dragon_tmp | tail -1`
HOSTNAME1=`head -3 $dragon_tmp | tail -1`
HDD1=`head -4 $dragon_tmp | tail -1`
HDD2=`head -5 $dragon_tmp | tail -1`
KEYMAP=`head -6 $dragon_tmp | tail -1`
TIMEZONE=`head -7 $dragon_tmp | tail -1`
GRUBVER=`head -8 $dragon_tmp | tail -1`
DUALBOOT=`head -9 $dragon_tmp | tail -1`
LINHDD=`head -10 $dragon_tmp | tail -1`
LINPART=`head -11 $dragon_tmp | tail -1`
WINHDD=`head -12 $dragon_tmp | tail -1`
WINPART=`head -13 $dragon_tmp | tail -1`
SWAP=`head -14 $dragon_tmp | tail -1`
MAKEJOBS=`head -15 $dragon_tmp | tail -1`
MANUALCONFIG=`head -16 $dragon_tmp | tail -1`
EXTRABOOTOP=`head -17 $dragon_tmp | tail -1`
USEFLAGS=`head -18 $dragon_tmp | tail -1`


#####################################################

mkdir /mnt/gentoo
mv ./configuration ./Chroot-Script /mnt/gentoo
chmod +x /mnt/gentoo/Chroot-Script
cd /mnt/gentoo
wget http://www.mirrorservice.org/sites/distfiles.gentoo.org/releases/amd64/autobuilds/current-stage3-amd64/stage3-amd64-20141204.tar.bz2
echo "-----------------------------"
echo "checking if file downloaded"
sleep 10
if [ -f "$file" ]
then
	echo "downloaded"
else
	clear
	echo "file did not download please get it manually : http://www.mirrorservice.org/sites/distfiles.gentoo.org/releases/amd64/autobuilds/current-stage3-amd64/ "
	exit
fi

cd /mnt/gentoo/
tar xvjpf stage3-*.tar.bz2
echo 'CFLAGS="-O2 -pipe"' > /mnt/gentoo/etc/portage/make.conf
echo 'CXXFLAGS="${CFLAGS}"' >> /mnt/gentoo/etc/portage/make.conf
echo -n 'MAKEOPTS=-j'$MAKEJOBS >> /mnt/gentoo/etc/portage/make.conf 
echo 'CHOST="x86_64-pc-linux-gnu"' >> /mnt/gentoo/etc/portage/make.conf
echo 'ACCEPT_LICENSE="*"' >> /mnt/gentoo/etc/portage/make.conf
echo -n 'USE='  >> /mnt/gentoo/etc/portage/make.conf
echo $USEFLAGS >> /mnt/gentoo/etc/portage/make.conf
echo 'PORTDIR="/usr/portage"' >> /mnt/gentoo/etc/portage/make.conf
echo 'DISTDIR="${PORTDIR}/distfiles"' >> /mnt/gentoo/etc/portage/make.conf
echo 'PKGDIR="${PORTDIR}/packages"' >> /mnt/gentoo/etc/portage/make.conf
cp -L /etc/resolv.conf /mnt/gentoo/etc/
cd 
mount -t proc proc /mnt/gentoo/proc ; mount --rbind /sys /mnt/gentoo/sys ; mount --rbind /dev /mnt/gentoo/dev
clear
echo " LOADING CHROOT.  RUN /Chroot-Script"
chroot /mnt/gentoo /bin/bash
[hr]
This Post is the Script to run in chroot

named: Chroot-Script


#!/bin/bash
######2nd script

dragon_tmp=./configuration
USER1=`head -1 $dragon_tmp | tail -1`
SHELL1=`head -2 $dragon_tmp | tail -1`
HOSTNAME1=`head -3 $dragon_tmp | tail -1`
HDD1=`head -4 $dragon_tmp | tail -1`
HDD2=`head -5 $dragon_tmp | tail -1`
KEYMAP=`head -6 $dragon_tmp | tail -1`
TIMEZONE=`head -7 $dragon_tmp | tail -1`
GRUBVER=`head -8 $dragon_tmp | tail -1`
DUALBOOT=`head -9 $dragon_tmp | tail -1`
LINHDD=`head -10 $dragon_tmp | tail -1`
LINPART=`head -11 $dragon_tmp | tail -1`
WINHDD=`head -12 $dragon_tmp | tail -1`
WINPART=`head -13 $dragon_tmp | tail -1`
SWAP=`head -14 $dragon_tmp | tail -1`
MAKEJOBS=`head -15 $dragon_tmp | tail -1`
MANUALCONFIG=`head -16 $dragon_tmp | tail -1`
EXTRABOOTOP=`head -17 $dragon_tmp | tail -1`
USEFLAGS=`head -18 $dragon_tmp | tail -1`


#####################################################

source /etc/profile
export PS1="(chroot) $PS1"
emerge-webrsync
emerge --sync
PROFILESET=$(eselect profile list | grep desktop | awk 'NR==1{ print $1 }' | grep -o '[0-9]\+')
eselect profile set $PROFILESET
echo "$TIMEZONE" > /etc/timezone
emerge --config sys-libs/timezone-data
echo "en_GB ISO-8859-1" >> /etc/locale.gen
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
LOCALESET=$(eselect locale list | grep en_GB.iso88591 | sed s/en_GB.iso88591//g | awk 'NR==1{ print $1 }' |  grep -o '[0-9]\+')
eselect locale set $LOCALESET
env-update && source /etc/profile
emerge gentoo-sources
cd /usr/src/linux
if [ $MANUALCONFIG == 1 ];then
make menuconfig
else
mv /.config .
fi
make 
make modules_install
make install
emerge genkernel
genkernel --install initramfs
mv /boot/initramfs* /boot/initramfs
mv /boot/vmlinuz* /boot/kernel
mv /boot/kernel* /boot/kernel
echo -n $HDD1 > /etc/fstab
echo "  /  ext4  noatime,rw  0 1" >> /etc/fstab
echo -n $SWAP >> /etc/fstab
echo "  none  swap  sw  0 0" >> /etc/fstab
echo "/dev/sr0  /media/cdrom  udf,iso9660  noauto,ro,group,users,noexec  0 0" >> /etc/fstab
echo"tmpfs  /dev/shm  tmpfs  defaults  0 0" >> /etc/fstab
echo hostname="$HOSTNAME1" > /etc/conf.d/hostname
emerge --noreplace netifrc
touch /README-on-1st-boot
echo "mv /etc/init.d/net.eth0 to /etc/init.d/net.(INTERFACE NAME)  if your ethernet card is not listed as eth0 in ifconfig " > /README-on-1st-boot
echo " you may also need to  run ifconfig -a to see you interface , if this is the case run ifconfig INTERFACE-NAME up " >> /README-on-1st-boot
echo " once you have establihed the card that is being used and turned it on you can now run   rc-update add net.(INTERFACE-NAME) default   to add it to the default run level and be started on boot" >> /README-on-1st-boot
echo " you can now edit  /etc/conf.d/net and add config_INTERFACE-NAME="dhcp"  to start the connection default with dhcp" >> /README-on-1st-boot
cd /etc/init.d
ln -s net.lo net.eth0
mkdir /media/cdrom
mv /etc/rc.conf /etc/rc.conf.back
echo 'rc_parallel="YES"' > /etc/rc.conf
echo 'rc_shell=/sbin/sulogin' >> /etc/rc.conf
echo 'rc_hotplug="*"' >> /etc/rc.conf
echo 'rc_logger="YES"' >> /etc/rc.conf
echo 'rc_log_path="/var/log/rc.log"' >> /etc/rc.conf
echo 'rc_log_path="/var/log/rc.log"' >> /etc/rc.conf
echo 'unicode="YES"' >> /etc/rc.conf
echo 'rc_sys=""' >> /etc/rc.conf
echo 'rc_tty_number=12' >> /etc/rc.conf
mv /etc/conf.d/keymaps /etc/conf.d/keymaps.back
if [ $KEYMAP == uk ];then
   echo "uk" > /etc/conf.d/keymaps
else
   echo "us" > /etc/conf.d/keymaps
fi
echo 'windowkeys="YES"' >> /etc/conf.d/keymaps
echo 'dumpkeys_charset=""' >> /etc/conf.d/keymaps
echo 'fix_euro="NO"' >> /etc/conf.d/keymaps
if [ $DUALBOOT == 1 ];then
	mv /etc/conf.d/hwclock /etc/conf.d/hwclock.back
	echo 'clock="local"' > /etc/conf.d/hwclock
	echo 'clock_args=""' >> /etc/conf.d/hwclock
else
	echo " keeping hw clock to UTC, linux only setup"
fi
emerge syslog-ng
rc-update add syslog-ng default
emerge mlocate
updatedb
rc-update add sshd default
emerge dhcpcd
rc-update add dbus default
if [ $GRUBVER == 2 ];then
	emerge sys-boot/grub
	grub2-install $HDD2
	grub2-mkconfig -o /boot/grub/grub.cfg
else
	emerge sys-boot/grub:0
	echo 'default 0' > /boot/grub/grub.conf
	echo 'timeout 30' >> /boot/grub/grub.conf
	if [ $DUALBOOT == 1 ];then
	echo 'title Winblows' >> /boot/grub/grub.conf
	echo rootnoverify (hd$WINHDD,$WINPART) >> /boot/grub/grub.conf
	echo 'makeactive' >> /boot/grub/grub.conf
	echo 'chainloader +1' >> /boot/grub/grub.conf
	else
	fi
	echo '' >> /boot/grub/grub.conf
	echo 'title Gentoo Linux' >> /boot/grub/grub.conf
	echo root (hd$LINHDD,$LINPART) >> /boot/grub/grub.conf
	echo kernel /boot/kernel root=$HDD1 real_root=$HDD1 rootfstype=ext4 $EXTRABOOTOP >> /boot/grub/grub.conf
	echo 'initrd /boot/initramfs' >> /boot/grub/grub.conf
	grep -v rootfs /proc/mounts > /etc/mtab >> /boot/grub/grub.conf
	grub-install --no-floppy $HDD2 >> /boot/grub/grub.conf
fi
useradd -m -G users,wheel,audio -s $SHELL1 $USER1
clear
echo " "
echo " "
echo " "
echo " ------------------------------------"
echo "SET PASSWORD FOR ROOT"
passwd
echo " "
echo " SET PASSWORD FOR $USER1 "
passwd $USER1
echo "--------------------------------------"
echo " "
echo " Clean .tar "
rm /stage3-*.tar.bz2*
rm $dragon_tmp
sleep 2
clear
echo " "
echo " "
echo " "
echo " ----------------------"
echo " run these commands manually from outside of the chroot "
echo " -----------------------"
echo " umount -l /mnt/gentoo/dev{/shm,/pts,}"
echo "umount /mnt/gentoo{/boot,/sys,/proc,}"
echo "reboot "
echo "---------------------------"
echo " AFTER REBOOT READ  THE FILE /README-on-1st-boot"
echo "script is finished"
read -p ""
[hr]
This is the configuration setup file

Named configuration

gentoo-user
/bin/bash
gentoo-local
/dev/sda1
/dev/sda
uk
GMT
1
0
0
0
1
1
/dev/sda2
5
0
 
"-gnome-shell -nautilus -systemd mmxext vdpau introspection unicode X a52 aac alsa ao blas bzip2 cairo cdda cddb cdparanoia consolekit -hal cdr dbus dri dv dvdr encode ffmpeg fbcon flac glut -gnome gtk -kde -qt lame libnotify mad lm_sensors modules mp3 mp4 mpeg mplayer multilib mysql mysqli ncurses nsplugin ogg opengl pam policykit pdf perl php pulseaudio python sasl seamonkey sqlite sqlite3 sse sse2 symlink syslog tiff udev v4l v4l2 vcd vorbis wavpack wifi win32codecs x264 xcomposite xv xvid bash-completion mmx sse sse2 jpeg dvd xinerama oss glib"
##line number   |    its use
#      1        |    USERNAME1
#      2        |    SHELL1   e.g   /bin/bash
#      3        |    HOSTNAME1 of machine
#      4        |    HDD1     this is the device used for linux root   e.g /dev/sda1
#      5        |    HDD2    this is the boot device grub will be installed to e.g /dev/sda
#      6        |    KEYMAP   currently set as uk or us
#      7        |    TIMEZONE 
#      8        |    GRUBVER   1 = legacy 2 = grub2  #### 3 = uefi enabled (not added support yet)
#      9        |    DUALBOOT  if your going to use this with windows then set to 1 otherwise 0
#      10       |    LINHDD   set this to a value of hdd where linux is( /devsda = 0 /dev/sdb = 1 ect)
#      11       |    LINPART  set this to partition value of linux ( /dev/sda1 = 0  /dev/sda2 = 1 ect) 
#      12       |    WINHDD   same as line 10 but for windows location  |   its ignored if line 9 = 0
#      13       |    WINPART  same as line 11 but for Windows location  |   its ignored if line 9 = 0
#      14       |    SWAP     swap space e.g /dev/sda2
#      15       |    MAKEJOBS  this is the (cpu cores + 1 )  i.e quad core , set this to 5
#      16       |    MANUALCONFIG   set to 0 to use .config or 1 to use menuconfig  (KERNEL)
#      17       |    EXTRABOOTOPS  extra boot options to hadd to grub, can be left blank
#      18       |    USEFLAGS   this is the use flags in make.conf , needs to be in " "
[hr]
this is a .config , manually move it to /mnt/gentoo/ and set MANUALCONFIG to 0

https://gist.github.com/anonymous/954f8331d00f74f8f631

MANUALCONFIG=1  will allow make menuconfig

the files configuration and Chroot-Script must be in the same Dir when Host-Script is executed

Comments

Sign In or Register to comment.