LoginSignup
11
12

More than 5 years have passed since last update.

Self-extracting Shell Script

Posted at

シェルスクリプトとアーカイブをくっつけて自己解凍できるやつ。
Unixのインストーラでこういうのありますよね。
こういう技は素晴らしいですね。しかもお手軽だし。
http://stackoverflow.com/questions/20758981/self-extracting-script-in-sh-shell

スクリプトを作成。perlでもpythonでもshでもなんでもいいです。
スクリプトの最後だという識別子を入れておきます。ここでは#EOF#という識別子を書いています。

header.sh
#!/bin/sh
num=0
sed '1,/^#__EOF__#$/d' $0 | zcat - | tar xvf - 2>&1  |\
while read  mod
do
  num=`expr $num + 1`
  echo -ne "$num : $mod\r"
  sleep 0.1
done
echo ""

exit
#__EOF__#

スクリプトと展開したいアーカイブをくっつけます。

$ cat header.sh data.tgz > self-extract.tgz.bin

アーカイブに実行権限を付けて実行

$ chmod +x self-extract.tgz.bin
$ ./self-extract.tgz.bin
11
12
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12