AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 792245
Accepted
Dimitrios Desyllas
Dimitrios Desyllas
Asked: 2025-03-11 02:26:57 +0800 CST2025-03-11 02:26:57 +0800 CST 2025-03-11 02:26:57 +0800 CST

为什么在我的脚本中我无法在 Debian 上放置多行文本变更日志条目?

  • 772

我正在使用这个 bash 脚本自动升级我的项目版本:

#!/usr/bin/env bash

CHANGELOG="Changelog.md"
DEBIAN_CHANGELOG="debian/changelog"
UPSTREAM_VERSION=$(cat VERSION)

# Updating entries in rpm files

DEB_RELEASE_NOTES=$(awk '{print "  * " $0}' < RELEASE_NOTES)

echo "Adding new Debian changelog entry for version $UPSTREAM_VERSION."
dch -D unstable -m "$DEB_RELEASE_NOTES" --newversion "$UPSTREAM_VERSION-0debian1-unstable1"

# Prompt user to edit Debian changelog
$EDITOR_CHOICE "$DEBIAN_CHANGELOG"

echo "Version updated successfully: $UPSTREAM_VERSION"

它的作用是同步并将版本放在 rpm 和 debian 包中。但是这个命令:

dch -D unstable -m "$DEB_RELEASE_NOTES" --newversion "$UPSTREAM_VERSION-0debian1-unstable1"

给我带来了一些麻烦,因为在 debian/changelog 中存在以下内容:

mkdotenv (0.2.0-0debian1-unstable1) unstable; urgency=medium

  *   * 1. Split codebase into multiple files.   * 2. Use a seperate
    version file and define built version upon compile.   * 4. [BUGFIX]
    If input file is same as output file copy input file into a
    temporary one.   * 5. Improved Documentation

 -- Dimitrios Desyllas <[email protected]>  Mon, 10 Mar 2025 20:08:00 +0200

该RELEASE_NOTES文件包含:

1. Split codebase into multiple files.
2. Use a seperate version file and define built version upon compile.
4. [BUGFIX] If input file is same as output file copy input file into a temporary one.
5. Improved Documentation

您知道为什么所有行都卡在单个项目符号中吗?

shell-script
  • 2 2 个回答
  • 371 Views

2 个回答

  • Voted
  1. Stephen Kitt
    2025-03-11T03:40:45+08:002025-03-11T03:40:45+08:00

    dch需要单个未修饰的变更日志条目。它将为您格式化,添加星号并根据需要换行。

    对于您的用例,您需要对每个条目运行一次,而无需指定目标发行版。然后,要“关闭”目标版本的条目,请运行

    dch -M -r -D unstable ignored
    

    这需要一个参数但忽略它,因此有“忽略”参数。-r更新变更日志中的第一行以指定给出的分布-D;-M使用“维护者”字段中指定的名称和电子邮件地址,而debian/control不是依赖环境变量。

    总体流程如下:

    DEB_VERSION="$UPSTREAM_VERSION-0debian1-unstable1"
    while IFS= read -r line; do
      dch -v "$DEB_VERSION" -- "$line"
    done < RELEASE_NOTES
    dch -M -r -D unstable ignored
    

    无需“初始化”新版本,当dch给定的版本与变更日志顶部的版本不匹配时,它会自动发生。

    • 6
  2. Best Answer
    Dimitrios Desyllas
    2025-03-11T04:32:56+08:002025-03-11T04:32:56+08:00

    最后正如@Stephen Kitt 所说:

    #!/usr/bin/env bash
    
    UPSTREAM_VERSION=$(cat VERSION)
    
    echo "Adding new Debian changelog entry for version $UPSTREAM_VERSION."
    
    DEB_VERSION="$UPSTREAM_VERSION-0debian1~unstable1"
    
    if [ -f DEBEMAIL ];then
        DEBEMAIL_VAL=$(cat DEBEMAIL)
    fi
    
    DEBEMAIL_VAL=$(dialog --inputbox "Enter your email:" 8 50 "$DEBEMAIL_VAL" 3>&1 1>&2 2>&3)
    
    if [ ! -z "$DEBEMAIL_VAL" ]; then
        echo $DEBEMAIL_VAL > DEBEMAIL
    fi
    
    export DEBEMAIL=$DEBEMAIL_VAL
    
    dch --distribution unstable --newversion $DEB_VERSION -m ""
    while IFS= read -r line; do
        echo $line;
        dch -a "$line"
    done < RELEASE_NOTES
    
    # Prompt user to edit Debian changelog
    $EDITOR_CHOICE "$DEBIAN_CHANGELOG"
    
    echo "Version updated successfully: $UPSTREAM_VERSION"
    
    

    为此,您需要通过调用以下命令来初始化版本:

    dch --newversion "$DEB_VERSION"
    

    然后对于文件中的每一行RELEASE_NOTES我们都需要调用:

        dch --newversion "$DEB_VERSION" -a "$line"
    

    这会在文件上附加一行debian/changelog,然后我们完成该行:

    dch --newversion "$DEB_VERSION" --distribution unstable ignored
    

    然后需要最终确定发布内容如下:

    dch --newversion "$DEB_VERSION" --distribution unstable ignored
    

    在您的示例中,这将导致以下变更日志条目:

    mkdotenv (0.2.0-0debian1-unstable1) unstable; urgency=medium
    
      [ John Doe ]
      * 1. Split codebase into multiple files.   
      * 2. Use a seperate version file and define built version upon compile.   
      * 4. [BUGFIX] If input file is same as output file copy input file into a temporary one.  
      * 5. Improved Documentation
    
     -- username <username@hostname>  Mon, 10 Mar 2025 22:01:07 +0200
    

    2025/3/25 更新

    如果没有导出环境变量,则会省略一些行DEBEMAIL,因此我为用户提供了一个小提示,让用户输入他/她的电子邮件并将其存储在 DEBEMAIL 文件中。

    • 4

相关问题

  • 在awk中的两行之间减去相同的列

  • 打印文件行及其长度的脚本[关闭]

  • 通过命令的标准输出以编程方式导出环境变量[重复]

  • 按分隔符拆分并连接字符串问题

  • MySQL Select with function IN () with bash array

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve