我在这里一直在挣扎,如果它能被整合的话,那就太棒了。
我的想法是,创建一个函数,它将在某个时间运行,它将检查是否有新版本的脚本。但我不知道怎么把命令组合起来。
我这里已经有一种素描:

SCRIPT_NAME="$0"
ARGS="$@"
NEW_FILE="/tmp/blog.sh"
VERSION="1.0"

check_upgrade () {

# check if there is a new version of this file
# here, hypothetically we check if a file exists in the disk.
# it could be an apt/yum check or whatever...
[ -f "$NEW_FILE" ] && {


# install a new version of this file or package
# again, in this example, this is done by just copying the new file
echo "Found a new version of me, updating myself..."
cp "$NEW_FILE" "$SCRIPT_NAME"
rm -f "$NEW_FILE"

# note that at this point this file was overwritten in the disk
# now run this very own file, in its new version!
echo "Running the new version..."
$SCRIPT_NAME $ARGS

# now exit this old instance
exit 0
}

我知道这样做是可能的,但我在网上没有发现任何有用的东西。
每一个建议都将非常感谢。

最佳答案

假设脚本始终在运行,则制作另一个卷曲文件的脚本,并将其与原始文件进行对照检查。类似于:

if [ version newer ]; then
    kill old verseion
    mv "new version" 'old version"
    ./new version
else:
    delete tmp file
fi

以你认为合适的间隔与cron一起运行

关于linux - 在Shell中集成了内置的Update函数,以便在可用时接收OTA更新,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31145682/

10-14 14:35
查看更多