#!/bin/bash ############## # Author: Mirko Matošin # # Date: 2022-06-06 # Last Edit: 2022-06-09 # Hosted as gists in Github # Mit diesem Skript werden die Proxy-Parameter für den notwendigen Internetzugang # an mehreren Stellen geschrieben. Das Passwort wird im Klartext innerhalb der VM gespeichert ############## # Beispiel-Ausführung # Die Datei muss in die VM kommen. Mit Mobaxterm ist dies ganz einfach. Per Upload in den sftp browser auf # linken seite oder senden per scp (secure shell copy). # Zum Dateipfad wechseln und die Datei ausführbar machen. Anschließend ausführen mit bash # cd ~/proxypass # chmod u+x proxypass # bash proxypass.sh # Eingabe der Loginnamen und Passwörter, jedes mal mit enter bestätigen # OK...OK...OK...OK...OK... # Fail sollte nicht kommen - bitte die Ausgabe untersuchen. # TODO: Musterausgabe an Skript hängen (ohne PW) ############## if [ "$1" ] then testpart=$1 else testpart=99 fi echo $testpart pvdir=$(pwd) printf "Hallo Liebe Tutorial-Teilnehmer, wir vom iRAS heißen euch herzlich willkommen. Mit diesem Skript werden die Proxy-Parameter für den notwendigen Internetzugang an mehreren Stellen geschrieben. Das Passwort wird im Klartext innerhalb der VM gespeichert\n" ################# # Abfrage der Daten ################# read -p "Geben sie ihren Loginnamen ein:" user printf 'Hallo:\t%s\n' "$user" read -p "Geben sie ihr IZ-Kürzel ein:" iz read -p "Geben sie ihr Passwort ein:" pass ################# #Anlegen für Zugriff im Terminal ################# if [ $testpart -eq 0 ] || [ $testpart -eq 99 ]; then http_proxy=http://${iz}:${pass}@proxy.hs-karlsruhe.de:8888 https_proxy=http://${iz}:${pass}@proxy.hs-karlsruhe.de:8888 no_proxy="*.hs-karlsruhe.de, 193.196.64.0/18, localhost, 127.0.0.1, 10.0.0.0/8, 172.0.0.0/8" echo "$http_proxy" export http_proxy=\"$http_proxy\" export https_proxy=\"$https_proxy\" echo "export http_proxy=\"$http_proxy\"" | tee -a /home/"$USER"/.bashrc echo "export https_proxy=\"$https_proxy\"" | tee -a /home/"$USER"/.bashrc echo "export no_proxy=\"$no_proxy\"" | tee -a /home/"$USER"/.bashrc source /home/"$USER"/.bashrc ################# # Test ################# echo "Aktuelle IP: " curl -k https://ifconfig.me echo "" fi if sudo hwclock --hctosys;then echo OK else echo FAIL printf "Uhrzeit passt nicht" exit 1 fi ################# # Apt ################# if [ $testpart -eq 1 ] || [ $testpart -eq 99 ];then apthttp="Acquire::http::Proxy ${http_proxy}; " apthttps="Acquire::https::Proxy ${http_proxy}; " if sudo test -w "/etc/apt/apt.conf";then echo "$apthttp" | sudo tee -a /etc/apt/apt.conf echo "$apthttps" | sudo tee -a /etc/apt/apt.conf else sudo touch /etc/apt/apt.conf echo "$apthttp" | sudo tee -a /etc/apt/apt.conf echo "$apthttps" | sudo tee -a /etc/apt/apt.conf fi ################# # Test ################# cat /etc/apt/apt.conf if sudo apt update; then echo OK else echo FAIL exit 1 fi fi printf "\n\n######################################\n\n" echo ok ################# # Container runtime ################# if [ $testpart -eq 2 ] || [ $testpart -eq 99 ] then if sudo apt install jq -y; then echo OK key1=default subkey1=httpProxy subkey2=httpsProxy subkey3=noProxy dockprox=$(jq -n --arg key1 "$key1" --arg subkey1 "$subkey1" --arg subkey2 "$subkey2" --arg subkey3 "$subkey3" \ --arg value1 "$http_proxy" --arg value2 "$https_proxy" --arg value3 "$no_proxy" ' { proxies:{ ($key1): { ($subkey1): $value1, ($subkey2): $value2, ($subkey3): $value3 } } } ') echo $dockprox # Ist die config.json beschreibbar if [ -w ~/.docker/config.json ] then echo $dockprox | tee -a ~/.docker/config.json elif [ ! -d ~/.docker/ ] then mkdir -p ~/.docker/ touch ~/.docker/config.json echo $dockprox | tee -a ~/.docker/config.json else touch ~/.docker/config.json echo $dockprox | tee -a ~/.docker/config.json fi fi fi ################# # Docker daemon ################# if [ $testpart -eq 3 ] || [ $testpart -eq 99 ];then if [ $? -eq 0 ]; then echo OK dir1="/etc/systemd/system/docker.service.d" yaml="[Service]\nEnvironment="HTTP_PROXY=$http_proxy"\nEnvironment="HTTPS_PROXY=$https_proxy"\nEnvironment="NO_PROXY=$no_proxy"" # Ist der Ordner da? if [ -d $dir1 ];then pvdir=$(pwd) cd $dir1 || exit sudo touch http-proxy.conf echo -e $yaml | sudo tee -a http-proxy.conf else if sudo mkdir -p $dir1; then pvdir=$(pwd) cd $dir1 || exit else echo FAIL fi if sudo touch http-proxy.conf; then echo OK echo -e $yaml | sudo tee -a http-proxy.conf else echo FAIL fi cd $pvdir || exit fi else echo FAIL fi fi sudo apt install git -y if [ $? -eq 0 ]; then echo "alles ist gut durchgelaufen" git config --global http.proxy $http_proxy git config --global https.proxy $https_proxy git config --global http.https://www.w.hs-karlsruhe.de.proxy "" if [ $? -eq 0 ]; then echo OK exit 0 else echo FAIL exit 1 fi else echo "FAIL git install.. no git config" exit 1 fi exit 0