我有 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
在我看来,文件名(或至少包含版本标识符的部分)是在您的第二个脚本(标记为#shared)中建立的,该行:
由于
shared
脚本来自脚本的第二个非空非注释行createbuildinfo
,因此您DATE
对该行变量的初始化:……发生得太晚了。您必须将它移到
shared
脚本的开头,或者移到createbuildinfo
脚本的开头,在该行之前:完成此更改后,您可以按如下方式修改脚本
BUILTBASENAME
中的分配:shared
请注意,当前定义的
DATE=$(date +%Y%m%d-%H%M)
时间戳格式为 YYYYmmdd-HHMM,即它还包括时间。如果您不希望这样,请在orSHORTDATE=$(date +%Y%m%d)
的开头创建一个仅限日期的时间戳,并在构造 的值时使用inplace of 。createbuildinfo
shared
SHORTDATE
DATE
BUILTBASENAME