reprepro - 有没有机会通过 bash 脚本输入密码?

P4t*_*4tR 3 bash cron prompt reprepro passphrase

我使用“reprepro”从我的本地存储库中获取最新的 Debian 软件包,手动工作正常。
现在我需要通过 cron 作业自动执行此过程,但 reprepro 密码是一个提示。

有没有可能通过bash脚本发送密码?在 reprepro 联机帮助页中找不到任何内容。

小智 6

我需要同样的东西并正在寻找解决方案。除了 run gpg-agent,它只会要求输入一次密码(例如在启动期间)并缓存它以备下次使用,我什么也没找到。

问题是如何与交互式脚本进行交互,这些脚本要求用户从 stdin 输入。Expect ( apt-get install expect) 正好解决了这个问题。

这是我编写并保存在 /usr/local/bin/reprepro_expect 中的脚本:

#!/usr/bin/expect -f
set timeout 2
set passphrase "mysupersecretpassword"

spawn reprepro -b [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3]
expect {
        "*passphrase:*" {
                send -- "$passphrase\r"
        }
}
expect {
        "*passphrase:*" {
                send -- "$passphrase\r"
        }
}
interact
Run Code Online (Sandbox Code Playgroud)

你可以像这样运行它:

reprepro_expect [path_to_repository] [command] [distribution] [package_name]

例如:

添加新包:

reprepro_expect /var/www/myrepo includedeb wheezy mypackage_0.1-1_all.deb

删除包

reprepro_expect /var/www/myrepo remove wheezy mypackage

安全性:由于您的私钥的密码存储在脚本中,我chown向用户推荐它,在此情况下将使用chmod它并将其设置为 500。为什么不将密码作为另一个参数传递?因为它将存储在 ~/.bash_history 中,并且会ps axu在运行时显示。