LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 803|回复: 1

哪位兄弟对bash shell 脚本编程熟悉的?请教下,修改boot script

[复制链接]
发表于 2008-11-8 23:23:57 | 显示全部楼层 |阅读模式
打算修改该文件放到mkcpio.conf中创建从硬盘、U盘、移动硬盘(USB-ZIP & USB-Floppy)、光驱的启动intrd.img.....

下面这个script只是寻找上有archlive.sqfs文件的设备
(硬盘或USB-ZIP或USB-Floppy或USB-CDROM或CDROM),然后将挂载这些设备。。。


以下是Godan写的bootall脚本http://github.com/godane/archiso ... chiso/hooks/bootall

主页:http://arch-live.blogspot.com/

run_hook ()
{
    # external drives may need to settle
    msg ":: Waiting for usb devices to settle..."
    /sbin/udevadm trigger --subsystem-match=usb
    /sbin/udevadm settle
    sleep 5

    msg ":: Scanning for boot cdrom device..."
   
    /bin/mkdir -p /bootmnt
    /bin/mkdir -p /live
    live="/live"
    bootmnt="/bootmnt"
    found=0
   
    if [ "${break}" = "y" ]; then
        echo ":: Break requested, type 'exit' to resume operation"
        echo "   NOTE: klibc contains no 'ls' binary, use 'echo *' instead"
        PS1="ramfs$ " /bin/sh -i
    fi
   
        if [ "x${bootiso}" != "x" ]; then
           for usb in /dev/sd[a-z][0-9]; do
        if mount -t vfat "${usb}" ${bootmnt} >/dev/null 2>&1 ||\
           mount -t ntfs-3g "${usb}" ${bootmnt} >/dev/null 2>&1 ||\
           mount -t ext2 "${usb}" ${bootmnt} >/dev/null 2>&1; then
            if [ -e "${bootmnt}/${bootiso}" ]; then
                found=1
                msg "${usb}"
                            break
                        fi
        else
              echo "Failed to mount ${usb}"
        fi
        [ ${found} -eq 0 ] && umount ${bootmnt} >/dev/null 2>&1
        done
        
    elif [ "${bootusb}" = "y" ]; then
        for usb in /dev/sd[a-z][0-9]; do
        if mount -t vfat "${usb}" ${bootmnt} >/dev/null 2>&1 ||\
           mount -t ntfs-3g "${usb}" ${bootmnt} >/dev/null 2>&1 ||\
           mount -t ext2 "${usb}" ${bootmnt} >/dev/null 2>&1; then
                if [ "x${from}" != "x" ]; then
                if [ -e "${bootmnt}/${from}/archlive.sqfs" ]; then
                    found=1
                    msg "${usb}"
                            /bin/mount -o bind "${bootmnt}/${from}" "${live}"
                    break
                fi
                    else
                    if [ -e "${bootmnt}/archlive.sqfs" ]; then
                    found=1
                    msg "${usb}"
                    break
                fi
                fi
            else
               echo "Failed to mount ${usb}"
            fi
        [ ${found} -eq 0 ] && umount ${bootmnt} >/dev/null 2>&1
        done
        
    else
        /bin/modprobe -q isofs >/dev/null 2>&1
        for cdrom in /dev/sr[0-9]; do
            if mount -r -t iso9660 "${cdrom}" ${bootmnt} >/dev/null 2>&1; then
                    if [ -e "${bootmnt}/archlive.sqfs" ]; then
                    found=1
                    msg "${cdrom}"
                    break
                fi
                else
                    echo "Failed to mount ${cdrom}"
                fi
        [ ${found} -eq 0 ] && umount ${bootmnt} >/dev/null 2>&1
        done
    fi
       
    if [ ${found} -eq 0 ]; then
            if [ "${bootusb}" = "y" ]; then
                    echo "ERROR: cannot find booted usb device, cannot continue..."
            else
            echo "ERROR: cannot find booted cdrom device, cannot continue..."
            fi
            exit 1
    else
        export BOOT_MOUNT="${bootmnt}"
    fi

}
 楼主| 发表于 2008-11-9 15:13:08 | 显示全部楼层

改动了两个 但有错误,帮忙修改下了。。。

第一个版本:

提示  line 98: syntax error near unexpected token `done'

  1. test_live_data_dir ()
  2. {
  3.     /bin/mount -r -t iso9660 "$1" $2 >/dev/null 2>/dev/null || \
  4.     /bin/mount -r -t vfat -o noatime,nodiratime "$1" $2 >/dev/null 2>/dev/null || \
  5.     /bin/mount -r -t ntfs-3g -o noatime,nodiratime "$1" $2 >/dev/null 2>/dev/null || \
  6.     /bin/mount -r -t ext2 -o noatime,nodiratime "$1" $2 >/dev/null 2>/dev/null
  7.     if [ $? -eq 0 ]; then
  8.         if [ -f "$2/${from}/carbon" ]; then
  9.             LDEV="$1"
  10.             msg_ " ... found at $1"
  11.             found=1
  12.             return 0
  13.         else
  14.             /bin/umount $2 2>/dev/null
  15.             msg_ " ... $1 mounted, but no 'carbon' found"
  16.         fi
  17.     else
  18.         msg_ "  ... not $1"
  19.     fi
  20.     return 1
  21. }


  22. run_hook ()
  23. {
  24.     # external drives may need to settle
  25.     msg ":: Waiting for usb devices to settle..."
  26.     /sbin/udevadm trigger --subsystem-match=usb
  27.     /sbin/udevadm settle
  28.     sleep 5

  29.     msg_ ":: Scanning for boot device..."
  30.     /bin/mkdir -p /bootmnt
  31.     /bin/mkdir -p /live
  32.     live="/live"
  33.     bootmnt="/bootmnt"
  34.     found=0      
  35.    
  36.     if [ "${break}" = "y" ]; then
  37.         echo ":: Break requested, type 'exit' to resume operation"
  38.         echo "   NOTE: klibc contains no 'ls' binary, use 'echo *' instead"
  39.         PS1="ramfs$ " /bin/sh -i
  40.     fi
  41.         
  42.     # look for livecd data directory, first try ${root}
  43.     LDEV="${root}"
  44.     if [ "x${LDEV}" != "x" ]; then
  45.         /bin/mount -r -t iso9660 "${LDEV}" "${bootmnt}" >/dev/null 2>/dev/null || \
  46.         /bin/mount -r -t vfat -o noatime,nodiratime "${LDEV}" "${bootmnt}" >/dev/null 2>/dev/null || \
  47.         /bin/mount -r -t ntfs-3g -o noatime,nodiratime "${LDEV}" "${bootmnt}" >/dev/null 2>/dev/null || \
  48.         /bin/mount -r -t ext2 -o noatime,nodiratime "${LDEV}" "${bootmnt}" >/dev/null 2>/dev/null
  49.         if [ $? -eq 0 ]; then
  50.             if [ -d "${bootmnt}/${from}/carbon" ]; then
  51.                 msg_ ":: Archlive system at ${LDEV}"
  52.                 /bin/mount -o bind "${bootmnt}/${from}" "${live}"
  53.                 found=1
  54.                 break
  55.             else
  56.                 /bin/umount "${bootmnt}" 2>/dev/null
  57.                 echo "!! No Archlive system at ${LDEV}"
  58.                 LDEV=""
  59.             fi
  60.         else
  61.             echo "!! Couldn't mount ${LDEV}"
  62.             LDEV=""
  63.         fi
  64.     fi

  65.     # then try cdroms
  66.     if [ "x${LDEV}" = "x" ]; then
  67.         msg_ ":: Looking for boot device"
  68.         cdroms=$( /bin/cat /proc/sys/dev/cdrom/info | { while read a b c; do
  69.                 if [ "${a}" = "drive" -a "${b}" = "name:" ]; then
  70.                     echo "${c}"
  71.                     break
  72.                 fi
  73.             done
  74.         } )
  75.         for i in ${cdroms}; do
  76.             test_live_data_dir "/dev/${i}" "${bootmnt}"
  77.             if [ $? -eq 0 ]; then break; fi
  78.         done
  79.     fi

  80.     # test USB devices (and disks) repeatedly until timed out
  81.     if [ "x${LDEV}" = "x" ]; then
  82.         msg_ ":: Searching for usb (and disk) devices .."
  83.         for i in 1 2 3 4 5; do
  84.             msg_ " :wait ${i} :::"
  85.             /bin/sleep ${i}
  86.             for d in /dev/sd[a-z][0-9]*; do
  87.                 test_live_data_dir "${d}" "${bootmnt}"
  88.                 if [ $? -eq 0 ]; then break 2; fi
  89.             done
  90.         done
  91.     fi
  92.     export BOOT_MOUNT="${bootmnt}"
  93. done
  94. }
复制代码


第二个版本
提示  line 63: syntax error near unexpected token `elif'

  1. run_hook ()
  2. {
  3.     # external drives may need to settle
  4.     msg ":: Waiting for usb devices to settle..."
  5.     /sbin/udevadm trigger --subsystem-match=usb
  6.     /sbin/udevadm settle
  7.     sleep 5

  8.     msg ":: Scanning for boot cdrom device..."
  9.    
  10.     /bin/mkdir -p /bootmnt
  11.     /bin/mkdir -p /live
  12.     live="/live"
  13.     bootmnt="/bootmnt"
  14.     found=0
  15.    
  16.     if [ "${break}" = "y" ]; then
  17.         echo ":: Break requested, type 'exit' to resume operation"
  18.         echo "   NOTE: klibc contains no 'ls' binary, use 'echo *' instead"
  19.         PS1="ramfs$ " /bin/sh -i
  20.     fi
  21.    
  22.     # look for livecd data directory, first try ${root}
  23.     LDEV="${root}"
  24.     if [ "x${LDEV}" != "x" ]; then
  25.         /bin/mount -r -t iso9660 "${LDEV}" "${bootmnt}" >/dev/null 2>/dev/null || \
  26.         /bin/mount -r -t vfat -o noatime,nodiratime "${LDEV}" "${bootmnt}" >/dev/null 2>/dev/null || \
  27.         /bin/mount -r -t ntfs-3g -o noatime,nodiratime "${LDEV}" "${bootmnt}" >/dev/null 2>/dev/null || \
  28.         /bin/mount -r -t ext2 -o noatime,nodiratime "${LDEV}" "${bootmnt}" >/dev/null 2>/dev/null
  29.         if [ $? -eq 0 ]; then
  30.             if [ -d "${bootmnt}/${from}/carbon" ]; then
  31.                 msg_ ":: Archlive system at ${LDEV}"
  32.                 /bin/mount -o bind "${bootmnt}/${from}" "${live}"
  33.                 found=1
  34.                 break
  35.             else
  36.                 /bin/umount "${bootmnt}" 2>/dev/null
  37.                 echo "!! No Archlive system at ${LDEV}"
  38.                 LDEV=""
  39.             fi
  40.         else
  41.             echo "!! Couldn't mount ${LDEV}"
  42.             LDEV=""
  43.         fi
  44.     fi
  45.    
  46.         if [ "x${bootiso}" != "x" ]; then
  47.            for usb in /dev/sd[a-z][0-9]; do
  48.            if mount -t vfat "${usb}" ${bootmnt} >/dev/null 2>&1 ||\
  49.                mount -t ntfs-3g "${usb}" ${bootmnt} >/dev/null 2>&1 ||\
  50.                mount -t ext2 "${usb}" ${bootmnt} >/dev/null 2>&1; then
  51.                     if [ -e "${bootmnt}/${bootiso}" ]; then
  52.                         found=1
  53.                         msg "${usb}"
  54.                                     break
  55.                                 fi
  56.                     else
  57.                     echo "Failed to mount ${usb}"
  58.             fi
  59.            [ ${found} -eq 0 ] && umount ${bootmnt} >/dev/null 2>&1
  60.         done
  61.         
  62.     elif [ "${bootusb}" = "y" ]; then
  63.         for usb in /dev/sd[a-z][0-9]; do
  64.            if mount -t vfat "${usb}" ${bootmnt} >/dev/null 2>&1 ||\
  65.               mount -t ntfs-3g "${usb}" ${bootmnt} >/dev/null 2>&1 ||\
  66.               mount -t ext2 "${usb}" ${bootmnt} >/dev/null 2>&1; then
  67.                     if [ "x${from}" != "x" ]; then
  68.                     if [ -e "${bootmnt}/${from}/carbon" ]; then
  69.                         found=1
  70.                         msg "${usb}"
  71.                                 /bin/mount -o bind "${bootmnt}/${from}" "${live}"
  72.                         break
  73.                     fi
  74.                         else
  75.                         if [ -e "${bootmnt}/carbon" ]; then
  76.                         found=1
  77.                         msg "${usb}"
  78.                         break
  79.                        fi
  80.                     fi
  81.             else
  82.                 echo "Failed to mount ${usb}"
  83.             fi
  84.          [ ${found} -eq 0 ] && umount ${bootmnt} >/dev/null 2>&1   
  85.          done
  86.     else
  87.         /bin/modprobe -q isofs >/dev/null 2>&1
  88.         for cdrom in /dev/sr[0-9]; do
  89.             if mount -r -t iso9660 "${cdrom}" ${bootmnt} >/dev/null 2>&1; then
  90.                     if [ -e "${bootmnt}/${from}/carbon" ]; then
  91.                     found=1
  92.                     msg "${cdrom}"
  93.                     break
  94.                 fi
  95.             else
  96.                 echo "Failed to mount ${cdrom}"
  97.             fi
  98.             [ ${found} -eq 0 ] && umount ${bootmnt} >/dev/null 2>&1
  99.         done
  100.     fi
  101.     export BOOT_MOUNT="${bootmnt}"
  102. }
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表