From b796931d4f9ad51ae606b58d67988218be3f04dc Mon Sep 17 00:00:00 2001 From: ml Date: Thu, 13 Feb 2020 21:12:20 +0100 Subject: [PATCH] Rewrite script for OEM installation. Closes #23 (#25) Do everything as root. For OEM installation Inform user about cleanup Co-authored-by: ml Reviewed-by: stefan230 Reviewed-by: York-Simon Johannsen --- mint/linux_mint.sh | 130 +++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 69 deletions(-) diff --git a/mint/linux_mint.sh b/mint/linux_mint.sh index c647a49..4ebbecc 100755 --- a/mint/linux_mint.sh +++ b/mint/linux_mint.sh @@ -1,14 +1,14 @@ #!/usr/bin/env bash +# execute self with sudo if user is not root +[[ $UID -ne 0 ]] && exec sudo ./"$0" + ### # Set variables ### export DEBIAN_FRONTEND=noninteractive DPKG_CFG_FRAGMENT=/etc/dpkg/dpkg.cfg.d/non-interactive -# Color of prefix (>>>) to distinguish user and root echos -color_prefix=32 # green - # Linux distro script_distro='Linux Mint 19.x' @@ -88,13 +88,10 @@ packages=( ### # Functions ### -is_root() { - [[ $UID -eq 0 ]] -} # $*: message to echo e() { - printf "\e[%sm>>>\e[0m %s\n" "$color_prefix" "$*" + printf "\e[31m>>>\e[0m %s\n" "$*" } # It's a pain to stop (ctrl+c, kill) execution with all the Python applications @@ -106,8 +103,8 @@ handle_signal() { # always executed on shell exit regardless of reason. for cleanup tasks handle_exit() { - # Remove temporary dpkg cfg if root - is_root && rm -f "$DPKG_CFG_FRAGMENT" + e "Finales Cleanup wird durchgeführt..." + rm -f "$DPKG_CFG_FRAGMENT" } trap handle_signal SIGINT SIGTERM @@ -117,58 +114,6 @@ pkg() { apt install "$@" --yes --quiet } -### -# Root setup -### -if is_root; then - color_prefix=31 # red - if [[ $1 != "root-setup" ]]; then - e "Dieses Script sollte nicht direkt als Root ausgeführt werden!" >&2 - e "Privilegien werden automatisch eskaliert sobald es notwendig ist." >&2 - exit 1 - fi - - # place temporary dpkg configurations to ensure non-interactive upgrade - cat <<'DPKG' >"$DPKG_CFG_FRAGMENT" -force-confold -force-confdef -DPKG - - e "Automatische Installation empfohlener Pakete aktivieren ..." - sed -i 's/false/true/g' /etc/apt/apt.conf.d/00recommends - - e "Besten Spiegelserver für '${script_distro}' auswählen ..." - mint-switch-to-local-mirror - - e "Paketquellen aktualisieren ..." - apt update --yes --quiet - - e "System aktualisieren (apt) ..." - apt full-upgrade --yes --quiet - - e "System aktualisieren (mintupdate-cli) ..." - mintupdate-cli --yes upgrade - - e "Proprietäre Treiber installieren (sofern verfügbar) ..." - ubuntu-drivers autoinstall - - e "Zusätzliche Software installieren ..." - pkg "${packages[@]}" - - e "Sprachunterstützung vervollständigen ..." - pkg "$(check-language-support)" - # these packages have to be installed after "$(check-language-support)" - pkg hunspell-de-at hunspell-de-ch hunspell-de-de - - e "Unnötige Pakete entfernen und Cache bereinigen ..." - apt clean --yes --quiet - apt autoremove --yes --quiet - - e "Root Setup abgeschlossen." - # It's very important to exit here. We don't want root past this point! - exit -fi - ### # Greeting ### @@ -190,16 +135,63 @@ e "Starte initiales Setup für Rechner mit frisch installiertem '${script_distro ### # Automatic installation ### -e "Script wird als Root ausgeführt für privilegierte Aufgaben" -sudo ./"$0" root-setup +# place temporary dpkg configurations to ensure non-interactive upgrade +cat <<'DPKG' >"$DPKG_CFG_FRAGMENT" +force-confold +force-confdef +DPKG -e "Richte arabisches und persisches Tastatur-Layout ein..." -gsettings set org.gnome.libgnomekbd.keyboard layouts "['de', 'ara', 'ir']" +e "Automatische Installation empfohlener Pakete aktivieren ..." +sed -i 's/false/true/g' /etc/apt/apt.conf.d/00recommends -e "Ändere Anzeigeoptionen für die Tastatur auf die richtigen Werte..." -gsettings set org.cinnamon.desktop.interface keyboard-layout-show-flags false -gsettings set org.cinnamon.desktop.interface keyboard-layout-use-upper true -gsettings set org.cinnamon.desktop.interface keyboard-layout-prefer-variant-names true +e "Besten Spiegelserver für '${script_distro}' auswählen ..." +mint-switch-to-local-mirror + +e "Paketquellen aktualisieren ..." +apt update --yes --quiet + +e "System aktualisieren (apt) ..." +apt full-upgrade --yes --quiet + +e "System aktualisieren (mintupdate-cli) ..." +mintupdate-cli --yes upgrade + +e "Proprietäre Treiber installieren (sofern verfügbar) ..." +ubuntu-drivers autoinstall + +e "Zusätzliche Software installieren ..." +pkg "${packages[@]}" + +e "Sprachunterstützung vervollständigen ..." +pkg "$(check-language-support)" +# these packages have to be installed after "$(check-language-support)" +pkg hunspell-de-at hunspell-de-ch hunspell-de-de + +e "Unnötige Pakete entfernen und Cache bereinigen ..." +apt clean --yes --quiet +apt autoremove --yes --quiet + +# https://askubuntu.com/questions/1037553/how-to-configure-a-dconf-key-globally-across-all-user-accounts#1037557 +# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/desktop_migration_and_administration_guide/custom-default-values-system-settings +e "Tastatur- und Desktopoptionen werden angepasst" +mkdir -vp /etc/dconf/{profile,db/local.d} + +cat <<'EOF' > /etc/dconf/profile/user +user-db:user +system-db:local +EOF + +cat <<'EOF' > /etc/dconf/db/local.d/00-keyboard-layout +[org/gnome/libgnomekbd/keyboard] +layouts=['de', 'ara', 'ir'] + +[org/cinnamon/desktop/interface] +keyboard-layout-show-flags=false +keyboard-layout-use-upper=true +keyboard-layout-prefer-variant-names=true +EOF + +dconf update ### # Finalisation