mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.7 KiB

  1. #!/bin/bash
  2. #
  3. # Commands in isofs.txt files:
  4. #
  5. # EVERY from to Put this on every disk
  6. # DISK1 from to Put this on the 1st disk
  7. # SINGLE from to Put it on any disk
  8. # SPLIT from to You may split it up over many disks
  9. #
  10. # BOOT boot-options Add this mkisofs options for 1st disk
  11. #
  12. # If you want to add multiple 'BOOT' lines, use the tag-name 'BOOTx' for
  13. # the 2nd and all further lines.
  14. #
  15. # SCRIPT script-name args Run given script for each image
  16. #
  17. # Intended for image post-processing. The first attached argument is the CD
  18. # number and the second the image file.
  19. #
  20. cleanup () {
  21. # Cleanup used for EXIT
  22. umount $mountpoint
  23. rmdir -p $mountpoint
  24. losetup -d $loopdevice
  25. }
  26. eval `grep rockver scripts/parse-config`
  27. if [ $# -eq 0 ] ; then
  28. echo
  29. echo "Usage: $0 [-size MB] [-debug] [-verbose] [-full]"
  30. echo " [-prefix FS-Prefix] [-fs filesystem] Config"
  31. echo
  32. echo "E.g.: $0 -full -prefix my myconfig"
  33. echo "this will leave you with a file 'my_linux' (the kernel) and a file"
  34. echo "'my_rootfs' (the file system). Just start it with ./linux"
  35. echo
  36. exit 1
  37. fi
  38. src=0; mkdebug=0; fssize=0; full=0;
  39. filesystem="reiserfs"
  40. while true ; do
  41. case "$1" in
  42. -size)
  43. fssize=$2 ; shift ; shift ;;
  44. -debug)
  45. debug=1 ; shift ;;
  46. -verbose)
  47. verbose=1 ; shift ;;
  48. -fs)
  49. filesystem=$2; shift; shift ;;
  50. -prefix)
  51. ufsprefix=$2; shift; shift ;;
  52. -full)
  53. full=1; shift ;;
  54. -* | '')
  55. $0 ; exit 1 ;;
  56. *)
  57. cfg=$1 ; shift ; break ;;
  58. esac
  59. done
  60. if [ ! "x$ufsprefix" = "x" ]; then fsprefix=${ufsprefix}_; else fsprefix=""; fi
  61. if [ -f ${fsprefix}rootfs -o -f ${fsprefix}linux ]; then
  62. echo "Sorry, there exists a file with the same name, please make sure"
  63. echo "that no ${fsprefix}linux and no ${fsprefix}rootfs exist here."
  64. exit 1
  65. fi
  66. # get the build id
  67. if [ ! -d config/$cfg ]; then
  68. echo "I cannot find the selected Config '$cfg'!"
  69. exit 1
  70. fi
  71. buildid="`grep '^export ROCKCFG_ID=' config/$cfg/config | cut -f2 -d\'`"
  72. if [ ! -d build/$buildid ]; then
  73. echo "I cannot find the build for the Config '$cfg' (build/$buildid)"
  74. exit 1;
  75. fi
  76. # check if there is a kernel executable
  77. if [ ! -f build/$buildid/boot/linux -o "x" = "x$(grep UMLPATCH=\'1\' config/$cfg/config)" ]; then
  78. echo "I cannot find the executable kernel, "
  79. echo "or it seems that the UML Patch was not applied to the kernel."
  80. exit 1;
  81. fi
  82. # calculate the default disk size as all packages of that config + 1/3 of the same
  83. if [ $fssize = 0 ]; then
  84. echo "Calculating optimal image size, may take some time ..."
  85. cfssize=$(cd build/$buildid; du -sm --exclude ROCK | awk '{print $1;}';cd $OLDPWD)
  86. echo "All packages consume $cfssize MB"
  87. freespace=$(( $cfssize / 3 ))
  88. fssize=$(( $cfssize + $freespace ))
  89. echo "Therefore I propose a fs size of $fssize, that leaves you $freespace MB of free space."
  90. fi
  91. # check if there is enough disk space
  92. hereiskbfree=$(df -P $PWD | tail -n 1 | awk '{ print $4; }')
  93. hereismbfree=$(( $hereiskbfree / 1024 ))
  94. if [ $hereismbfree -lt $fssize ]; then
  95. echo "Sorry, you have only $hereismbfree MB free here, "
  96. echo "that is not enough for a rootfs of $fssize MB."
  97. exit 1
  98. fi
  99. # create the empty rootfs file
  100. dd if=/dev/zero of=${fsprefix}rootfs seek=${fssize} count=1 bs=1M
  101. trap 'cleanup' EXIT
  102. # find a free loop device
  103. for i in `ls /dev/loop/*`; do
  104. echo $i
  105. losetup $i ${fsprefix}rootfs
  106. if [ $? = 0 ]; then
  107. loopdevice=$i
  108. break
  109. fi
  110. done
  111. # make a filesystem
  112. yes | mkfs -t $filesystem $loopdevice
  113. # loop-mount the file
  114. mountpoint=${fsprefix}rootfs_mnt
  115. mkdir -p $mountpoint
  116. mount -t $filesystem $loopdevice $mountpoint
  117. # install all
  118. echo "Installing files, may take some time..."
  119. if [ $full = 1 ]; then
  120. # for i in build/$buildid/*; do
  121. # if [ $i = "build/$buildid/ROCK" ]; then continue; fi
  122. # cp -rp $i $mountpoint
  123. # done
  124. for i in build/$buildid/ROCK/pkgs/*gem; do
  125. if [ 'x1' = "x$verbose" ]; then
  126. echo "Installing ${i/*\//}"
  127. fi
  128. mine -i -R $mountpoint $i
  129. done
  130. fi
  131. # call the update script and some other tweaks
  132. echo "Doing post-install adoptions"
  133. chroot $mountpoint bash /etc/cron.d/00-updates
  134. sed -i -e 's,vc/1,vc/0,' -e 's,^\([2-6]:\),#\1,' $mountpoint/etc/inittab
  135. cat >$mountpoint/etc/fstab <<EOF
  136. /dev/root / auto defaults 0 1
  137. proc /proc proc defaults 0 0
  138. devfs /dev devfs defaults 0 0
  139. devpts /dev/pts devpts defaults 0 0
  140. tmpfs /dev/shm tmpfs defaults 0 0
  141. sysfs /sys sysfs defaults 0 0
  142. #tmpfs /tmp tmpfs defaults 0 0
  143. EOF
  144. # Copy the executable kernel
  145. cp $mountpoint/boot/linux ${fsprefix}linux
  146. # Finished.
  147. echo "Finished. You may now run"
  148. echo " ./${fsprefix}linux ubd0=${fsprefix}rootfs"