如何在没有用户输入的情况下在外壳脚本中添加PPA?


57

基本上,我想在add-apt-repository ppa:(whatever)没有“按Enter继续”提示的情况下运行。我该怎么做?

本质上,我想部署在没有用户输入的情况下在Shell脚本中添加存储库。


12
只需-y在命令末尾添加即可add-apt-repository -y ...
Uri Herrera

1
man add-apt-repository然后您将看到-y@UriHerrera所说的开关。
NickTux

Answers:


79

脚本是这样的

#! /bin/sh
sudo add-apt-repository ppa:(Your ppa here) -y

顺便说一句,您仍然需要输入密码


你遇到了什么错误?
注册用户

1
aditya,您好,它的工作人员:D,刚刚检查过……
Babin

-2

当然,如果您真的想打动R2D2,也可以避免输入密码提示。准备您的用户帐户,使其看起来像这样:

you@yourhost:~$
you@yourhost:~$ cat /home/you/.bash_login;
# ASK_PASS service for you «begins»
export SUDO_ASKPASS="/home/you/.ssh/.supwd.sh";
# ASK_PASS service for you «ends»
you@yourhost:~$
you@yourhost:~$
you@yourhost:~$ cat /home/you/.ssh/.supwd.sh;
#!/bin/sh
echo '(Your sudoer password here)';
you@yourhost:~$
you@yourhost:~$
you@yourhost:~$ ls -l .ssh/.supwd.sh 
-rwx------ 1 you you 35 Mar 31 10:28 .ssh/.supwd.sh
you@yourhost:~$ 
you@yourhost:~$
you@yourhost:~$ cat ./tmp.sh 
#!/bin/sh
. /home/you/.bash_login;  # 'source' bash_login to declare the ask_pass script
sudo -A add-apt-repository ppa:(Your ppa here) -y;
# The flag '-A' lets you add the repo without sudo demanding your password.
#
you@yourhost:~$
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.