从另一个文件加载bash中的变量
我为各种Android设备构建了一些ROM和其他软件,为了让我更容易,我使用了基于bash的脚本。 下面是我的TWRP构建脚本中的一个示例:从另一个文件加载bash中的变量,bash,workflow,Bash,Workflow,我为各种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 -
#!/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脚本。是的,这非常可行,而且也是一件好事 将配置放在一个文件中,比如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在您的路径中,您可以简单地说:
source tw_config.sh
行
。build/envsetup.sh
已经在这样做了。查看envsetup.sh的内部,您将看到类似的命令(可能还有一些控制设置内容的逻辑)。祝你好运