Kouhei Sutou
kou****@clear*****
Fri Sep 5 10:48:09 JST 2014
> +exist_user() {
> + grep "^$1:" /etc/passwd > /dev/null
> +}
/etc/passwdをgrepするより
getent passwd "$USER"
とか
id "$USER"
とした方がポータブルですよ。
getentやidだとLDAPやNISなど/etc/passwd以外の他の仕組みですで
に存在するユーザーもチェックしてくれるので、/etc/passwdでは
存在しないと思ったけどuseraddしたらすでに存在した、というこ
とがおきないと思います。
In <87c2607b725912da7179fe4efc259c598ecabd72 �� jenkins.clear-code.com>
"[Groonga-commit] long-long-float/droonga-engine �� 87c2607 [master] Add check on whether user has already existed." on Thu, 04 Sep 2014 01:32:12 +0900,
long-long-float <null+groonga �� clear-code.com> wrote:
> long-long-float 2014-09-04 01:32:12 +0900 (Thu, 04 Sep 2014)
>
> New Revision: 87c2607b725912da7179fe4efc259c598ecabd72
> https://github.com/long-long-float/droonga-engine/commit/87c2607b725912da7179fe4efc259c598ecabd72
>
> Merged e1158cd: Merge pull request #23 from long-long-float/safer-install-script
>
> Message:
> Add check on whether user has already existed.
>
> Modified files:
> script/install.sh
>
> Modified: script/install.sh (+5 -1)
> ===================================================================
> --- script/install.sh 2014-09-03 18:03:42 +0900 (674073e)
> +++ script/install.sh 2014-09-04 01:32:12 +0900 (d9584ed)
> @@ -8,13 +8,17 @@ apt-get -y upgrade
> apt-get install -y ruby ruby-dev build-essential
> gem install droonga-engine
>
> +exist_user() {
> + grep "^$1:" /etc/passwd > /dev/null
> +}
> +
> # fetch files
> SCRIPT_URL=https://raw.githubusercontent.com/droonga/droonga-engine/master/script
> curl -O $SCRIPT_URL/droonga-engine -O $SCRIPT_URL/droonga-engine.yaml
>
> # add droonga-engine user and create files
> USER=droonga-engine
> -useradd -m $USER
> +exist_user $USER || useradd -m $USER
>
> DROONGA_BASE_DIR=/home/$USER/droonga
> droonga-engine-catalog-generate --output=./catalog.json