2017-12-01 25 views
2

다양한 Android 디바이스 용 ROM 및 기타 소프트웨어를 빌드하고 더 쉽게 사용할 수 있도록 bash 기반 스크립트를 사용합니다.다른 파일에서 bash로 변수로드하기

#!/usr/bin/env bash 

# Variables 
export TW_DEVICE_VERSION="0" 
export BRANCH="android-5.1" 

# Don't touch this 
VERSION=$(grep "TW_MAIN_VERSION_STR" bootable/recovery/variables.h -m 1 | cut -d \" -f2)-${TW_DEVICE_VERSION} 

# Acer Liquid Z500 specific TWRP build configuration 
export BRAND="acer" 
export DEVICE="acer_Z500" 

git clone https://github.com/liquidporting/android_device_${BRAND}_${DEVICE}.git -b ${BRANCH} device/${BRAND}/${DEVICE} 
. build/envsetup.sh 
lunch omni_${DEVICE}-eng 
mka recoveryimage > twrp_${DEVICE}.log 
cd out/target/product/${DEVICE} 
if [ -f "recovery.img" ] 
then 
    mv recovery.img twrp-${VERSION}-${DEVICE}.img 
else 
    echo "" 
    echo "*******************************************************************************" 
    echo "Something went wrong during the build process, try checking your device tree." 
    echo "After that, run the script again and see if you messed up something new or not." 
    echo "*******************************************************************************" 
    echo "" 
fi 

if [ -f "twrp-${VERSION}-${DEVICE}.img" ] 
then 
    megarm /Root/LPAD/TWRP/twrp-${VERSION}-${DEVICE}.img 
    megarm /Root/LPAD/TWRP/twrp_${DEVICE}.log 
    megaput --no-progress --path /Root/LPAD/TWRP twrp-${VERSION}-${DEVICE}.img 
    megaput --no-progress --path /Root/LPAD/TWRP ../../../../twrp_${DEVICE}.log 
fi 

if [ -f "twrp-${VERSION}-${DEVICE}.img" ] 
then 
    cd ../../../.. 
    rm twrp_${DEVICE}.log 
    make clean 
    cd device 
    rm -rf ${BRAND} 
    cd .. 
else 
    rm twrp_${DEVICE}.log 
    make clean 
    cd device 
    rm -rf ${BRAND} 
    cd .. 
    echo "" 
    echo "**************************************************************" 
    echo "The build process of TWRP Recovery failed for device ${DEVICE}" 
    echo "**************************************************************" 
    echo "" 
    exit 
fi 

# Lenovo A328 specific TWRP build configuration 
export BRAND="lenovo" 
export DEVICE="A328" 

git clone https://github.com/liquidporting/android_device_${BRAND}_${DEVICE}.git -b ${BRANCH} device/${BRAND}/${DEVICE} 
. build/envsetup.sh 
lunch omni_${DEVICE}-eng 
mka recoveryimage > twrp_${DEVICE}.log 
cd out/target/product/${DEVICE} 
if [ -f "recovery.img" ] 
then 
    mv recovery.img twrp-${VERSION}-${DEVICE}.img 
else 
    echo "" 
    echo "*******************************************************************************" 
    echo "Something went wrong during the build process, try checking your device tree." 
    echo "After that, run the script again and see if you messed up something new or not." 
    echo "*******************************************************************************" 
    echo "" 
fi 

if [ -f "twrp-${VERSION}-${DEVICE}.img" ] 
then 
    megarm /Root/LPAD/TWRP/twrp-${VERSION}-${DEVICE}.img 
    megarm /Root/LPAD/TWRP/twrp_${DEVICE}.log 
    megaput --no-progress --path /Root/LPAD/TWRP twrp-${VERSION}-${DEVICE}.img 
    megaput --no-progress --path /Root/LPAD/TWRP ../../../../twrp_${DEVICE}.log 
fi 

if [ -f "twrp-${VERSION}-${DEVICE}.img" ] 
then 
    cd ../../../.. 
    rm twrp_${DEVICE}.log 
    make clean 
    cd device 
    rm -rf ${BRAND} 
    cd .. 
else 
    rm twrp_${DEVICE}.log 
    make clean 
    cd device 
    rm -rf ${BRAND} 
    cd .. 
    echo "" 
    echo "**************************************************************" 
    echo "The build process of TWRP Recovery failed for device ${DEVICE}" 
    echo "**************************************************************" 
    echo "" 
    exit 
fi 

지침 및 변수의 세트를 포함 다른 하나를 구축 포함하는 분리 bash는 스크립트를 가질 수 있습니다 : 여기 내 TWRP 빌드 스크립트의 예입니다?

나는 이런 식으로 뭔가 의미 :

#!/usr/bin/env bash 

export TW_DEVICE_VERSION="0" 
export BRANCH="android-5.1" 

VERSION=$(grep "TW_MAIN_VERSION_STR" bootable/recovery/variables.h -m 1 | cut -d \" -f2)-${TW_DEVICE_VERSION} 

export BRAND="acer" 
export DEVICE="acer_Z500" 

export BRAND="lenovo" 
export DEVICE="A328" 

export BRAND="doogee" 
export DEVICE="X5" 

을하지만 각 장치 별 구성 후 나는 빌드 지침이 포함 bash는 스크립트를 실행하는 데 필요합니다.

+1

라인'. build/envsetup.sh'은 이미 그것을하고 있습니다. 'envsetup.sh' 내부를 살펴보면 비슷한 명령을 볼 수있을 것입니다. 행운을 빕니다. – shellter

답변

1

네, 그럴 가능성이 매우 높습니다. 또한 그렇게하는 것이 좋습니다.

구성을 파일 (예 : tw_config.sh)에 넣으십시오. 그런 다음, 구성 스크립트이 방법을 호출 :

source /path/to/tw_config.sh 
if [ $? -ne 0 ]; then 
    # couldn't load config 
    # your logic here - makes sense to exit 
fi 

을 tw_config.sh이 PATH에있는 경우, 당신은 단순히 말할 수있다 :

source tw_config.sh