Advertisement
opexxx

genvm.sh

Feb 11th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 16.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. #    Contact            : FHH <fhh@e-galaxie.org>
  5. #    Web                : https://sourceforge.net/projects/genvm
  6. #    Description        : "genvm" Is a powerfull script bash to generate
  7. #   a minimal and complete virtual machine for KVM/QEMU, VirtualBox
  8. #   and/or VMWare.
  9. #    Licence            : GPL3
  10. #
  11. #    This program is free software: you can redistribute it and/or modify
  12. #    it under the terms of the GNU General Public License as published by
  13. #    the Free Software Foundation, either version 3 of the License, or
  14. #    (at your option) any later version.
  15. #
  16. #    This program is distributed in the hope that it will be useful,
  17. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. #    GNU General Public License for more details.
  20. #
  21. #    You should have received a copy of the GNU General Public License
  22. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23. #
  24.  
  25. trap end_of_script SIGINT SIGTERM SIGQUIT
  26.  
  27. NEEDED_COMMANDS="qemu-img qemu-nbd fdisk sync kpartx losetup mktemp mount source \
  28. debootstrap cat chroot umount modprobe cat source mkswap basename readlink dirname" ;
  29.  
  30. _SCRIPT_NAME=$(basename $0) ;
  31. _CONFIG_FILE="${HOME}/.${_SCRIPT_NAME}.conf /etc/${_SCRIPT_NAME}.conf" ;
  32. _VERBOSE=false ;
  33. _DEBUG=false ;
  34. _NBD="" ;
  35. _LOOP="" ;
  36. _THIRD_ONLY=false ;
  37. _INTERACTIVE_SEQUENCE=false ;
  38. _TMPDIR="/tmp" ;
  39. SECURE_TMOUT=1 ;
  40. ARCH="amd64" ;
  41. KERNEL="linux-image-" ;
  42. VERSION="wheezy" ;
  43. SERVER="http://ftp.debian.org/debian" ;
  44. SIZE="5G" ;
  45. FORMAT="raw" ;
  46.  
  47. declare -a STEPS ;
  48.  
  49. # Display help message :
  50. usage () {
  51.     cat <<EOF
  52. $0 [options] <hard drive image>
  53.  
  54.   ** Note that root privileges are needed to run $0 **
  55.  
  56. Options
  57.     -a  : architecture : amd64, i386 (default : ${ARCH})
  58.     -A  : additionals package to install in vm
  59.     -c  : specify a config file (first in ${_CONFIG_FILE})
  60.     -D  : debug mode
  61.     -f  : format of image : raw, qcow2, qcow, vmdk (default : ${FORMAT})
  62.     -h  : this message
  63.     -i  : run interactive shell before exiting
  64.     -k  : specify kernel version (default : ${KERNEL}${ARCH})
  65.     -l  : file containing list of additionnal packages (one per line)
  66.     -n  : virtual machine name (default : $(hostname -s))
  67.     -o  : change default tmp dir location (path with no space ; default "${_TMPDIR}")
  68.     -p  : root password (default : ask to user)
  69.     -P  : definition of partitions (not yet available)
  70.     -s  : image size (default : ${SIZE})
  71.     -S  : server to download debian (default : ${SERVER})
  72.     -t  : script to run after installation
  73.     -T  : run third party only
  74.     -v  : verbose mode
  75.     -V  : debian version : jessie, wheezy, ... (default : ${VERSION})
  76.  
  77. There is 2 posibilities to run third party scripts :
  78.  - create a single file containing script to run ;
  79.  - create a directory who contain list of files numeroted and fix in witch environment
  80. the script run :
  81.     3rd/
  82.      |- 01.chroot.norecommends
  83.      |- 01.host.java
  84.      ...
  85.      |- 01.post.chown
  86.      \`- 02.host.rc.local
  87.  
  88. All script with "chroot" is executed in chroot environement, all with "post" are run after
  89. image umount. "host" Run in host who generate environnement.
  90.  
  91. Script to run after installation can use some function and vaiables.
  92. All lines begin by \$CH is run in new environnement.
  93. Exemple :
  94.  
  95.     \$CH adduser foo
  96.     set_passwd_to foo bar
  97.     wget http://my.site/archive.zip -O \${MOUNT_POINT}/archive.zip
  98.  
  99. run "adduser" in new environnement, set foo password to bar and download http://my.site/archive.zip
  100. from host and paste it in the new environement.
  101. EOF
  102.     exit ${1:-1} ;
  103. }
  104.  
  105. die () {
  106.     enable_output ;
  107.     echo "$@" >&2 ;
  108.     cleaning ;
  109.     exit 1 ;
  110. }
  111.  
  112. Kill () {
  113.     enable_output ;
  114.     echo "$@" >&2 ;
  115.     echo "Hard end of script :-( " ;
  116.     exit 1 ;
  117. }
  118.  
  119. disable_output () {
  120.     exec 2>&1 ;
  121.     exec 3>&1 ;
  122.     exec >/dev/null 2>&1 ;
  123. }
  124.  
  125. enable_output () {
  126.     ${_VERBOSE} || {
  127.         exec 1>&3 ;
  128.         exec 2>&3 ;
  129.     }
  130. }
  131.  
  132. # find free loop
  133. find_loop () {
  134.     CALL_BACK=${1:-false} ;
  135.     _LOOP=$(losetup -f) ;
  136.     [ -z "${_LOOP}" ] && {
  137.         ${CALL_BACK} && {
  138.             die "ERR > No loop device found. Execution failed" ;
  139.         } || {
  140.             echo "No loop device found. Trying to load module" ;
  141.             modprobe loop || die "ERR > No loop device found and module cant be load" ;
  142.             find_loop true ;
  143.         }
  144.     }
  145.     echo "loop device ${_LOOP} seem free. Script use it." ;
  146. }
  147.  
  148. are_you_root () {
  149.     [ ${EUID:=1000} -ne 0 ] && {
  150.         echo "ERR > Script only run as root" >&2 ;
  151.         exit 1 ;
  152.     }
  153. }
  154.  
  155. # find free nbd
  156. find_nbd () {
  157.     CALL_BACK=${1:-false} ;
  158.     [ -e "/proc/partitions" ] || {
  159.         die "ERR > \"/proc/partitions\" not found. Execution failed" ;
  160.     }
  161.     for device in $(find /dev/ -maxdepth 1 -iname nbd* -exec basename {} \; | sort) ; do
  162.         echo "looking for network block device ${device}" ;
  163.         grep ${device} /proc/partitions || {
  164.             _NBD="/dev/${device}" ;
  165.             break ;
  166.         }
  167.     done
  168.     [ -z "${_NBD}" ] && {
  169.         ${CALL_BACK} && {
  170.             die "ERR > No free network block device found. Execution failed. Try modprobe nbd and run again." ;
  171.         } || {
  172.             echo "No nbd device found. Trying to nbd module" ;
  173.             modprobe nbd || die "ERR > No nbd device found and module cant be load" ;
  174.             find_nbd true ;
  175.         }
  176.     }
  177.     echo "network block device /dev/${device} seem free. Script use it." ;
  178. }
  179.  
  180. # Check requirements to script :
  181. check_requirements () {
  182.     for requirement in ${NEEDED_COMMANDS} ; do
  183.         echo -n "checking for \"$requirement\" ... " ;
  184.         command -v ${requirement} > /dev/null && {
  185.             echo "Ok" ;
  186.             continue ;
  187.         } || {
  188.             echo "required but not found !" ;
  189.             RETURN=1 ;
  190.         }
  191.         done
  192.     [ -z "${RETURN}" ] || {
  193.         die "ERR > Requirement missing. Try \"-v\" for more informations" ;
  194.     }
  195. }
  196.  
  197. # init output
  198. init_out () {
  199. #   Select debug mode
  200.     ${_DEBUG} && {
  201.         set -x
  202.         VERBOSE=true ;
  203.     }
  204. #   Select verbose mode
  205.     ${_VERBOSE} || { disable_output ; } ;
  206. }
  207.  
  208. # init environment
  209. init_env () {
  210. #   Search a config file   
  211.     for fic in ${_CONFIG_FILE} ; do
  212.         [ -r "${fic}" ] && {
  213.             echo "\"${fic}\" found and is readable : loading" ;
  214.             source ${fic} ;
  215.             break ;
  216.         }
  217.     done
  218.     : ${_NAME:=$(hostname -s)} ;
  219.     echo "virtual machine name : ${_NAME}" ;
  220.     : ${_FORMAT:=${CMD_FORMAT:=${FORMAT}}} ;
  221.     echo "type of image : ${_FORMAT}" ;
  222.     : ${_SIZE:=${SIZE}} ;
  223.     echo "size of vm : ${_SIZE}" ;
  224.     : ${_ARCH:=${CMD_ARCH:=${ARCH}}} ;
  225.     echo "architecture : ${_ARCH}" ;
  226.     : ${_VERSION:=${CMD_VERSION:=${VERSION}}} ;
  227.     echo "install debian ${_VERSION}" ;
  228.     : ${_SERVER:=${CMD_SERVER:=${SERVER}}} ;
  229.     [ ! -z "${CMD_LISTPKG}" ] && {
  230.         [ -r ${CMD_LISTPKG} ] && {
  231.             __content=$(sed '{s/[[:blank:]]//g;s/#.*$//g;s,//.*,,g;/^$/d;s/-$//}' ${CMD_LISTPKG}) ;
  232.             [ -z "${CMD_ADDPKG}" ] && {
  233.                 CMD_ADDPKG=$(echo ${__content} | sed -e 's/ /,/g') ;
  234.             } || {
  235.                 CMD_ADDPKG=${CMD_ADDPKG},$(echo ${__content} | sed -e 's/ /,/g') ;
  236.             }
  237.         } || {
  238.             echo "list of package not readable. skip it." ;
  239.             CMD_LISTPKG="" ;
  240.         }
  241.     }
  242.     echo "use server ${_SERVER} to installation" ;
  243.     case ${_ARCH} in
  244.         amd64)  KARCH=${_ARCH} ;;
  245.         i386)   KARCH="686" ;;
  246.         *)  die "ERR > Architecture unknown." ;;
  247.     esac
  248.     : ${_KERNEL:=${CMD_KERNEL:=${KERNEL}${KARCH}}} ;
  249.     echo "install kernel : ${_KERNEL}" ;
  250.     : ${_ROOTPWD:="${CMD_ROOTPWD:="${ROOTPWD:=""}"}"} ;
  251.     [ ! -z "${_PARTITIONS}" ] && {
  252.         [ -r ${_PARTITIONS} ] && {
  253.             echo "partitions file to use : ${_PARTITIONS}" ;
  254.         } || {
  255.             unset _PARTITIONS ;
  256.             echo "default partition schema (file can't be read)" ;
  257.         }
  258.     }
  259.     [ -z "${CMD_ADDPKG}" ] || \
  260.         CMD_ADDPKG=",${CMD_ADDPKG}" ;
  261.     find_nbd ;
  262.     find_loop ;
  263. }
  264.  
  265. secure_tmout () {
  266.     [ ${SECURE_TMOUT:=0} -gt 0 ] && {
  267.         echo "Add delay for old or slow computers (${SECURE_TMOUT} sec)" ;
  268.         sleep ${SECURE_TMOUT} ;
  269.     }
  270. }
  271.  
  272. create_vm_hd () {
  273.     echo "create vm hard drive ${HD_IMG} (format ${_FORMAT})" ;
  274.     qemu-img create -f ${_FORMAT} "${HD_IMG}" ${_SIZE} || \
  275.         die "ERR > making ${HD_IMG} failed. Execution failed" ;
  276.     echo "hard drive created" ;
  277.     secure_tmout ;
  278. }
  279.  
  280. hd2nbd () {
  281.     HD_FULL_PATH=$(dirname "$(readlink -f "${HD_IMG}")")/$(basename "${HD_IMG}") ;
  282.     echo "associate vm hd (${HD_FULL_PATH}) to nbd (${_NBD})" ;
  283.     qemu-nbd -c ${_NBD} "${HD_FULL_PATH}" || \
  284.         die "ERR > association ${_NBD} to ${HD_IMG} failed. Execution failed" ;
  285.     STEPS[${#STEPS[@]}]="free_nbd" ;
  286.     echo "association ok" ;
  287.     secure_tmout ;
  288. }
  289.  
  290. free_nbd () {
  291.     echo "freeing nbd ${_NBD}" ;
  292.     qemu-nbd -d ${_NBD} || {
  293.         unset STEPS[${#STEPS[@]}-1] ;
  294.         Kill "ERR > ${_NBD} wont be free." ;
  295.     }
  296.     echo "Freeing nbd ${_NBD} ok" ;
  297.     secure_tmout ;
  298. }
  299.  
  300. end_of_script () {
  301.     echo "" ;
  302.     die " *** Script stopped by user *** " ;
  303. }
  304.  
  305. cleaning () {
  306.     while [ ${#STEPS[@]} -gt 0 ] ; do
  307.         ${STEPS[${#STEPS[@]}-1]} ;
  308.         unset STEPS[${#STEPS[@]}-1] ;
  309.     done
  310.     echo "delete temporary mount point (if needed)" ;
  311.     [ -d "${_MOUNT_POINT}" ] && {
  312.         grep "${_MOUNT_POINT}" /proc/mounts && {
  313.             die "ERR > mount point \"${_MOUNT_POINT}\" still in use. Script cant erase it." ;
  314.         } || {
  315.             rm -rf "${_MOUNT_POINT}" ;
  316.         }
  317.     }
  318. }
  319.  
  320. partitiondrive () {
  321.     [ -z "${_PARTITIONS}" ] && {
  322.         fdisk ${_NBD} <<EOF
  323. n
  324. p
  325. 1
  326.  
  327.  
  328. a
  329. 1
  330. p
  331. w
  332. EOF
  333.     }
  334.     return 0 ;
  335. }
  336.  
  337. detect_partitions () {
  338.     echo "detecting partitions" ;
  339.     kpartx -av ${_NBD} || {
  340.         die "ERR > partitions detection failed. Exit." ;
  341.     }
  342.     STEPS[${#STEPS[@]}]="free_part" ;
  343.     echo "partitions detected" ;
  344.     secure_tmout ;
  345. }
  346.  
  347. free_part () {
  348.     echo "freeing partitions schema" ;
  349.     kpartx -dv ${_NBD} || {
  350.         unset STEPS[${#STEPS[@]}-1] ;
  351.         Kill "ERR > partitions wont be free. Exit." ;
  352.     }
  353.     echo "cleaning partitions ok" ;
  354.     secure_tmout ;
  355. }
  356.  
  357. create_filesystem () {
  358.     [ -z "${_PARTITIONS}" ] && {
  359.         mkfs.ext4 /dev/mapper/$(basename ${_NBD})p1 || {
  360.             die "ERR > partition can't be formated. Exit." ;
  361.         }
  362.     }
  363. }
  364.  
  365. assos2loop () {
  366.     echo "assosiate first partition to loop device" ;
  367.     losetup ${_LOOP} /dev/mapper/$(basename ${_NBD})p1 || {
  368.         die "ERR > associate first partition to loop device failed. Exit. Try modprobe loop and run again." ;
  369.     }
  370.     STEPS[${#STEPS[@]}]="free_loop" ;
  371.     echo "association partition / loop ok" ;
  372.     secure_tmout ;
  373. }
  374.  
  375. free_loop () {
  376.     echo "freeing loop device" ;
  377.     losetup -d ${_LOOP} || {
  378.         unset STEPS[${#STEPS[@]}-1] ;
  379.         Kill "ERR > Freeing loop device failed. Exit. Try modprobe loop and run again." ;
  380.     }
  381.     echo "freeing loop ok" ;
  382.     secure_tmout ;
  383. }
  384.  
  385. create_tempdir () {
  386.     _MOUNT_POINT="$(mktemp -p "${_TMPDIR}" -d)" ;
  387.     [ -z "${_MOUNT_POINT}" ] && {
  388.         die "ERR > Mount point not create. Exit" ;
  389.     }
  390.     echo "mount point created : ${_MOUNT_POINT}" ;
  391. }
  392.  
  393. mount_partitions () {
  394.     echo "mounting filesystems" ;
  395.     mount ${_LOOP} "${_MOUNT_POINT}" || {
  396.         die "ERR > Impossible to mount ${_LOOP} in ${_MOUNT_POINT}. Exit." ;
  397.     }
  398.     STEPS[${#STEPS[@]}]="umount_dev" ;
  399.     echo "filesystems monted" ;
  400. }
  401.  
  402. umount_dev () {
  403.     umount ${_LOOP} || {
  404.         unset STEPS[${#STEPS[@]}-1] ;
  405.         Kill "ERR > partition still monted. Exit." ;
  406.     }
  407.     echo "filesystems unmounted" ;
  408. }
  409.  
  410. install_sys () {
  411.     echo "debootstrap --arch=${_ARCH} --include=grub2,${_KERNEL}${CMD_ADDPKG} --variant=minbase ${_VERSION} ${_MOUNT_POINT} ${_SERVER}" ;
  412.     debootstrap --arch=${_ARCH} --include=grub2,${_KERNEL}${CMD_ADDPKG} --variant=minbase ${_VERSION} "${_MOUNT_POINT}" ${_SERVER} || {
  413.         die "ERR > installation failed. Exit." ;
  414.     }
  415. }
  416.  
  417. mount_fs_dev () {
  418.     echo "mounting dev" ;
  419.     mount -o bind /dev/ "${_MOUNT_POINT}"/dev/ || {
  420.         die "ERR > failed to mount /dev in chroot" ;
  421.     }
  422.     STEPS[${#STEPS[@]}]="umount_fs_dev" ;
  423.     echo "dev mounted" ;
  424. }
  425.  
  426. umount_fs_dev () {
  427.     umount -l "${_MOUNT_POINT}"/dev/ || {
  428.         unset steps[${#steps[@]}-1] ;
  429.         kill "err > failed to umount /dev in chroot" ;
  430.     }
  431.     echo "dev unmounted" ;
  432. }
  433.  
  434. mount_fs_proc () {
  435.     echo "mounting proc" ;
  436.     mount -t proc proc "${_MOUNT_POINT}"/proc/ || {
  437.         die "ERR > failed to mount /proc in chroot" ;
  438.     }
  439.     STEPS[${#STEPS[@]}]="umount_fs_proc" ;
  440.     echo "proc mounted" ;
  441. }
  442.  
  443. umount_fs_proc () {
  444.     umount -l "${_MOUNT_POINT}"/proc/ || {
  445.         unset steps[${#steps[@]}-1] ;
  446.         kill "err > failed to umount /proc in chroot" ;
  447.     }
  448.     echo "proc unmounted" ;
  449. }
  450.  
  451. mapping_grub () {
  452.     cat > "${_MOUNT_POINT}"/boot/grub/device.map <<EOF
  453. (hd0) ${_NBD}
  454. (hd0,1) ${_LOOP}
  455. EOF
  456. }
  457.  
  458. install_grub () {
  459.     echo "chroot ${_MOUNT_POINT} /usr/sbin/grub-install --no-floppy --grub-mkdevicemap=/boot/grub/device.map --root-directory=/ ${_NBD}" ;
  460.     chroot "${_MOUNT_POINT}" <<__EOF__
  461. source /etc/profile
  462. /usr/sbin/grub-install --no-floppy --grub-mkdevicemap=/boot/grub/device.map --root-directory=/ ${_NBD}
  463. __EOF__
  464.     [ $? -gt 0 ] && {
  465.         die "ERR > Installation of grub failed. Exit." ;
  466.     }
  467.     chroot "${_MOUNT_POINT}" <<__EOF__
  468. source /etc/profile
  469. grub-mkconfig | grep -v ^[[:blank:]]loopback.* | grep -v "^[[:blank:]]set\ root=.*" > /boot/grub/grub.cfg
  470. __EOF__
  471.     [ $? -gt 0 ] && {
  472.         echo "WARNING > Update grub2 failed !" >&2 ;
  473.     }
  474. }
  475.  
  476. set_passwd_to () {
  477.     [ -z "${1}" ] && {
  478.         echo "Nothing to do. Skip password setting." ;
  479.         return 0 ;
  480.     }
  481.     USER_TARGET=${1} ;
  482.     [ -z "${2}" ] && {
  483.         enable_output ;
  484.         echo "Set password to ${USER_TARGET} > " ;
  485.         chroot "${_MOUNT_POINT}" /usr/bin/passwd "${USER_TARGET}" ;
  486.         init_out ;
  487.         return 0 ;
  488.     }
  489.     shift ;
  490.     PASSWD="${@}" ;
  491.     chroot "${_MOUNT_POINT}" /usr/bin/passwd "${USER_TARGET}" <<EOF
  492. ${PASSWD}
  493. ${PASSWD}
  494. EOF
  495. }
  496.  
  497. clean_install () {
  498.     chroot "${_MOUNT_POINT}" apt-get clean
  499. }
  500.  
  501. set_machine_name () {
  502.     echo ${_NAME} > "${_MOUNT_POINT}"/etc/hostname ;
  503. }
  504.  
  505. run_ch () {
  506.     CH="chroot ${MOUNT_POINT}" ;
  507.     $CH <<[*_EOF_*]
  508. source /etc/profile
  509. $(cat ${1})
  510. [*_EOF_*]
  511. }
  512.  
  513. excute_third_part () {
  514.     echo "Keep current location for bad scripters ..." ;
  515.     __current_location=${PWD} ;
  516.  
  517.     [ ! -z "${CMD_THIRD}" ] && {
  518.         MOUNT_POINT="${_MOUNT_POINT}" ;
  519.         CH="chroot ${MOUNT_POINT}" ;
  520.  
  521.         [ -d "${CMD_THIRD}" ] && {
  522.             for _file in $(find "${CMD_THIRD}" \( -type f -o -type l \) \
  523.                 -a -regex "${CMD_THIRD}/[0-9]+.*" | sort) ; do
  524.                 echo ${_file} | grep -P "[0-9]{2}\.chroot.*" && {
  525.                     echo "Running ${_file} in chroot environment" ;
  526.                     run_ch "${_file}"
  527.                 }
  528.                 echo ${_file} | grep -P "[0-9]{2}\.host.*" && {
  529.                     echo "Running ${_file} on host" ;
  530.                     source ${_file} ;
  531.                     cd ${__current_location} ;
  532.                 }
  533.             done
  534.         }
  535.         [ -f "${CMD_THIRD}" ] && {
  536.             [ -r "${CMD_THIRD}" ] && {
  537.                 . "${CMD_THIRD}" ;
  538.             } || {
  539.                 echo "Third party unreadable. Ignored." ;
  540.             }
  541.         }
  542.     }
  543.     cd ${__current_location} ;
  544. }
  545.  
  546. execute_post_install () {
  547.     [ ! -z "${CMD_THIRD}" ] && {
  548.         [ -d "${CMD_THIRD}" ] && {
  549.             for _file in $(find "${CMD_THIRD}" \( -type f -o -type l \) \
  550.                 -a -regex "${CMD_THIRD}/[0-9]+.*" | sort) ; do
  551.                 echo ${_file} | grep -P "[0-9]{2}\.post.*" && {
  552.                     echo "Running ${_file} after all" ;
  553.                     source ${_file} ;
  554.                 }
  555.             done
  556.         }
  557.     }
  558. }
  559.  
  560. interactive_seq () {
  561.     enable_output ;
  562.     echo -ne "\n\n*** ENTERING IN INTERACTIVE SHELL ***\n\n" ;
  563.     echo "You are here : ${PWD}" ;
  564.     echo "Virtual machine is monted here : ${_MOUNT_POINT}" ;
  565.     echo "Press \"Ctrl+d\" or \"exit\" to exit" ;
  566.     echo -ne "\n\n" ;
  567.     /bin/bash --noprofile --norc ;
  568.     echo -ne "\n\n*** END OF INTERACTIVE SEQUENCE ***\n\n" ;
  569.     init_out ;
  570. }
  571.  
  572. step_by_step () {
  573.     ${_THIRD_ONLY} || create_vm_hd ;
  574.     hd2nbd ;
  575.     ${_THIRD_ONLY} || partitiondrive ;
  576.     detect_partitions ;
  577.     ${_THIRD_ONLY} || create_filesystem ;
  578.     assos2loop ;
  579.     create_tempdir ;
  580.     mount_partitions ;
  581.     ${_THIRD_ONLY} || install_sys ;
  582.     mount_fs_dev ;
  583.     mount_fs_proc ;
  584.     ${_THIRD_ONLY} || mapping_grub ;
  585.     ${_THIRD_ONLY} || install_grub ;
  586.     ${_THIRD_ONLY} || set_machine_name ;
  587.     ${_THIRD_ONLY} || set_passwd_to root "${_ROOTPWD}" ;
  588.     ${_THIRD_ONLY} || clean_install ;
  589.     excute_third_part ;
  590.     ${_INTERACTIVE_SEQUENCE} && interactive_seq ;
  591.     cleaning ;
  592.     execute_post_install ;
  593. }
  594.  
  595. # main part
  596. # Partitionnement in developpement option -P
  597. while getopts ":a:hc:vDn:f:k:s:S:p:V:A:t:l:Tio:" opt ; do
  598.     case ${opt} in
  599.         h)
  600.             usage 0 ;;
  601.         a)
  602.             CMD_ARCH=${OPTARG} ;;
  603.         A)
  604.             CMD_ADDPKG=${OPTARG} ;;
  605.         c)
  606.             _CONFIG_FILE=${OPTARG} ;;
  607.         D)
  608.             _DEBUG=true ;;
  609.         f)
  610.             CMD_FORMAT=${OPTARG} ;;
  611.         i)
  612.             _INTERACTIVE_SEQUENCE=true ;;
  613.         k)
  614.             CMD_KERNEL=${OPTARG} ;;
  615.         l)
  616.             CMD_LISTPKG=${OPTARG} ;;
  617.         o)
  618.             echo "${OPTARG}" | grep [[:blank:]] > /dev/null && {
  619.                 echo -e "> No space authorized in name of alternative temp dir (option \"-o\").\n" ;
  620.                 usage ;
  621.             }
  622.             [ -d "${OPTARG}" -a -w "${OPTARG}" ] && {
  623.                 _TMPDIR="${OPTARG%/}" ;
  624.             } || {
  625.                 echo "WARN > ${OPTARG} not a directory or not writable. Option ignored" ;
  626.             } ;;
  627.         p)
  628.             CMD_ROOTPWD="${OPTARG}" ;;
  629.         P)
  630.             _PARTITIONS=${OPTARG} ;;
  631.         s)
  632.             SIZE=${OPTARG} ;;
  633.         S)
  634.             CMD_SERVER=${OPTARG} ;;
  635.         t)
  636.             CMD_THIRD=${OPTARG%/} ;;
  637.         T)
  638.             _THIRD_ONLY=true ;;
  639.         n)
  640.             _NAME="${OPTARG,,}" ;;
  641.         v)
  642.             _VERBOSE=true ;;
  643.         V)
  644.             CMD_VERSION=${OPTARG} ;;
  645.         :)
  646.             echo -e "> Option -$OPTARG requiert un argument.\n" ;
  647.             usage ;;
  648.         *)
  649.             echo -e "> Invalide option \"-$OPTARG\".\n" ;
  650.             usage ;;
  651.     esac
  652. done
  653.  
  654. shift $((OPTIND-1))
  655. case $# in
  656.     0)
  657.         usage 0 ;;
  658.     1)
  659.         HD_IMG="${1}" ;;
  660.     *)
  661.         echo -e "> Bad number of arguments\n\t${0} <hard drive image>\n" ;
  662.         usage ;;
  663. esac
  664.  
  665. are_you_root ;
  666. init_out ;
  667. check_requirements ;
  668. init_env ;
  669. step_by_step ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement