7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

apt-getで一括インストール

Last updated at Posted at 2015-07-28

ファイルに羅列したパッケージを一括インストール(bash編)

※githubに置きました → https://github.com/digitarhythm/apt-install
※「spitiko」でインストール出来ます。

おそらく車輪の再発明だが、備忘録として書いておく。
下記のようなbashスクリプトをパスの通ったところに「apt-install」みたいな名前で置いておく。

# !/bin/bash
# =====================================================
# apt-get install at once from package list file
# =====================================================
TARGET="$@"

# if [ -z ${TARGET} ]; then
if [ "${#}" -eq 0 ]; then
    echo "Usage:"
    echo "apt-install [package name | package list file]"
    exit
fi

if [ -f ${1} ]; then
    for line in `cat ${1}`
    do
        if [ -n "${line}" ]; then
            ret=`dpkg -l ${line} | egrep "i\s*?${line}"`
            if [ -z "${ret}" ]; then
                sudo apt-get install ${line} -y
            fi
        fi
    done
else
    for i in `seq 1 ${#}`; do
        sudo apt-get install ${1} -y
        shift
    done
fi

で、「require.txt」とかのファイルに、

git
php5-cli
php5-cgi
imagemagick

とか書いて、
$ apt-install ./require.txt
などと実行すると、入ってないものだけがインストールされる。
パッケージ名を指定するとそのままそのパッケージがインストールされる。
指定した名前がファイルかどうかで判断してるが、ファイルであるほうが優先される。
でも、ファイル名をなにかのパッケージ名と同じにしないようにしておくほうが後々のトラブルを防げるとは思う。
中で「sudo」をしてるので、自分のアカウントではパスワードが必要ないようにするとそのアカウントではそのまま使えます。
セキュリティがぁ〜という人は、sudoを外して「/usr/local/sbin」にでも置いて、スーパーユーザーで実行するようにするといいでせう。

7
7
4

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
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?