免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1289 | 回复: 0
打印 上一主题 下一主题

[其他] 今天无事,写了个生成单安装文件的脚本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-11-27 16:42 |只看该作者 |倒序浏览
参数你的 安装脚本名称 和 安装包名称(tar包什么的)

  1. #!/bin/bash
  2. str='000000000000000'
  3. onekeyfile='onekey.sh'
  4. shfile=''
  5. tarfile=''

  6. for tmp in $@
  7. do
  8.         case $tmp in
  9.         shfile=*)
  10.                 shfile=$(echo $tmp|awk -F= '{print $2}')
  11.                 ;;
  12.         tarfile=*)
  13.                 tarfile=$(echo $tmp|awk -F= '{print $2}')
  14.                 ;;
  15.         *)
  16.                 echo 'Usage:'
  17.                 echo '  makeone.sh shfile=<install script> tarfile=<source file>'
  18.         esac
  19. done
  20. [[ ! -f $shfile ]] && shfile=''
  21. [[ ! -f $tarfile ]] && tarfile=''
  22. while [[ $shfile == '' || $tarfile == '' ]]
  23. do
  24.         [[ $shfile == '' ]] && read -p 'input install script file name:' shfile
  25.         [[ ! -f $shfile ]] && shfile=''
  26.         [[ $tarfile == '' ]] && read -p 'input source file name:' tarfile
  27.         [[ ! -f $tarfile ]] && tarfile=''
  28. done

  29. echo '#!/bin/bash
  30. count="000000000000000"
  31. shfilebyte="000000000000000"
  32. count=$(echo $count|sed "s/^0*//g")
  33. shfilebyte=$(echo $shfilebyte|sed "s/^0*//g")
  34. shfileend=$(($count+$shfilebyte))
  35. sh_file=ins.sh
  36. tar_file=file.tar.gz
  37. dd if=$0 of=$sh_file bs=1 skip=$count count=$shfilebyte
  38. dd if=$0 of=$tar_file bs=1 skip=$shfileend
  39. chmod 755 ./$sh_file
  40. eval ./$sh_file $tar_file
  41. exit' > $onekeyfile
  42. chmod 755 $onekeyfile

  43. headsize=$(stat -c %s $onekeyfile)
  44. headstr=${str:0:$((15-${#headsize}))}
  45. sed -i "/^count/s/$str/$headstr$headsize/g" $onekeyfile

  46. #cat $shfile >> $onekeyfile
  47. dd if=./$shfile of=$onekeyfile bs=1 seek=$headsize
  48. shfilesize=$(stat -c %s $shfile)
  49. if [[ ${#shfilesize} -gt 15 ]]
  50. then
  51.         echo "$shfile is too big to make one step install file"
  52.         exit 1
  53. fi
  54. headstr=${str:0:$((15-${#shfilesize}))}
  55. sed -i "/^shfilebyte/s/$str/$headstr$shfilesize/g" $onekeyfile

  56. #cat $tarfile >> $onekeyfile
  57. shfileend=$(($headsize+$shfilesize))
  58. dd if=./$tarfile of=$onekeyfile bs=1 seek=$shfileend
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP