【问题标题】:How to determine the latest stable TuxOnIce version as compactly as possible如何尽可能紧凑地确定最新的稳定 TuxOnIce 版本
【发布时间】:2013-03-20 10:58:51
【问题描述】:

所以我打算在这里做的是从http://tuxonice.net/downloads/all/(当前为tuxonice-for-linux-3.8.0-2013-02-24.patch.bz2)确定最新的稳定版TuxOnIce。

让事情变得复杂的是没有“当前”链接,所以我们必须遵循版本控制,类似于(这些不存在):

tuxonice-for-linux-3.8.0-2013-4-2.patch.bz2
tuxonice-for-linux-3.8-4-2013-4-16.patch.bz2
tuxonice-for-linux-3.8-11-2013-5-23.patch.bz2

问题是它们会按这个顺序排列:

tuxonice-for-linux-3.8-11-2013-5-23.patch.bz2
tuxonice-for-linux-3.8-4-2013-4-16.patch.bz2
tuxonice-for-linux-3.8.0-2013-4-2.patch.bz2

我目前的实现(这是垃圾)是这样的。我考虑过使用日期,但也不知道该怎么做(/tmp/tuxonice 是索引文件):

_major=3.8 # Auto-generated
_TOI=$(grep ${_major}-1[0-9] /tmp/tuxonice | cut -d '"' -f2 | tail -1)
[ ! $_TOI ] && _TOI=$(grep ${_major}- /tmp/tuxonice | cut -d '"' -f2 | tail -1)
[ ! $_TOI ] && _TOI=$(grep ${_major}.0-2 /tmp/tuxonice | cut -d '"' -f2 | tail -1)

谢谢。

【问题讨论】:

    标签: bash sed grep cut tail


    【解决方案1】:

    使用网络服务器的功能将索引页面按修改日期倒序排序,使用lynx -dump 抓取页面,获取与您感兴趣的文件名匹配的第一行并打印相应的列。这为您提供了文件的绝对 URL,您可以从那里调整命令以提供您想要的确切输出(文件名,只是版本字符串,...)。

    $ lynx -dump 'http://tuxonice.net/downloads/all/?C=M&O=D'|awk '/^[[:space:]]*[[:digit:]]+\..+\/tuxonice-for-linux/ { print $2; exit }'
    http://tuxonice.net/downloads/all/tuxonice-for-linux-3.8.0-2013-02-24.patch.bz2
    

    仍然不是超级健壮,如果修改日期不符合预期,显然会中断,您可能还想稍微调整一下正则表达式以更具体。

    【讨论】:

    • 不知道您可以按日期对索引进行排序。因此,只要同一个内核没有任何其他版本,一个简单的grep ${_major} /tmp/tuxonice | cut -d '"' -f2 | head -1 就足够了(前面是curl -s "http://tuxonice.net/downloads/all/?C=M&O=D" -o /tmp/tuxonice)。
    • 没错!如果您好奇,请检查 Apache's documentation of mod_autoindex 以了解 (Apache) 索引的可能排序和格式参数。显然,这只有在他们坚持支持按 URL 参数排序的网络服务器时才有效(不是很多人这样做)。
    • 当然,grep -m1| head -1 还要好。现在才想起来。
    【解决方案2】:

    这不是一个真正的答案,但我认为这个“单线”[1] 很酷:

    HTML=$(wget -qO- http://tuxonice.net/downloads/all/ | grep tuxonice); TIMESTAMP=$(echo "$HTML" | sed 's/.*\([0-9]\{2\}-[A-Za-z]\{3\}-[0-9]\{4\} [0-9]\{2\}:[0-9]\{2\}\).*/\1/' | while read line; do echo $(date --date "$line" +%s) $line; done | sort | tail -n 1 | cut -d' ' -f2-3); LINK=$(echo "$HTML" | grep "$TIMESTAMP" | sed 's/.*href=\"\(.*\)\".*/\1/'); echo "http://tuxonice.net/downloads/all/${LINK}"
    

    打印:

    http://tuxonice.net/downloads/all/tuxonice-for-linux-3.8.0-2013-02-24.patch.bz2
    

    不过,这种方法实际上只是个玩笑。显然,有更好的方法可以做到这一点,也许使用支持 XML 解析的脚本语言。

    至少,这可能会让您对如何使用文件的日期/时间值来选择“最新”有所了解。但是我会谨慎使用它(因为上传日期可能与版本号不一致),并建议您的版本号想法可能是一个更好的主意,如果您可以以某种方式处理所有各种命名和版本编号方案,它们看起来像用过。

    [1] 这不是真正的单排

    【讨论】:

      猜你喜欢
      • 2012-12-28
      • 2023-01-28
      • 1970-01-01
      • 2017-04-10
      • 1970-01-01
      • 2015-12-22
      • 2011-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多