Deb32位包转换64位包的脚本
Tofloor
poster avatar
Coollove
deepin
2012-04-11 23:38
Author
Deb32位包转换64位包的脚本
  1. #!/bin/bash
  2. #
  3. #Make 32 bit deb package installable in 64 bit system.       
  4. #author Jarlyyn hsu http://jarln.net
  5. #usage: deb32toall 32bir_deb_filename
  6. #depandment:zenity see about http://library.gnome.org/users/zenity/stable/
  7. #depandment:mktemp to make temp unzip folder
  8. #depandment:sed
  9. #depandment:dpkg dpkg-deb
  10. main()
  11. {
  12.   init_string
  13.   check_depandment
  14.   check_infile "$@"
  15.   convert_file
  16. }
  17. #Output string list
  18. init_string()
  19. {
  20.   outfile="%s.all.deb"
  21.   err_nofile="No selected file."
  22.   err_notdeb="文件必须以.deb结尾。"
  23.   err_notexist="指定的文件 %s 不存在。"
  24.   err_outfileexist="输出文件%s 已存在。转换终止。"
  25.   err_unparkerr="无法展开deb包,请检查 ' %s '的文件格式。\r\n%s"
  26.   err_makeerr="无法制作deb包,请检查 ' %s '文件及所在目录的权限。\r\n%s"
  27.   err_ok="转换完成,输出文件为 %s 。"
  28.   title_ok="转换完毕"
  29.   title_inputfile="请输入您要处理的32位deb文件"
  30.   progress_title="转换deb文件"
  31.   progress_text="正在转换……"
  32.   progress_unpack="解压缩DEB文件。"
  33.   progress_unpackcontrol="解压缩控制文件"
  34.   progress_sed="替换控制文件"
  35.   progress_make="生成deb文件。可能会花费较长时间,请稍候……"
  36.   progress_ok="转换完成,输出文件为 %s 。"
  37.   progress_rm="删除临时文件"
  38.   addition_depand=", ia32-libs, ia32-libs-gtk"
  39. }
  40. check_depandment()
  41. {
  42.   for cmd in "/usr/bin/zenity" "/bin/sed" "/bin/mktemp" "/usr/bin/dpkg" "/usr/bin/dpkg-deb"  
  43.   do
  44.     if [ ! -e $cmd ] ;then
  45.       echo "$cmd not found"
  46.       exit
  47.     fi
  48.   done
  49. }
  50. err(){
  51.   zenity --error --text="`printf "$@"`"
  52.   exit
  53. }
  54. info(){
  55.   zenity --info --title="$3" --text="`printf "$1" $2`"
  56. }
  57. # check input file
  58. check_infile()
  59. {
  60.   infile="$@"
  61.   if [ -z "$infile" ] ;then
  62.     #show file dialog
  63.     infile=`zenity --file-selection  --file-filter="*.deb" --title "$title_inputfile"`
  64.     if [ $? != 0 ] ;then
  65.       echo $err_nofile
  66.       exit
  67.     fi
  68.   fi
  69.   #Validate Filename
  70.   filename=`expr match "$infile" "\(.*\)\.deb$"`
  71.   if [ -z "$filename" ] ;then
  72.     err "$err_notdeb"
  73.   fi
  74.   filename=`printf "$outfile" "$filename"`
  75.   #find file
  76.   if [ ! -e "$infile" ] ;then
  77.     err "$err_notexist" "$infile"
  78.   fi
  79.   if [ -e "$filename" ] ;then
  80.     err "$err_outfileexist" "$filename"
  81.   fi
  82. }
  83. convert_file()
  84. {
  85.   tmpdir=`mktemp -d /tmp/deb32toall.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`
  86.   if [ ${tmpdir:0:5} != "/tmp/" -o  ! -d "$tmpdir" ] ;then
  87.     #make sure tmpdir
  88.     #make sure tmpdir is in /tmp/ for avoid wrong rm.
  89.     exit
  90.   fi
  91.   #########convert begin###########
  92.   (echo "10" ; echo "# $progress_unpack" ; dpgk_err=`dpkg-deb -x "$infile" "$tmpdir"`
  93.   if [ $? != 0 ] ;then
  94.     echo "100"
  95.     progress_err=-1
  96.     err "$err_unparkerr" "$infile" "$dpgk_err"
  97.   fi
  98.   echo "30" ; echo "# $progress_unpackcontrol" ; dpkg-deb --control "$infile" "$tmpdir/DEBIAN" > /dev/null
  99.   echo "35" ; echo "# $progress_sed" ; sed -i "s/^\s*Architecture:\s*i386\s*$/Architecture: all/" "$tmpdir/DEBIAN/control" > /dev/null
  100.   echo "40" ;sed -i -r "s/^\s*(Depends: .*)$/\1$addition_depand/" "$tmpdir/DEBIAN/control" > /dev/null
  101.   echo "50" ; echo "# $progress_make" ; dpgk_err=`dpkg -b "$tmpdir" "$filename"`
  102.   if [ $? != 0 ] ;then
  103.     progress_err=-1
  104.     err "$err_makeerr" "$filename" "$dpgk_err"
  105.   fi
  106.   echo "100";
  107.   )|zenity --progress \
  108.           --title="$progress_title" \
  109.           --text="$progress_text" \
  110.           --auto-close\
  111.           --percentage=0
  112.   rm "$tmpdir" -r -f
  113.   if [ "$?" == "-1" -o "$progress_err" == "-1" -o ! -e "$filename" ] ;then
  114.     exit
  115.   fi
  116.   info "$err_ok" "$filename" "$title_ok"
  117.   ###########convert end###########
  118.   ###########check for gdebi gui??
  119.   if [ -e "/usr/bin/gdebi-gtk" ] ;then
  120.     /usr/bin/gdebi-gtk "$filename"
  121.   elif [ -e "/usr/bin/gdebi-kde" ] ;then
  122.     /usr/bin/gdebi-kde "$filename"
  123.   fi
  124. }
  125. main "$@"
Copy the Code
Reply Favorite View the author
All Replies
cxbii
deepin
2012-04-11 23:46
#1
楼主自己写的?测试怎么样呢?
Reply View the author
Coollove
deepin
2012-04-12 00:35
#2
楼主自己写的?测试怎么样呢?
网上淘的,可以转换完成安装,终端启动安装后的程序查看缺少的lib。。自已ln -s
Reply View the author
cxbii
deepin
2012-04-12 00:59
#3
[quote]楼主自己写的?测试怎么样呢?
网上淘的,可以转换完成安装,终端启动安装后的程序查看缺少的lib。。自已ln -s[/quote]
ok!
Reply View the author