Permalink
Browse files

new scripts structure

  • Loading branch information...
1 parent 925e76c commit 22c05d739aa507d6e519ba749ae85a825ecf9e95 @yerenkow committed Jun 13, 2012
Showing with 249 additions and 0 deletions.
  1. +17 −0 scripts-v2/config-10-kde.sh
  2. +96 −0 scripts-v2/functions.sh
  3. +136 −0 scripts-v2/run-all.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+
+partition="37"
+disk="ada0"
+sourcedir="`realpath /zstorage/testenv/sources/10`"
+echo $sourcedir
+portstree="`realpath /zstorage/testenv/portstree`"
+portsnap="`realpath /zstorage/testenv/portsnap`"
+codename="10-i386-kde"
+target="i386"
+srcpatchdirs="" #use empty if there's none
+simplemergedir="`realpath /zstorage/testenv/kms-files`"
+mergedirs="`realpath /zstorage/testenv/xorg-dev`" #separated by space, all this dirs goes to /root. If you need move them - embed mv to installation script
+installscript="/root/install.sh"
+statedir="/zstorage/testenv/newstates/" #trailing slash please;
+mountdir="/zstorage/testenv/mount/10-i386"
View
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+createPartition(){
+#1 - num, 2 - disk, 3 - label
+gpart add -s 7500m -t freebsd -i ${1} ${2}
+#gpart create -s BSD ${2}s${1}
+gpart add -s 7100m -t freebsd-ufs -i 1 ${2}s${1}
+#if we switch to GPT - label changing in separate call - since it could be faulted
+#gpart modify -i 1 -l ${3} ${2}s${1}
+gpart add -t freebsd-swap -i 2 ${2}s${1}
+#gpart modify -i 2 -l ${4} ${2}s${1}
+
+dd if=/dev/zero of=/dev/${2}s${1}a bs=128m
+dd if=/dev/zero of=/dev/${2}s${1}b bs=128m
+
+newfs -Uj /dev/${2}s${1}a
+}
+
+destroyPartition(){
+#1 - num, 2 - disk
+ gpart delete -i 2 ${2}s${1}
+ gpart delete -i 1 ${2}s${1}
+ gpart delete -i ${1} ${2}
+}
+
+isStateFilePresent(){
+#1 - statedirpath, 2 - revision, 3 - action, 4 - appendix
+ if [ -e "$1$2$3$4" ] ; then
+ echo "true"
+ else
+ echo "false"
+ fi
+}
+createStateFile(){
+#1 - statedirpath, 2 - revision, 3 - action, 4 - appendix
+ touch "$1$2$3"
+}
+
+getSvnRevision(){
+#1 - dirpath
+svnrev=`cd $1 && svn info | grep "Last Changed Rev" | awk '{split($0, f, " "); print f[4];}' `
+echo $svnrev
+}
+
+svnUpdateDir(){
+#ignoring output, like we are in a ideal world
+ st="`pwd`"
+ cd $1 && svn up
+ cd $st
+}
+
+dirName(){
+ basename `realpath $1`
+}
+
+updatePortsTree(){
+portsnap -p $1 -d $2 fetch update
+}
+
+buildWorld(){
+ st="`pwd`"
+ cd $1 && nice make -j 4 buildworld TARGET=$2
+ cd $st
+}
+
+buildKernel(){
+ st="`pwd`"
+ cd $1 && nice make -j 4 buildkernel TARGET=$2
+ cd $st
+}
+
+installAll(){
+ st="`pwd`"
+ cd $1 && nice make installworld installkernel distribution TARGET=$2 DESTDIR=$3
+ cd $st
+}
+
+mountDisk(){
+#1 - num, 2 - disk, 3 - path
+#todo think about label mount?...
+ mount -o noatime /dev/${2}s${1}a ${3}
+}
+
+writeBootCode(){
+#1 - num, 2 - disk, 3 - mountdir
+ gpart bootcode -b ${3}/boot/boot ${2}s${1}
+}
+
+mergeSimpleDirs(){
+#1 - src, 2 - mountdir
+ st="`pwd`"
+ cd $1 && cp -r ./ $2
+ cd $st
+}
+
+
View
@@ -0,0 +1,136 @@
+#!/bin/sh
+
+. functions.sh
+
+#step 0 - load config script, we get from there such variables:
+# num of partition to use
+# disk to use
+# src dir path
+# portstree path
+# portsnap db path
+# codename of build
+# src patches if exists
+# new system merge dir
+# new system packet installation script (to which we chroot)
+# fstab hints (what for we are building - da0, or ada0)
+
+#step 1 - svn up needed source tree
+#step 2 - update ports tree
+#step 3 - check if any patches-trees we need, update them
+
+#step4a - if there's no src patches, build world + kernel
+#step4b - if there's src patches - copy src tree and apply all src patches before building;
+
+#step5 - destroy disk partiton, init all from scratch
+
+#step6 - install world to partition, create basic fstab
+#step7 - write bootcode to partition
+
+# after this we have basically bootable and working clear OS.
+#step8 - merge system
+#step9 - chroot to installation script if any, catch output
+#stepA - umount all, dump partition to file
+#stepB - xz file
+
+
+if [ ! -f "$1" ] ; then
+ echo "Usage example:";
+ echo " $0 your-config-file.sh";
+ exit 0;
+fi
+
+. $1
+
+#TODO - FINISH ALL FOR OLD REVISION BEFORE UPDATE ANY SOURCES.
+svnUpdateDir $sourcedir
+sourceRev=$(getSvnRevision $sourcedir)
+sourceDirName=$(dirName $sourcedir)
+echo $sourceDirName
+updatePortsTree $portstree $portsnap
+
+workingSrcDir="$sourcedir"
+sourceState="${sourceDirName}-${sourceRev}"
+if [ ! -z "$srcpatchdirs" ] ; then
+ echo "source patches"
+ #todo make tempdir, copy sources, iterate by source pathes, svn up them and copy patches
+ #change workingSrcDir;
+ #change sourceState
+else
+ echo "no source patches, proceeding in $workingSrcDir dir."
+fi
+
+t=$(isStateFilePresent $statedir $sourceState "-world-built")
+if [ "$t" != "true" ] ; then
+ buildWorld $sourcedir $target
+ createStateFile $statedir $sourceState "-world-built"
+else
+ echo "world already built, continue;"
+fi
+
+t=$(isStateFilePresent $statedir $sourceState "-kernel-built")
+if [ "$t" != "true" ] ; then
+ buildKernel $sourcedir $target
+ createStateFile $statedir $sourceState "-kernel-built"
+else
+ echo "kernel already built, continue;"
+fi
+
+
+t=$(isStateFilePresent $statedir $sourceState "-newmedia")
+if [ "$t" != "true" ] ; then
+ destroyPartition $partition $disk
+ createPartition $partition $disk
+ #labels as 3,4 args, only for gpt in future; "${disklabel}${sourceRev}" "${swaplabel}${sourceRev}"
+ createStateFile $statedir $sourceState "-newmedia"
+else
+ echo "media already inited, continue;"
+fi
+
+#todo think about already mounted?...
+mountDisk $partition $disk $mountdir
+
+t=$(isStateFilePresent $statedir $sourceState "-wk-installed")
+if [ "$t" != "true" ] ; then
+ installAll $sourcedir $target $mountdir
+ createStateFile $statedir $sourceState "-wk-installed"
+else
+ echo "all already installed, continue;"
+fi
+
+t=$(isStateFilePresent $statedir $sourceState "-bootcode")
+if [ "$t" != "true" ] ; then
+ writeBootCode $partition $disk $mountdir
+ createStateFile $statedir $sourceState "-bootcode"
+else
+ echo "bootcode already installed, continue;"
+fi
+
+t=$(isStateFilePresent $statedir $sourceState "-simplemerge")
+if [ "$t" != "true" ] ; then
+ mergeSimpleDirs $simplemergedir $mountdir
+ createStateFile $statedir $sourceState "-simplemerge"
+else
+ echo "simple merge already done, continue;"
+fi
+
+if [ ! -z "$mergedirs" ] ; then
+ echo "mergedirs"
+ for m in $mergedirs ; do
+ svnUpdateDir $m
+ targetDir="$mountdir/root/`basename $m`"
+ mkdir -p $targetDir
+ mergeSimpleDirs $m $targetDir
+ done
+ #todo make tempdir, copy sources, iterate by source pathes, svn up them and copy patches
+ #change workingSrcDir;
+ #change sourceState
+else
+ echo "no merge dirs, continue."
+fi
+
+mkdir -p ${mountdir}/usr/ports
+mount -t nullfs ${portstree} ${mountdir}/usr/ports
+
+chroot ${mountdir} ${installscript}
+
+# umount $mountdir

0 comments on commit 22c05d7

Please sign in to comment.