B2G(FirefoxOS)のconfig.sh
#!/bin/bash REPO=${REPO:-./repo}
echo ${name:-value}
もし変数nameが空白(セットされていない場合も含む)であれば、「value」がその値となります。以下のコマンド郡と同じような意味となります。
repo_sync() { rm -rf .repo/manifest* && $REPO init -u $GITREPO -b $BRANCH -m $1.xml && $REPO sync ret=$? if [ "$GITREPO" = "$GIT_TEMP_REPO" ]; then rm -rf $GIT_TEMP_REPO fi if [ $ret -ne 0 ]; then echo Repo sync failed exit -1 fi }
case `uname` in "Darwin") CORE_COUNT=`system_profiler SPHardwareDataType | grep "Cores:" | sed -e 's/[ a-zA-Z:]*\([0-9]*\)/\1/'` ;; "Linux") CORE_COUNT=`grep processor /proc/cpuinfo | wc -l` ;; *) echo Unsupported platform: `uname` exit -1 esac
$ uname
Linux
$ uname --all
Linux ubuntu1204 3.2.0-38-generic #61-Ubuntu SMP Tue Feb 19 12:18:21 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
$ grep processor /proc/cpuinfo
processor : 0
processor : 1
processor : 2
processor : 3
$ grep processor /proc/cpuinfo | wc -l
4
GITREPO=${GITREPO:-"git://github.com/mozilla-b2g/b2g-manifest"} BRANCH=${BRANCH:-v1-train} GIT_TEMP_REPO="tmp_manifest_repo" if [ -n "$2" ]; then <= 2番めの引数がある? どうやって使うんだろ? GITREPO=$GIT_TEMP_REPO rm -rf $GITREPO && <= rm temp git init $GITREPO && <= git init git://github.com/mozilla-b2g/b2g-manifest cp $2 $GITREPO/$1.xml && <= cp $2 temp/$1(galaxy_nexus).xml cd $GITREPO && <= cd temp git add $1.xml && <= git add $1(galaxy_nexus).xml git commit -m "manifest" && <= git commit -m "manifest" git branch -m $BRANCH && <= git branch -m $BRANCH cd .. <= cd .. fi
条件式で-n 変数名とすると変数内の文字列の長さがゼロでないかどうか調べることができます。ゼロでない場合にはthen以後の命令が実行されます。
引数は、シェルスクリプトからは順番に$1、$2、$3、……として参照できます。
command $1 $2
echo MAKE_FLAGS=-j$((CORE_COUNT + 2)) > .tmp-config echo GECKO_OBJDIR=$PWD/objdir-gecko >> .tmp-config echo DEVICE_NAME=$1 >> .tmp-config
$ bash -verbose ./config.sh emulator $ cat .tmp-config MAKE_FLAGS=-j6 GECKO_OBJDIR=/home/B2G_gen/objdir-gecko DEVICE_NAME=emulator DEVICE=generic LUNCH=full-eng
case "$1" in "galaxy-nexus") echo DEVICE=maguro >> .tmp-config && repo_sync $1 ;; "emulator") echo DEVICE=generic >> .tmp-config && echo LUNCH=full-eng >> .tmp-config && repo_sync $1 ;; "emulator-x86") echo DEVICE=generic_x86 >> .tmp-config && echo LUNCH=full_x86-eng >> .tmp-config && repo_sync emulator ;; *) echo Usage: $0 \(device name\) echo echo Valid devices to configure are: echo - galaxy-nexus echo - emulator echo - emulator-x86 exit -1 ;; esac
if [ $? -ne 0 ]; then <=前の処理結果が0以外は、失敗 echo Configuration failed exit -1 fi
#!/bin/bash mkdir test rm test <= これでエラーになると以下のifに入る if [ $? -ne 0 ]; then echo Configuration failed exit -1 fi
mv .tmp-config .config echo Run \|./build.sh\| to start building
if 文と test コマンド - UNIX & Linux コマンド・シェルスクリプト リファレンス