Linux .bin安裝檔案製作

來源:互聯網
上載者:User

一 Linux安裝檔案

Linux常見的安裝為tar,zip,gz,rpm,deb,bin等。我們可以簡單的分為三類,

第一:打包或壓縮檔tar,zip,gz等,一般解壓後即可,或者解壓後運行sh檔案;

第二:對應的有管理工具的deb,rpm等,通常的這類安裝檔案可以通過第三方的命令列或UI來簡單的安裝,例如Ubuntu中的apt來安裝deb,Redhat中的yum來安裝rpm;

第三:像.bin類,其實就是把sh和zip打包為bin,或把sh和rpm打包為bin等,當在命令列運行bin安裝檔案時,其實就是bin裡面的sh來解壓bin中的zip或安裝rpm的過程;

 

二 .bin安裝檔案

.bin安裝檔案可以認為是sh檔案和zip或rpm等其他安裝檔案的打包形式。如:

 

.bin安裝檔案的優點:

1)只有一個包即.bin檔案;

2)可以直接運行在Linux上,因為他是sh(他的前半部分是sh);

3)在sh中可以包含需要使用者接收的協議資訊,而且提示使用者接收,如果使用者不接收,安裝退出;

 

三 .bin安裝檔案執行

1)超級簡單: sh xxxx.bin 或直接xxxx.bin。

 2)過程如下:

 

四 .bin安裝檔案製作

1) 組成之sh檔案(例子:YYYY.bin)

 

#!/bin/sh
PATH=/usr/bin:/bin
umask 022
echo_args="-e "
localinstall=$1
more <<"EOF"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxx
EOF
agreed=
while [ x$agreed = x ]; do
    echo
    echo "Do you agree to the above license terms? [yes or no] "
    read reply leftover
    case $reply in
    y* | Y*)
        agreed=1;;
    n* | N*)
    echo "If you don't agree to the license you can't install this software";
    exit 1;;
    esac
done
if [ -d "$localinstall" ] ; then
    outname=$localinstall/OUTNAME
else
    outname=OUTNAME
fi
echo "Unpacking..."
tail -n +AAA$0 > $outname    
if [ -x /usr/bin/sum ] ; then
    echo "Checksumming..."

    sum=`/usr/bin/sum $outname`
    index=1
    for s in $sum
    do
    case $index in
    1)  sum1=$s;
        index=2;
        ;;
    2)  sum2=$s;
        index=3;
        ;;
    esac
    done
    if [ $sum1 != SUM1 -o $sum2 != SUM2 ] ; then
    echo "The download file appears to be corrupted."
    echo "Please do not attempt to install this archive file."
    exit 1
    fi
else
    echo "Can't find /usr/bin/sum to do checksum.  Continuing anyway."
fi
echo "Done."
exit 0

#此檔案YYYY.bin可以重複使用,OUTNAME,SUM1,SUM2均為標識符,表示要打包到bin中的zip,rpm的路徑,sum的checksum和filesize。

#使用者協議處:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxx

#tail -n +AAA $0 > $outname,AAA為此sh檔案的line count, 此命令即把bin中的sh後面的zip或rpm提取出來 ;

# sum用來檢測所提取的zip或rpm檔案是否正確;

#最後一定要exit 0,一定要。
#也可以在退出前雲新unzip或rpm來安裝,或者由使用者自行來安裝zip或rpm。

 

2)組成之zip,gz或rpm (例子:XXXX.rpm)

 這個就是你要安裝的zip或rpm。

 

3)建立bin安裝檔案的指令碼sh(例子:createbin.sh,使用上面的YYYY.sh和XXXX.rpm)

#!/bin/sh

PATH=.:$PATH
RPM=XXXX.rpm
LICENSEBIN=YYYY.bin
BASE=$(basename $RPM .rpm)
sum=`sum $RPM`
index=1
for s in $sum
do
  case $index in
    1) sum1=$s;
       index=2;
       ;;
    2) sum2=$s;
       index=3;
       ;;
  esac
done
cat $LICENSEBIN | sed -e s/OUTNAME/$RPM/ -e s/SUM1/$sum1/ -e s/SUM2/$sum2/ > linux_license_new.bin
dos2unix -k -q linux_license_new.bin
cat linux_license_new.bin $RPM >${BASE}-rpm.bin
sudo chmod a+x res/${BASE}-rpm.bin

# dos2unix 確保license shell為linux格式;

#且此shell檔案需要在Linux上執行;

 

五 參考:http://itboba.com/taxonomy/term/1015 

 

完!

感謝,Thanks!

作者:iTech
出處:http://itech.cnblogs.com/

本文著作權歸作者iTech所有,轉載請包含作者簽名和出處,不得用於商業用途,非則追究法律責任!

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.