我有 3 个脚本来构建 OpenWrt,但我无法将其设置为最后有时间。这是脚本给出的内容和脚本。
openwrt-snapshot-r22256+29-14334c222e-ipq806x-generic-linksys_ea8500-sysupgrade.bin
但我想要随着时间的推移进行这样的描述:
openwrt-snapshot-r22256+29-14334c222e-20230310-ipq806x-generic-linksys_ea8500-sysupgrade.bin
剧本:
#!/bin/bash
# createbuildinfo
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/shared
STATUSFILE="$BINDIR/$BUILTBASENAME.status"
DIFFFILE="$BINDIR/$BUILTBASENAME.patch"
DIFFCONFIGFILE="$BINDIR/$BUILTBASENAME.diffconfig"
DATE=$(date +%Y%m%d-%H%M)
cd $BUILDROOT
echo "Creating build info for"
echo " $BUILTBASENAME in"
echo " $BINDIR "
getGitInfo() {
#params: directory
echo "###########################################################################"
(cd $1
echo -n "Repo : "
git remote -v show | grep fetch
echo -n "Branch : "
git rev-parse --abbrev-ref HEAD
echo -n "Commit : "
git show --format="%cd %h %s" --abbrev=7 --date=short | head -n 1 | cut -b1-60
echo "Status : "
git status --porcelain
)
}
getGitDiff() {
(cd $1
git --no-pager diff HEAD
)
}
echo "Generating git statusfile $STATUSFILE"
echo "Status for $BUILTBASENAME created $DATE" >$STATUSFILE
echo " " >>$STATUSFILE
getGitInfo $BUILDROOT >>$STATUSFILE
for feed in `cat feeds.conf | grep -v "^#" | awk '{print $2}'`
do
getGitInfo $BUILDROOT/feeds/$feed >>${STATUSFILE}
done
echo "Generating diff file $DIFFFILE"
getGitDiff $BUILDROOT >$DIFFFILE
echo "Generating diffconfile $DIFFCONFIGFILE"
$BUILDROOT/scripts/diffconfig.sh > $DIFFCONFIGFILE
#共享
#!/bin/bash
BRANCH="snapshot"
BUILDROOT="/run/media/james/D/ipq806x_builds/NSS_test/"
BUILTDIR="$BUILDROOT/../builds"
VERSION_NUMBER=$($BUILDROOT/scripts/getver.sh)
VERSION_DIST=$(grep CONFIG_VERSION_DIST $BUILDROOT/.config | awk -F\" '{print $2}')
VERSION_DIST="${VERSION_DIST:=OpenWRT}"
TARGET_PROFILE=$(grep CONFIG_TARGET_PROFILE $BUILDROOT/.config | awk -F\" '{print $2}' | sed 's/DEVICE_//')
TARGET_SUBTARGET=$(grep CONFIG_TARGET_SUBTARGET $BUILDROOT/.config | awk -F\" '{print $2}')
TARGET_BOARD=$(grep CONFIG_TARGET_BOARD $BUILDROOT/.config | awk -F\" '{print $2}')
BUILTBASENAME="${VERSION_DIST}-${BRANCH}-${VERSION_NUMBER}-${TARGET_BOARD}-${TARGET_SUBTARGET}-${TARGET_PROFILE}"
BUILTBASENAME=$(echo $BUILTBASENAME | sed 's/ /-/g' | awk '{print tolower($0)}')
BINDIR="$BUILDROOT/bin/targets/${TARGET_BOARD}/${TARGET_SUBTARGET}"
#createbuild
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/shared
echo "#### `date`: Starting build of $VERSION_DIST $VERSION_NUMBER ####"
cd $BUILDROOT
time make -j4 V=s 2>&1 $1 | tee build.log | grep -i -E "^make.*(error|[12345]...Entering dir)"
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
echo -en "\007"
echo "#### `date`: Build failed, bailing out... "
exit 1
fi
echo -en "\007"
echo "#### `date`: Build of $VERSION_DIST $VERSION_NUMBER complete ###"
if [ -z $1 ]; then
${SCRIPT_DIR}/createbuildinfo
echo "#### `date`: Moving completed build to $BUILTDIR/$BUILTBASENAME ####"
mkdir -p $BUILTDIR/$BUILTBASENAME
#mv -v $BINDIR/$BUILTBASENAME* $BUILTDIR/$BUILTBASENAME
mv -v /run/media/james/D/ipq806x_builds/NSS_test/bin/targets/ipq806x/generic/*.bin /run/media/james/D/ipq806x_builds/builds/latest/
rm $BUILTDIR/latest
ln -s $BUILTDIR/$BUILTBASENAME $BUILTDIR/latest
echo "All done! Sysupgrade file can be found in"
echo $BUILTDIR/latest/$BUILTBASENAME-squashfs-sysupgrade.bin
fi
答案1
在我看来,文件名(或至少包含版本标识符的部分)是在您的第二个脚本(标记为#shared)中构建的:
BUILTBASENAME="${VERSION_DIST}-${BRANCH}-${VERSION_NUMBER}-${TARGET_BOARD}-${TARGET_SUBTARGET}-${TARGET_PROFILE}"
由于该shared
脚本源自脚本的第二个非空非注释行,因此您对该行的变量createbuildinfo
进行初始化:DATE
DATE=$(date +%Y%m%d-%H%M)
……发生得太晚了。您必须将其移动到脚本的开头shared
,或移动到脚本的开头createbuildinfo
,位于以下行之前:
source ${SCRIPT_DIR}/shared
完成此更改后,您可以修改脚本BUILTBASENAME
中的分配shared
,如下所示:
# original version commented out
# BUILTBASENAME="${VERSION_DIST}-${BRANCH}-${VERSION_NUMBER}-${TARGET_BOARD}-${TARGET_SUBTARGET}-${TARGET_PROFILE}"
# date included
BUILTBASENAME="${VERSION_DIST}-${BRANCH}-${VERSION_NUMBER}-${DATE}-${TARGET_BOARD}-${TARGET_SUBTARGET}-${TARGET_PROFILE}"
请注意,当前定义的DATE=$(date +%Y%m%d-%H%M)
结果是 YYYYmmdd-HHMM 形式的时间戳,即它还包括时间。如果您不想这样做,请在或SHORTDATE=$(date +%Y%m%d)
的开头创建一个仅日期时间戳,并在构造 的值时使用代替。createbuildinfo
shared
SHORTDATE
DATE
BUILTBASENAME