root/LiveKoha/create-koha-live

Revision e545d090c90d02e869663eb2fb45d1ead7cd5e7a, 32.6 KB (checked in by root <root@…>, 2 years ago)

Merge LiveKoha project as our subdirectory

  • Property mode set to 100755
Line 
1#!/bin/bash
2# Author: Steven Shiau <steven _at_ nchc org tw>
3# Author: Thomas Tsai <thomas _at_ nchc org tw>
4# License: GPL
5# Description: This script original will create a Ubuntu live CD iso which is used as a template for clonezilla image with restoration function and now will create a Koha Live CD for demonstration.
6
7if [ ! -f "`pwd`/live-hook-dir/LiveKoha.sh" ]; then
8  echo "Unable to find `pwd`/live-hook-dir/LiveKoha.sh! Program terminated!"
9  exit 1
10fi
11
12PKG_BASE="util-linux tar gzip bzip2 procps dialog rsync pciutils tcpdump bc grub gawk hdparm sdparm netcat file ethtool etherwake ssh syslinux mtools mkisofs reiserfsprogs e2fsprogs psmisc locales wget disktype zip unzip ncftp perl-modules less localepurge whiptail lftp net-tools dpkg-dev fakeroot vim localepurge lynx gcc man build-essential g++ g++-4.2 libstdc++6-4.2-dev libicu-dev libicu38 libicu38-dbg libssl-dev libwrap0-dev libxml2-dev libxslt1-dev libxslt1.1 tcl8.4 zlib1g-dev libfile-remove-perl libextutils-parsexs-perl libmodule-corelist-perl libarchive-tar-perl libmodule-pluggable-fast-perl man"
13
14PKG_XWINDOW="scim xterm xinit xauth xfonts-base xfonts-100dpi xfonts-75dpi firefox language-pack-zh-base language-pack-zh ttf-arphic-uming xserver-xorg gdm tango-icon-theme tango-icon-theme-common thunar ttf-bitstream-vera ttf-freefont ubuntu-artwork usplash vim xorg scim-chewing scim-tables-zh mozilla-firefox-locale-zh-tw mozilla-firefox-locale-zh-cn vim-gnome poppler-data"
15
16PKG_GNOME="ubuntu-default-settings ubuntu-desktop" # for LiveKoha large zip mode
17
18PKG_XFCE="xfce4 xfwm4 thunar xfwm4-themes xubuntu-default-settings xfce4-terminal"
19PKG_KOHA_SRV="daemon subversion apache2 mysql-server-5.0 phpmyadmin"
20
21PKG_FROM_DBN_WHICH_OCS_LIVE_NEED="$PKG_BASE $PKG_XWINDOW $PKG_KOHA_SRV"
22
23TARGET_MEDIA_FILE_DEF="both"
24
25mirror_url_def="http://free.nchc.org.tw/ubuntu"
26mirror_security_url_def="http://free.nchc.org.tw/ubuntu"
27# debian_type can be minimal (about 67 MB for Etch)/minimal-net (about 85 MB for Etch).
28# If we choose to use standard, it will get the DRBL GPG automatically, but
29# if using minimal, it will ignore GPG key of DRBL, however, it still can go.
30# This can be hacked by modifying /usr/sbin/lh_installapt and more, let it no matter it's minimal or mini, KEY will be loaded. One remaining problem is if using miminal, wget is not installed. Even if minimal-net, wget is installed after lh_installapt... therefore wget is necessary to be installed in lh_installapt. This is done in live-package-0.99.26 in http://free.nchc.org.tw/drbl-core/pool/drbl/live-unstable/ (might change to live-testing or live-stable in the future).
31# //NOTE// for Ubuntu: If we use minimal, we have to add some extra packages (udev, upstart, system-services by ourself). It's easier to use standard.
32#debian_type="minimal"
33debian_type="standard"
34DEBIAN_DIST_DEF="hardy"
35# Ubuntu sections:
36ubuntu_sections="main restricted universe multiverse"
37use_existing_stage1_iso="no"
38rm_tmp_iso="no"
39live_sys_files_dir_list="casper live isolinux"
40real_target_iso="LiveKoha.iso"
41real_target_zip="LiveKoha.zip"
42pkgs="$PKG_FROM_DBN_WHICH_OCS_LIVE_NEED"
43
44# UGLY... but we have to semi hard coded them... since live helper won't work in Ubuntu if we do not assign version number. It's because the kernel package name in Ubuntu is like linux-image-2.6.24-7-generic, and if we do not assign version number, live-helper will try to install linux-image-2.6-generic, which does not exist in ubuntu. In Ubuntu, it's linux-image-generic.
45# This is only set as default, later we will use get_latest_kernel_in_repository to find the latest kernel in repository.
46gutsy_release_kernel_ver_def="2.6.22-14"
47hardy_release_kernel_ver_def="2.6.24-15"
48
49# DRBL repository
50DRBL_REPOSITORY_URL="http://free.nchc.org.tw/drbl-core"
51# url to the repository key
52DRBL_GPG_KEY_URL="http://drbl.nchc.org.tw/GPG-KEY-DRBL"
53
54# path of pkg-ver-latest
55PKG_PATH=`pwd`
56
57# The files in dir $ocs_live_script_dir/ will be copied to the dir /live-hook-dir in dir chroot. The file "ocs-live-hook" is in $ocs_live_script_dir
58# We put some files in dir ocs_minimal_hook/ to do some jobs, like clean unnecessary files, set locales...
59ocs_live_script_dir="$PKG_PATH/live-hook-dir"
60# The script inside $ocs_live_script_dir/ will be run when chroot. There are many files in $ocs_live_script_dir/, we will just run one here.
61run_hook_script="LiveKoha.sh"
62
63# Check if root or not
64if [ ! "$UID" = "0" ]; then
65  echo
66  echo "[$LOGNAME] You need to run this script \"`basename $0`\" as root."
67  echo
68  exit 1
69fi
70
71prog="$(basename $0)"
72
73# functions
74USAGE() {
75    echo "Usage:"
76    echo "To create a Koha live CD which is used a template for koha live:"
77    echo "$prog [OPTION]"
78    echo "OPTION:"
79    echo "-b, --branch [stable|testing|unstable]  specifies the DRBL branch to be used in Live CD. Default is stable."
80    echo "-d, --debian-dist [gutsy|hardy]  Assign Ubuntu dist, the default is $DEBIAN_DIST_DEF if not assigned."
81    echo "-s, --desktop [gnome|xfce]  Assign Ubuntu Desktop, the default is xfce if not assigned."
82    echo "-i, --assign-version-no NO  Assign the version no as NO instead of date."
83    echo "-k, --live-kernel-pkg KERNEL_VER Assign kernel version as KERNEL_VER (KERNEL VER package must exist in repository. Ex. if KERNEL_VER is 2.6.20-1-486, then linux-image-2.6.20-1-486, squashfs-modules-2.6.20-1-486, and unionfs-modules-2.6.20-1-486 will be used."
84    echo "-l, --drbl-live-branch [s|stable|t|testing|u|unstable|e|experimental]  specifies the DRBL live branch to be used in Live CD. Default is stable."
85    echo "-m|--mirror-url URL Assign the URL for mirror site. Ex. http://free.nchc.org.tw/ubuntu/"
86    echo "-s|--mirror-security-url URL Assign the URL of security branch for mirror site. Ex. http://free.nchc.org.tw/ubuntu/"
87    echo "-t, --batch     Run in batch mode"
88    echo "-v, --verbose   Run make-live/lh_build in verbose mode"
89    echo "-o, --target-media-file  [cd|iso|usb|zip|b|both] Assign the target media file as CD (cd or iso), USB flash drive (usb or zip) or both of them (b or both). Default is both"
90    echo "-r, --rm-tmp-iso    Remove the first stage temp iso file"
91    echo "-u, --use-existing-tmp-iso  Use the existing first stage temp iso file"
92
93}
94#
95get_latest_kernel_in_repository() {
96  # Since we might run this on gutsy to create hardy live, so we can not use apt-cache to search that. Another approach is to use apt-file to do that. However, it looks like the file http://opensource.nchc.org.tw/ubuntu/dists/hardy/Contents-i386.gz which apt-file fetched is not updated with repository.
97  local ktmp kver
98  ktmp="$(mktemp -d /tmp/live_kver.XXXXXX || exit 1)"
99  echo "Downloading $mirror_url/dists/$debian_dist/main/binary-i386/Packages.gz  to finding latest kernel version..."
100  LANG=C wget $wget_opt -P $ktmp/ $mirror_url/dists/$debian_dist/main/binary-i386/Packages.gz
101  # The info in the Packges.gz is like:
102  # Package: linux-image-2.6.24-10-386
103  # Package: linux-image-2.6.24-10-generic
104  # Package: linux-image-2.6.24-10-server
105  # Package: linux-image-2.6.24-10-virtual
106  # Package: linux-image-2.6.24-11-386
107  # Package: linux-image-2.6.24-11-generic
108  # Package: linux-image-2.6.24-11-server
109  # Package: linux-image-2.6.24-11-virtual
110  kver="$(zgrep -E "^Package: linux-image-2\.6\.[[:digit:]]+.*-generic" $ktmp/Packages.gz  | sed -e "s|^Package: linux-image-||g" -e "s|-generic$||g" | $PKG_PATH/pkg-ver-latest)"
111  [ -d "$ktmp" -a -n "$ktmp" ] && rm -rf $ktmp
112  if [ -n "$kver" ]; then
113    release_kernel_ver="$kver"
114  else
115    eval release_kernel_ver="\$${debian_dist}_release_kernel_ver_def"
116  fi
117} # end of get_latest_kernel_in_repository
118
119
120get_live_boot_param() {
121  # For live helper with live-initramfs, maybe it is: boot=live username=casper union=aufs
122  # ---------------------------
123  # LABEL live
124  #     MENU LABEL Start Debian Live
125  #     kernel /live/vmlinuz1
126  #     append initrd=/live/initrd1.img boot=live username=casper union=aufs
127  # ---------------------------
128
129  # For live helper with casper, maybe it is: boot=casper username=casper union=unionfs
130  # ---------------------------
131  # LABEL live
132  #       MENU LABEL Start Debian Live
133  #     kernel /casper/vmlinuz1
134  #     append initrd=/casper/initrd1.img boot=casper username=casper hostname=debian
135  # ---------------------------
136  local iso_tmp="$1"
137  local cand_files="menu.cfg isolinux.cfg"
138  [ -z "$iso_tmp" ] && echo "No path for iso mount point! Exit!" && exit 1
139  echo "Trying to find the boot params from template live cd..."
140  for i in $cand_files; do
141   if [ -f "$iso_tmp/$i" ]; then
142      boot_opt="$(grep -oE "boot=[[:alnum:]]+" $iso_tmp/$i | sort | uniq)"
143      # (2) union=aufs|unionfs 
144      union_opt="$(grep -oE "union=[[:alnum:]]+" $iso_tmp/$i | sort | uniq)"
145      # (3) username
146      username_opt="$(grep -oE "username=[[:alnum:]]+" $iso_tmp/$i | sort | uniq)"
147      hostname_opt="$(grep -oE "hostname=[[:alnum:]]+" $iso_tmp/$i | sort | uniq)"
148      # Once we got the param, we can break later
149      [ -n "$union_opt" -o -n "$boot_opt" -o -n "$username_opt" -o -n "$hostname_opt" ] && next_step=break
150      # We'd better not to assign boot_opt and union_opt here if they are not found. Comment them! However, for username, it's important! Without correct username, live-initramfs or casper won't be able to login command line automatically.
151      # [ -z "$union_opt" ] && union_opt="union=unionfs"
152      # [ -z "$boot_opt" ] && boot_opt="boot=casper"
153      if [ -z "$username_opt" ]; then
154        # A workaround is to search the isolinux config if it contains something lie:
155        # append initrd=/live/initrd.img boot=live hostname=ubuntu union=aufs
156        # If we can find hostname=ubuntu, then use username=ubuntu. Otherwise leave it alone! We assume this is only a bug in the live-helper from Ubuntu 7.10. For newer live-helper from Debian SID, it will automatically add username in the created iso.
157        if grep -q "hostname=ubuntu" $iso_tmp/$i; then
158          username_opt="username=ubuntu"
159        else
160          username_opt=""
161        fi
162      fi
163      boot_param="$boot_opt $union_opt $username_opt $hostname_opt"
164      $next_step
165   fi
166  done
167  # BOOT_PARAM_DEFAULT is from drbl-ocs.conf.
168  [ -z "$boot_param" ] && boot_param="$BOOT_PARAM_DEFAULT"
169} # end of get_live_boot_param
170
171
172#
173create_version_tag_in_live() {
174  local tag_file_in_abs_path="$1"
175  local koha_v
176  koha_v="3.0.0-beta"
177  cat <<-TAG_END > $tag_file_in_abs_path
178koha: $koha_v
179This LiveKoha is created by:
180$full_cmd
181TAG_END
182}
183#
184
185#
186create_drbl_live_iso(){
187  echo "$msg_delimiter_star_line"
188  echo "Creating DRBL server iso file..."
189  echo "$msg_delimiter_star_line"
190  #
191  # Possible kernel/initrd paths are /casper (created by casper) or /live (created by live-initramfs)
192  # Find the kernel and initrd in $stage1_iso_TMP/casper or $stage1_iso_TMP/live
193  # Ex: $stage1_iso_TMP/casper/vmlinuz1, /$stage1_iso_TMP/casper/initrd1.img
194  # $live_sys_files_dir_list is from drbl-ocs.conf.
195  # Possible kernel/initrd paths are /casper (created by casper) or /live (created by live-initramfs)
196  sys_files_dir=""
197  for i in $live_sys_files_dir_list; do
198    krnfile="$(find $stage1_iso_TMP/$i/ -maxdepth 1 -name "vmlinuz*" -print 2>/dev/null)"
199    if [ -n "$krnfile" ]; then
200      krnfile="$(basename $krnfile)"
201      sys_files_dir="$i"
202      irdfile="$(find $stage1_iso_TMP/$i/ -maxdepth 1 -name "initrd*" -print)"
203      irdfile="$(basename $irdfile)"
204      break
205    fi
206  done
207  BOOT_ITEM_DIR=$ISOLNX_TMP/$sys_files_dir
208  [ ! -d $BOOT_ITEM_DIR ] && mkdir $BOOT_ITEM_DIR
209
210  if [ -z "$sys_files_dir" ]; then
211    [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
212    echo "No system files from template live iso are found! Something went wrong!"
213    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
214    echo "$msg_program_stop"
215    exit 1
216  fi
217
218  if [ -z "$krnfile" -o -z "$irdfile" ]; then
219     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
220     echo "Kernel and initrd files NOT found in path $stage1_iso_TMP/$sys_files_dir/!"
221     echo "$msg_program_stop"
222     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
223     exit 1
224  fi
225
226  # now we can insert the boot menu of isolinux
227  # create isolinux menu
228  # isolinux should be rw, so we have to copy it, and exclude the one in iso image.
229  rsync -a --exclude f*.txt --exclude boot.cat --exclude isolinux.txt --exclude isolinux.bin --exclude splash.rle --exclude doc $stage1_iso_TMP/isolinux $ISOLNX_TMP/
230  # we have to overwrite isolinux.bin since vesamenu.c32 should be same version with that.
231  cp -f syslinux/isolinux.bin syslinux/vesamenu.c32 syslinux/menu.c32 syslinux/memdisk LiveKoha_bg_img syslinux/chain.c32 $ISOLNX_TMP/isolinux/
232
233  # Put the tag
234  # The VER_TAG is like drbl-live-xfce-20070315
235  VER_TAG="$(echo $real_target_iso | sed -e "s/.iso$//g")"
236  create_version_tag_in_live $ISOLNX_TMP/Koha-Live-Version
237
238
239  # Excluding list for mkisofs
240  # We will create it like this:
241  # -x $stage1_iso_TMP/isolinux -x $stage1_iso_TMP/md5sum.txt -x $stage1_iso_TMP/casper/memtest
242  mkiso_exclude_list="isolinux md5sum.txt doc"
243  for i in $live_sys_files_dir_list; do
244    if [ -e "$stage1_iso_TMP/$i/memtest" ]; then
245      mkiso_exclude_list="$mkiso_exclude_list $i/memtest"
246      break
247    fi
248  done
249  mkiso_exclude_opt=""
250  for i in $mkiso_exclude_list; do
251    mkiso_exclude_opt="$mkiso_exclude_opt -x $stage1_iso_TMP/$i"
252  done
253
254  # Find the boot param $boot_param
255  get_live_boot_param $stage1_iso_TMP/isolinux
256  # generate the menu
257  $PKG_PATH/ocs-live-boot-menu -s --title "Koha Live" -f 788 -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m LiveKoha_bg_img --boot-param "$boot_param $live_extra_boot_param" -z "zh_TW" isolinux $ISOLNX_TMP/isolinux/
258
259  # $sys_files_dir maybe /casper, /live or /isolinux. If it is isolinux, we can not list them twice otherwise mkisofs will go wrong.
260  if [ "$sys_files_dir" != "isolinux" ]; then
261    sys_files_dir_graft_point="/isolinux/=$ISOLNX_TMP/isolinux/ /$sys_files_dir/=$ISOLNX_TMP/$sys_files_dir/"
262  else
263    sys_files_dir_graft_point="/isolinux/=$ISOLNX_TMP/isolinux/"
264  fi
265
266  # create the iso file
267  mkisofs \
268   -A "Koha Live CD" \
269   -V "LiveKoha" \
270   -publisher "Koha_tw http://koha.nchc.org.tw" \
271   -r -J -l \
272   -b isolinux/isolinux.bin -c isolinux/boot.cat \
273   -no-emul-boot -boot-load-size 4 -boot-info-table \
274   -x $stage1_iso_TMP/isolinux \
275   -x $stage1_iso_TMP/md5sum.txt \
276   $mkiso_exclude_opt \
277   -graft-points $stage1_iso_TMP \
278    $sys_files_dir_graft_point \
279   > $real_target_iso
280  RC_ISO=$?
281  if [ "$RC_ISO" -eq 0 ]; then
282    [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
283    echo "The $real_target_iso is created successfully!"
284    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
285  else
286    [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
287    echo "The $real_target_iso is NOT created! Something went wrong!"
288    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
289  fi
290} # end of create_drbl_live_iso
291
292#
293create_drbl_live_zip() {
294  # create temp dir for usb flash drive
295  echo "$msg_delimiter_star_line"
296  echo "Creating DRBL server zip file..."
297  echo "$msg_delimiter_star_line"
298  #
299  # Possible kernel/initrd paths are /casper (created by casper) or /live (created by live-initramfs)
300  # Find the kernel and initrd in $stage1_iso_TMP/casper or $stage1_iso_TMP/live
301  # Ex: $stage1_iso_TMP/casper/vmlinuz1, /$stage1_iso_TMP/casper/initrd1.img
302  # $live_sys_files_dir_list is from drbl-ocs.conf.
303  # Possible kernel/initrd paths are /casper (created by casper) or /live (created by live-initramfs)
304  sys_files_dir=""
305  for i in $live_sys_files_dir_list; do
306    krnfile="$(find $stage1_iso_TMP/$i/ -maxdepth 1 -name "vmlinuz*" -print 2>/dev/null)"
307    if [ -n "$krnfile" ]; then
308      krnfile="$(basename $krnfile)"
309      sys_files_dir="$i"
310      irdfile="$(find $stage1_iso_TMP/$i/ -maxdepth 1 -name "initrd*" -print)"
311      irdfile="$(basename $irdfile)"
312      break
313    fi
314  done
315
316  if [ -z "$sys_files_dir" ]; then
317    [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
318    echo "No system files from template live iso are found! Something went wrong!"
319    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
320    echo "$msg_program_stop"
321    exit 1
322  fi
323
324  if [ -z "$krnfile" -o -z "$irdfile" ]; then
325     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
326     echo "Kernel and initrd files NOT found in path $stage1_iso_TMP/$sys_files_dir/!"
327     echo "$msg_program_stop"
328     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
329     exit 1
330  fi
331
332  WD="$(pwd)"
333  USB_TMP="$(mktemp -d /tmp/usb-dev.XXXXXX)"
334  mkdir -p $USB_TMP/$sys_files_dir
335  mkdir -p $USB_TMP/syslinux/
336  echo "Copying files to temp working directory... This might take some time..."
337  rsync -av --exclude isolinux --exclude md5sum.txt --exclude doc $stage1_iso_TMP/*  $USB_TMP/
338  cp -af COPYING $USB_TMP/
339  cp -f syslinux/isolinux.bin syslinux/vesamenu.c32 syslinux/menu.c32 syslinux/memdisk LiveKoha_bg_img syslinux/chain.c32 $USB_TMP/syslinux/
340  # ref: http://syslinux.zytor.com/archives/2006-October/007440.html
341  # "-" will be regards as "_" if you want to use "-" for isolinux.
342  # In syslinux on vfat, etherboot.zlilo is too long, make it ever shorter as eb.zli
343  cp -af $stage1_iso_TMP/$sys_files_dir/{$krnfile,$irdfile} $USB_TMP/$sys_files_dir/
344  # Put the tag
345  # The VER_TAG is like drbl-live-xfce-20070315
346  VER_TAG="$(echo $real_target_zip | sed -e "s/.zip$//g")"
347  create_version_tag_in_live $USB_TMP/Koha-Live-Version
348
349  # Find the boot param $boot_param
350  get_live_boot_param $stage1_iso_TMP/isolinux
351  # generate the menu
352  $PKG_PATH/ocs-live-boot-menu -s --title "Koha Live" -f 788 -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m LiveKoha_bg_img --boot-param "$boot_param $live_extra_boot_param noprompt" -z "zh_TW" syslinux $USB_TMP/syslinux/
353
354  echo -n "Preparing syslinux.exe and makeboot.bat... "
355  cp -a syslinux/{syslinux.exe,makeboot.bat} $USB_TMP
356  echo "done!"
357  # just store it. since big files, like squash flie and opt_drbl.tgz are compressed, it's not necessary to compress it again.
358  [ -e "$WD/$real_target_zip" ] && rm -f $WD/$real_target_zip
359  (cd $USB_TMP; zip -0 -r $WD/$real_target_zip *)
360  echo "The created release file is $real_target_zip. You can extract all the files into your pendrive, and run makeboot.bat from pendrive in M$ windows."
361  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
362  echo "Warning: DO NOT RUN makeboot.bat from your local hard drive!! It is intended to be run from your USB device."
363  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
364
365} # end of create_drbl_live_zip
366
367
368batch_mode="off"
369# Parse command-line options
370while [ $# -gt 0 ]; do
371  case "$1" in
372    -b|--branch)
373            shift
374            if [ -z "$(echo $1 |grep ^-.)" ]; then
375              # skip the -xx option, in case
376              drbl_branch="$1"
377              shift
378            fi
379            [ -z "$drbl_branch" ] && USAGE && exit 1
380            ;;
381    -s|--desktop)
382            shift
383            if [ -z "$(echo $1 |grep ^-.)" ]; then
384              # skip the -xx option, in case
385              desktop="$1"
386              shift
387            fi
388            [ -z "$desktop" ] && USAGE && exit 1
389            ;;
390    -d|--debian-dist)
391            shift
392            if [ -z "$(echo $1 |grep ^-.)" ]; then
393              # skip the -xx option, in case
394              debian_dist="$1"
395              shift
396            fi
397            [ -z "$debian_dist" ] && USAGE && exit 1
398            ;;
399    -i|--assign-version-no)
400            shift
401            if [ -z "$(echo $1 |grep ^-.)" ]; then
402              # skip the -xx option, in case
403              version_no="$1"
404              shift
405            fi
406            [ -z "$version_no" ] && USAGE && exit 1
407            ;;
408    -k|--live-kernel)
409            shift
410            if [ -z "$(echo $1 |grep ^-.)" ]; then
411              # skip the -xx option, in case
412              live_kernel_ver="$1"
413              shift
414            fi
415            [ -z "$live_kernel_ver" ] && USAGE && exit 1
416            ;;
417    -l|--drbl-live-branch)
418            shift
419            if [ -z "$(echo $1 |grep ^-.)" ]; then
420              # skip the -xx option, in case
421              drbl_live_branch="$1"
422              shift
423            fi
424            [ -z "$drbl_live_branch" ] && USAGE && exit 1
425            ;;
426    -m|--mirror-url)
427            shift
428            if [ -z "$(echo $1 |grep ^-.)" ]; then
429              # skip the -xx option, in case
430              mirror_url="$1"
431              shift
432            fi
433            [ -z "$mirror_url" ] && USAGE && exit 1
434            ;;
435    -s|--mirror-security-url)
436            shift
437            if [ -z "$(echo $1 |grep ^-.)" ]; then
438              # skip the -xx option, in case
439              mirror_security_url="$1"
440              shift
441            fi
442            [ -z "$mirror_security_url" ] && USAGE && exit 1
443            ;;
444    -o|--target-media-file)
445            shift
446            if [ -z "$(echo $1 |grep ^-.)" ]; then
447              # skip the -xx option, in case
448              target_media_file="$1"
449              shift
450            fi
451            [ -z "$target_media_file" ] && USAGE && exit 1
452            ;;     
453    -r|--rm-tmp-iso)
454            rm_tmp_iso="yes"
455            shift ;;
456    -u|--use-existing-tmp-iso)
457            use_existing_stage1_iso="yes"
458            shift ;;
459    -t|--batch)
460            batch_mode="on"
461            shift ;;
462    -v|--verbose)
463            verbose="on"
464            shift ;;
465    -*)     echo "${0}: ${1}: invalid option" >&2
466            USAGE >& 2
467            exit 2 ;;
468    *)      break ;;
469  esac
470done
471
472
473if ! type lh_build &>/dev/null; then
474  [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
475  echo "This program only works in Ubuntu 7.10 or 8.04!"
476  echo "If you are running Ubuntu 7.10 or later, use 'apt-get install live-helper' to install the necessary packages, then run $0 again."
477  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
478  exit 1
479fi
480
481[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
482echo "///NOTE///"
483echo "0. This script works in Ubuntu 7.10 and 8.04 with the live-helper from patched one (live-helper_1.0~a42-2) by DRBL (modified from the one in Debian Sid!)"
484echo "1. You have to use cdebootstrap instead of debootstrap. Remember to install the one patched by DRBL/Clonezilla team. (cdebootstrap version 0.5.1 or later)"
485echo "2. If you want to create Hardy live on Gutsy, you should make sure the following exist in /usr/share/cdebootstrap/suites:"
486echo "Suite: hardy"
487echo "Config: generic-ubuntu"
488echo "Keyring: ubuntu-archive-keyring.gpg"
489echo "3. You might also need to use the live-experimental from DRBL (i.e. use run $0 with '-l e') so that:"
490echo "  a. Enable aufs instead of unionfs (To avoid this bug: https://bugs.launchpad.net/ubuntu/+source/linux-ubuntu-modules-2.6.22/+bug/150788)."
491echo "  b. Avoid a live-initramfs bug, which fails in console login."
492[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
493if [ "$batch_mode" = "no" ]; then
494  echo -n "Press enter to continue... "
495  read
496fi
497
498rm -rf LiveKohaIMG/.stage/
499
500# Apply default settings if not assigned
501[ -z "$debian_dist" ] && debian_dist="$DEBIAN_DIST_DEF"
502[ -z "$mirror_url" ] && mirror_url="$mirror_url_def"
503[ -z "$mirror_security_url" ] && mirror_security_url="$mirror_security_url_def"
504
505#
506case "$drbl_branch" in
507  t|testing)
508     echo "Using DRBL testing branch..."
509     LIVE_REPOSITORY_SECTIONS_drbl="stable testing"
510     ;;
511  u|unstable)
512     echo "Using DRBL unstable branch..."
513     LIVE_REPOSITORY_SECTIONS_drbl="stable testing unstable"
514     ;;
515  *)
516     echo "Using DRBL stable branch..."
517     LIVE_REPOSITORY_SECTIONS_drbl="stable"
518     ;;
519esac
520case "$drbl_live_branch" in
521  t|testing)
522     echo "Using DRBL Live testing branch..."
523     LIVE_REPOSITORY_SECTIONS_drbl="$LIVE_REPOSITORY_SECTIONS_drbl live-stable live-testing"
524     ;;
525  u|unstable)
526     echo "Using DRBL Live unstable branch..."
527     LIVE_REPOSITORY_SECTIONS_drbl="$LIVE_REPOSITORY_SECTIONS_drbl live-stable live-testing live-unstable"
528     ;;
529  e|experimental)
530     echo "Using DRBL Live experimental branch..."
531     LIVE_REPOSITORY_SECTIONS_drbl="$LIVE_REPOSITORY_SECTIONS_drbl live-stable live-testing live-unstable live-experimental"
532     ;;
533  *)
534     echo "Using DRBL live stable branch..."
535     LIVE_REPOSITORY_SECTIONS_drbl="$LIVE_REPOSITORY_SECTIONS_drbl live-stable"
536     ;;
537esac
538
539# If version_no is not assigned, use date (Ex. 20070409)
540[ -z "$version_no" ] && version_no="$(date +%Y%m%d)"
541target_iso="LiveKoha-${version_no}.orig.iso"
542real_target_iso="LiveKoha-${version_no}.iso"
543real_target_zip="LiveKoha-${version_no}.zip"
544
545
546[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
547echo "Creating a Ubuntu live cd iso which is used for clonezilla image with restoration function. The created iso will be in $target_iso"
548[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
549
550if [ "$desktop" = "gnome" ]; then
551  pkgs="$pkgs $PKG_GNOME"
552else
553  pkgs="$pkgs $PKG_XFCE"
554fi
555
556if [ "$verbose" = "on" ]; then
557  pref="bash -x"
558fi
559
560if [ "$use_existing_stage1_iso" = "no" ]; then
561  if [ -d "LiveKohaIMG" ]; then
562    echo "Found dir LiveKohaIMG, clean stale LiveKohaIMG files..."
563    chroot LiveKohaIMG/chroot umount /dev/pts &>/dev/null
564    chroot LiveKohaIMG/chroot umount /proc &>/dev/null
565    chroot LiveKohaIMG/chroot umount /sys &>/dev/null
566    (
567      cd LiveKohaIMG/
568      lh_clean
569    )
570    rm -rf LiveKohaIMG
571  fi
572 
573  mkdir LiveKohaIMG
574  (
575  cd LiveKohaIMG
576 
577  $pref lh_config --sections "$ubuntu_sections"
578  $pref lh_config --mirror-binary $mirror_url --mirror-binary-security $mirror_security_url
579  $pref lh_config --mirror-bootstrap $mirror_url
580  $pref lh_config --mirror-chroot $mirror_url --mirror-chroot-security $mirror_security_url
581 
582  # For Hardy, mkisofs is obsolete. Use genisoimage instead. Since aptitude won't fail if mkisofs (which is listed in drbl.conf) is not found in the repository. We can list mkisofs and genisoimage for pkgs. aptitude, unlike apt, won't exit if mkisofs is not found.
583  pkgs="$pkgs genisoimage"
584 
585  # Updated! 2007/12/27 with the patch from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=448210, now we can use cdebootstrap.
586  # ///OLD/// Here actually we can not use "--bootstrap cdebootstrap" due to this bug:
587  # ///OLD/// http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=448348&trim=no
588  # Looks like if we use "--apt apt" instead of "--apt aptitude", there are a lot of warning about failing authenticating deb packages.
589  $pref lh_config --bootstrap-flavour $debian_type --packages "$pkgs" --hook /home/koha/$run_hook_script --apt aptitude --apt-recommends disabled --binary-indices disabled --bootstrap cdebootstrap --tasksel none
590  #$pref lh_config --bootstrap-flavour $debian_type --packages "$pkgs" --hook /home/koha/test.sh --apt aptitude --apt-recommends disabled --binary-indices disabled --bootstrap cdebootstrap --tasksel none
591  # Since casper does not support aufs, and we need aufs to avoid this bug:
592  # https://bugs.launchpad.net/ubuntu/+source/linux-ubuntu-modules-2.6.22/+bug/150788. Comment this:
593  # //NOTE// We must use the live-initramfs patched by DRBL otherwise the created iso won't boot into command line. Some errors like:
594  # init:/etc/event.d/tty1:15: Unknown stanza
595  # will occur when booting, so upstart won't run gettty
596  $pref lh_config --initramfs live-initramfs
597  #$pref lh_config --linux-flavours generic --linux-packages "linux-restricted-modules"
598  $pref lh_config --linux-flavours generic
599 
600  # get the latest kernel ver "release_kernel_ver"
601  get_latest_kernel_in_repository
602  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
603  echo "The kernel version in this live CD will be: $release_kernel_ver"
604  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
605 
606  if [ "$debian_dist" = "gutsy" ]; then
607    # For Ubuntu 7.10, only unionfs comes with kernel, no aufs. However, we need aufs to avoid a bug (see above). An aufs module provided by DRBL works for this.
608    # $pref lh_config --distribution $debian_dist --union-filesystem aufs --linux-packages "linux-image${kernel_extra_tag} aufs-modules${kernel_extra_tag} squashfs-modules${kernel_extra_tag}"
609    # For gutsy: linux-image-2.6.22-14-386
610    # Live helper auto append "-386" for param from "--linux-packages"
611    # TODO: UGLY! 2.6.22-14 should not be hardcoded in this program. We should find a better solution to work with kernel and aufs module.
612    $pref lh_config --distribution $debian_dist --union-filesystem aufs
613    $pref lh_config --linux-packages "linux-image-$release_kernel_ver linux-ubuntu-modules-$release_kernel_ver aufs-modules-$release_kernel_ver"
614    # Exclude some stuffs from the squashfs root, since in Live system, we will only use vmlinuz and initrd in /{casper,live}, not in the /boot/ in the squashfs.
615    export MKSQUASHFS_OPTIONS="-no-duplicates -noappend -e boot"
616  elif [ "$debian_dist" = "hardy" ]; then
617    # For hardy, mkisofs was removed. Force to use genisoimage
618    # //NOTE// DO NOT put lh_config command option too long, otherwise lh_config will fail and show something like: E: internal error
619    # --genisoimage was removed in live-helper 1.0~a37
620    # ///NOTE/// From hardy with kernel 2.6.24-7 or later, linux-ubuntu-modules includes aufs module. Therefore aufs-modules-$release_kernel_ver is not requred anymore.
621    $pref lh_config --distribution $debian_dist --union-filesystem aufs
622    # $pref lh_config --linux-packages "linux-image-$release_kernel_ver linux-ubuntu-modules-$release_kernel_ver aufs-modules-$release_kernel_ver"
623    $pref lh_config --linux-packages "linux-image-$release_kernel_ver linux-ubuntu-modules-$release_kernel_ver"
624    # $pref lh_config --genisoimage genisoimage
625    # Exclude some stuffs from the squashfs root, since in Live system, we will only use vmlinuz and initrd in /{casper,live}, not in the /boot/ in the squashfs.
626    # Do not use lzma (For Hardy or later). /NOTE/ "-e dir_list" must be the last param for mksquashfs.
627    export MKSQUASHFS_OPTIONS="-no-duplicates -noappend -nolzma -e boot"
628  else
629    echo "This distribution $debian_dist is not supported."
630    echo "Program terminated!"
631    exit 1
632  fi
633 
634  # We force to use 486 kernel only.
635  $pref lh_config --linux-flavours generic
636 
637  # No memtest from debian, we will use the one from drbl since it's newer.
638  $pref lh_config --memtest disabled
639 
640  $pref lh_config --hostname "$debian_dist"
641  $pref lh_config --username koha --bootappend "username=koha"
642  $pref lh_config --syslinux-timeout 5
643  # Disable the security, otherwise live-helper >= 1.0~a37 does not support Ubuntu and will create a wrong sources.list for ubuntu updates and securit. We will create it by ourself.
644  $pref lh_config --security disabled
645  # prepare ubuntu updates and security source list
646cat << AddUBUNTURepository > config/chroot_sources/ubuntu.bootstrap
647deb $mirror_security_url ${debian_dist}-updates $ubuntu_sections
648deb $mirror_security_url ${debian_dist}-security $ubuntu_sections
649AddUBUNTURepository
650 
651  # put koha user's password
652  mkdir -p config/chroot_local-includes/usr/share/initramfs-tools/scripts/live-bottom/
653  cp $ocs_live_script_dir/10adduser config/chroot_local-includes/usr/share/initramfs-tools/scripts/live-bottom/
654 
655  # Put hook files
656  mkdir -p config/chroot_local-includes/home/koha/
657  if [ -d "$ocs_live_script_dir/koha-3.00.00-beta" ]; then
658    svn up $ocs_live_script_dir/koha-3.00.00-beta
659  else
660    svn co http://trac.nchc.org.tw/svn/koha/koha-3.00.00-beta $ocs_live_script_dir/koha-3.00.00-beta
661  fi
662  for i in $ocs_live_script_dir; do
663  #  cp -p -r $i/test.sh config/chroot_local-includes/home/koha/
664  #  cp -p -r $i/LiveKoha-functions config/chroot_local-includes/home/koha/
665    cp -p -r $i/* config/chroot_local-includes/home/koha/
666  done
667 
668  # prepare drbl source list
669  cat << AddDRBLRepository > config/chroot_sources/drbl.chroot
670deb $DRBL_REPOSITORY_URL drbl $LIVE_REPOSITORY_SECTIONS_drbl
671AddDRBLRepository
672 
673  # prepare drbl key
674  LANG=C wget -O config/chroot_sources/drbl.chroot.gpg $DRBL_GPG_KEY_URL
675 
676  $pref lh_build
677  )
678  mv -f LiveKohaIMG/binary.iso $target_iso
679else
680  echo "Use existing temp iso file: $target_iso"
681fi
682 
683[ -z "$target_media_file" ] && target_media_file="$TARGET_MEDIA_FILE_DEF"
684 
685# mount the stage 1 iso file
686stage1_iso_TMP="$(mktemp -d /tmp/ocs-iso.XXXXXX)"
687trap "[ -d "$stage1_iso_TMP" ] && umount $stage1_iso_TMP &>/dev/null && rm -rf $stage1_iso_TMP" HUP INT QUIT TERM EXIT
688ISOLNX_TMP="$(mktemp -d /tmp/isolnx.XXXXXX)"
689mount -o loop $target_iso $stage1_iso_TMP
690
691case "$target_media_file" in
692  cd|CD|iso|ISO)
693     create_drbl_live_iso
694     ;;
695  usb|zip)
696     create_drbl_live_zip
697     ;;
698  b|both|BOTH)
699     create_drbl_live_iso
700     create_drbl_live_zip
701     ;;
702esac
703# unmount all iso file
704umount $stage1_iso_TMP &>/dev/null
705# Clean the tmp working directory
706echo "Cleaning tmp dirs..."
707[ ! -z "$stage1_iso_TMP" ] && rm -rf $stage1_iso_TMP
708[ ! -z "$ISOLNX_TMP" ] && rm -rf $ISOLNX_TMP
709[ ! -z "$USB_TMP" ] && rm -rf $USB_TMP
710# clean the tmp iso.
711[ "$rm_tmp_iso" = "yes" -a -f "$target_iso" ] && rm -f $target_iso
712#
713case "$target_media_file" in
714  cd|CD|iso|ISO)
715     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
716     echo "$msg_burn_drbl_live_img_iso: $real_target_iso"
717     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
718     ;;
719  usb|zip)
720     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
721     echo "$msg_burn_drbl_live_img_zip: $real_target_zip"
722     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
723     ;;
724  b|both|BOTH)
725     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
726     echo "$msg_burn_drbl_live_img_iso: $real_target_iso"
727     echo "$msg_burn_drbl_live_img_zip: $real_target_zip"
728     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
729     ;;
730esac
Note: See TracBrowser for help on using the browser.