winlin
Goto Top

Ubuntu bash proxy script for apt-get

Hallo Zusammen,

ich habe ubuntu vms die apt-get nutzen um updates durczuführen. Ich möchte ein start script haben welches den proxy setzt für apt-get. Habe das hier gefunden: https://help.ubuntu.com/community/AptGet/Howto/#Setting_up_apt-get_to_us ...

Könnt ihr mir sagen wie das nun im skript aussehen muss für APT configuration file Methode, sodass nur apt-get den proxy nutzt?

#!/bin/bash
Acquire::http::Proxy "http://yourproxyaddress:proxyport";  
Acquire::https::Proxy "http://yourproxyaddress:proxyport";  

Content-Key: 3540454365

Url: https://administrator.de/contentid/3540454365

Ausgedruckt am: 29.03.2024 um 13:03 Uhr

Mitglied: SlainteMhath
SlainteMhath 04.08.2022 um 09:22:09 Uhr
Goto Top
Moin,

du benötigst kein Script. Du trägst einfach die beiden Zeilen in die /etc/apt/apt.conf ein.

lg,
Slainte
Mitglied: winlin
winlin 04.08.2022 um 09:35:56 Uhr
Goto Top
mein system sieht da so aus:
96dd-a9800aa5deb1:/etc/apt$ ls -la
total 36
drwxr-xr-x  7 root root 4096 Aug  3 16:23 .
drwxr-xr-x 88 root root 4096 Aug  4 07:34 ..
drwxr-xr-x  2 root root 4096 Jun 21 07:55 apt.conf.d
drwxr-xr-x  2 root root 4096 Jun 15  2021 auth.conf.d
drwxr-xr-x  2 root root 4096 Apr 20  2018 preferences.d
-rw-r--r--  1 root root  225 Jun 21 07:51 sources.list
drwxr-xr-x  2 root root 4096 Jun 21 07:51 sources.list.d
-rw-r--r--  1 root root  225 Jun 21 07:51 sources.list.save
drwxr-xr-x  2 root root 4096 Jun 21 07:51 trusted.gpg.d
a9800aa5deb1:/etc/apt$ cd apt.conf.d
a9800aa5deb1:/etc/apt/apt.conf.d$ ls -la
total 32
drwxr-xr-x 2 root root 4096 Jun 21 07:55 .
drwxr-xr-x 7 root root 4096 Aug  3 16:23 ..
-rw-r--r-- 1 root root 1018 Jun 15  2021 01autoremove
-r--r--r-- 1 root root 2267 Jun 21 07:54 01autoremove-kernels
-rw-r--r-- 1 root root   42 Apr 20  2018 01-vendor-ubuntu
-rw-r--r-- 1 root root   32 Jun 21 07:55 02periodic
-rw-r--r-- 1 root root  604 Apr 14 18:32 20apt-esm-hook.conf
-rw-r--r-- 1 root root  182 Feb 28  2018 70debconf
Mitglied: colinardo
Lösung colinardo 04.08.2022 aktualisiert um 11:17:42 Uhr
Goto Top
Servus.
Erstelle eine neue Datei in /etc/apt/apt.conf.d/, z.B. 80_proxy.conf und schreibe die Proxy-Konfigurationszeilen dort rein. Das Verzeichnis kommuliert alle *.conf Dateien und verwendet das dann als finale Gesamtkonfiguration für apt.
Wie immer steht das auch alles im Manual und ein man apt hätte es ebenfalls verraten.
Die Systematik das man Konfigurationsfragmente in ein Verzeichnis auslagert die wie die Hauptkonfigurations-Datei mit angehangenem ".d" benannt sind hat sich bei vielen Linux-Services etabliert. Das System dahinter: Man ändert an der Haupt-Konfigurationsdatei in der Regel nichts mehr sondern nur in dem Konfigurationsverzeichnis. So lässt sich bei einem Update von der APT-Komponente die Hauptkonfigurationsdatei durch die Standard-Version ersetzen und eigene Abweichungen bleiben damit trotzdem erhalten.

Grüße Uwe
Mitglied: winlin
winlin 04.08.2022 um 12:59:34 Uhr
Goto Top
danke colinardo, das hat geklapptface-smile
Mitglied: winlin
winlin 04.08.2022 um 13:32:06 Uhr
Goto Top
noch eine frage sorryface-smile

wenn ich ein setup script habe und darin eben diese apt.conf anlegen möchte mit den Proxy settings wie mache ich das???

habe ein Beispiel für das entfernen des Proxys:
 #!/bin/bash
        set -o errexit
        sed -i '/proxy/d' /directory/test/jobs/config.yml  
Mitglied: colinardo
colinardo 04.08.2022 aktualisiert um 13:41:13 Uhr
Goto Top
Du kannst jegliche Config-Direktiven auch dem apt command direkt mitgeben ohne irgendwelche Configs anpassen zu müssen:
apt update --option Acquire::HTTP::Proxy=http://localhost:3142
Ansonsten einfach weitere Config-Datei im Config-Verzeichnis ablegen, und wenn man es nicht mehr braucht die Datei wieder entfernen.
Mitglied: winlin
winlin 04.08.2022 um 13:53:24 Uhr
Goto Top
Das Problem ist das ich das leider ueber sed -i machen muss. Ich benötige ein start skript wo eben diese apt.conf angelegt wird.
Mitglied: SlainteMhath
SlainteMhath 04.08.2022 um 13:58:18 Uhr
Goto Top
Das Problem ist das ich das leider ueber sed -i machen muss.
Warum? Evtl. erzählst du uns mal die komplette Story...

Ich benötige ein start skript wo eben diese apt.conf angelegt wird.

uff... da könnte man schon "basics" nennen....
echo "was immer du willst zeile 1" > /etc/apt/apt.conf.d/99_proxy  
echo "was immer du willst zeile 2" >> /etc/apt/apt.conf.d/99_proxy  
Mitglied: winlin
winlin 04.08.2022 um 14:14:39 Uhr
Goto Top
wie mache ich das mit sed -i ????

 #!/bin/bash
        set -o errexit
        sed -i  ......
Mitglied: colinardo
colinardo 04.08.2022 aktualisiert um 14:43:03 Uhr
Goto Top
Zitat von @winlin:
wie mache ich das mit sed -i ????
Warum man das unbedingt nur mit sed machen sollte weiß wohl nur der Geier, aber bitte
sed -ie '$aAcquire::HTTP::Proxy=http://localhost:3142' datei.xyz