【发布时间】:2017-12-02 14:03:42
【问题描述】:
我为各种 Android 设备构建了一些 ROM 和其他软件,为了让我更轻松,我使用基于 bash 的脚本。 这是我的 TWRP 构建脚本中的一个示例:
#!/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 脚本包含构建指令和另一个包含一组变量?
我的意思是这样的:
#!/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 脚本。
【问题讨论】:
-
. build/envsetup.sh行已经在这样做了。查看envsetup.sh的内部,您会看到类似的命令(可能还有一些控制设置的逻辑)。祝你好运。