Pimp my Elementary OS 5.0 (Juno)

Bash, ElementaryOS, Fun

Wie man das „alte“ elementary OS 0.4 (Loki) optimal anpasst hatte ich ja bereits hier und hier beschrieben. Seit dem 16.10.2018 ist nun die neue Version von elementary OS für alle verfügbar und damit auch Zeit für mich mein Skript zu aktualisieren…

Eine hervorragende Vorlage für kurze Bash-Skripte habe ich bei github gefunden. Mit „Yet another Bash script template“ (YABST) ging es super einfach.

Genug der langen Vorrede, hier der Code:

#!/bin/bash
##
## Usage: juno_post_install [options]
##
## Improve fresh elementary OS (juno) installation.
## Must be run as root.
##
## Options:
##  -h, --help      Display this message.
##  -v, --version   Display version number.
##
## Example:
## juno_post_install --help
##

#-------------------#
# GLOBAL VARIABLES  #
#-------------------#
VMAJ=1  # major version
VMIN=0  # minor version
VREV=0  # patch version

QTM=0   # quiet mode flag (always off)
#------------------#
# GLOBAL FUNCTIONS #
#------------------#
_config(){
  source "$1"
}
_echo(){
  if [ $QTM -eq 0 ]; then
    echo "$1"
  fi
}
_error(){
  echo "$1"
  exit 1
}
_replace(){
  if [ "$#" -eq 3 ]; then
    if [ -f "$1" ]; then
      sed -i 's/'"${2////\\/}"'/'"${3////\\/}"'/g' "$1"
    else
      _error "'$1' is not a valid file."
    fi
  else
    _error "Function needs 3 parameter (file, search, replace)."
  fi
}
_require(){
  if ! [ -n "$(command -v $1)" ]; then
    _error "The program $1 is required. Please install it first."
  fi
}
_root(){
  if [[ $(whoami) != "root" ]]; then
    _error "This program must be run as root."
  fi
}
_title(){
  if [ $QTM -eq 0 ]; then
    (echo; echo \*\*\* $1 \*\*\*; echo)
  fi
}
_usage(){
  [ "$*" ] && echo "$0: $*"
  sed -n '/^##/,/^$/s/^## \{0,1\}//p' "$0"
  exit 2
}
_version(){
  echo "" && echo "$0 version $VMAJ.$VMIN.$VREV"
  exit 2
}
_write(){
  fname="out.txt"
  if [ ! -z "$2" ]; then
    fname="$2"
  fi

  cat  http://appcenter.elementary.io/
}
configure_vm(){
  _title "Configure virtual machine (if any)"

  vbox=`dmidecode -t system | grep -i 'virtualbox' | wc -l`
  if [ $vbox -gt 0 ]; then
    _echo "Install software and..."
    apt install virtualbox-guest-additions-iso virtualbox-guest-utils
    _echo "...add user to group"
    if [ $SUDO_USER == "" ]; then
      adduser $USER vboxsf
    else
      adduser $SUDO_USER vboxsf
    fi
  fi
}
create_aliases(){
  _title "Create command aliases"

  txt="
alias clear-history='cat /dev/null > ~/.bash_history && history -c'
alias apt-opt='sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y'"

  echo "$txt" >> "/home/$SUDO_USER/.bashrc"
  _echo "2 aliases added."
}
clean_up(){
  _title "Clean up"
  apt update && apt upgrade -y && apt autoremove -y && apt autoclean -y
}
#-----------------------#
# MAIN FUNCTION / START #
#-----------------------#
main() {
  while [ $# -gt 0 ]; do
    case $1 in
    (-h|--help) _usage;;
    (-v|--version) _version;;
    (-q) QTM=1;shift;;
    (--) shift; break;;
    (-*) _usage "$1: unknown option";;
    (*) break;;
    esac
  done
  _root
  # start steps
  full_update
  remove_software
  add_software1
  add_software2
  configure_vm
  create_aliases
  clean_up
}
main "$@"

Viel Spass!

Pimp my Elementary OS 0.4 (Loki) – Teil 2

Bash, ElementaryOS, Fun

Hier noch eine verbesserte Form des alten Skriptes:

#!/bin/bash
##
## Usage: loki_post_install [options]
##
## Removes unnecessary and add usefull software to a fresh installed Elementary OS 0.4 (Loki).
## Must be run as root.
##
## Options:
##  -h, --help      Display this message.
##

main() {
while [ $# -gt 0 ]; do
case $1 in
(-h|--help) usage;;
(--) shift; break;;
(*) break;;
esac
done
if [ $(whoami) != "root" ]; then
echo "This program must be run as root."
exit 1
fi
software
}
usage(){
[ "$*" ] && echo "$0: $*"
sed -n '/^##/,/^$/s/^## \{0,1\}//p' "$0"
exit 2
}
msg() {
(echo; echo \*\*\* $1 \*\*\*; echo)
}
software() {
msg "Prepare system"
apt update && apt upgrade -y && apt autoremove -y && apt autoclean -y
msg "Remove software"
apt purge maya-calendar pantheon-mail appcenter simple-scan -y
msg "Install software"
apt install zip unzip rar unrar gnome-disk-utility firefox lilypond fluid-soundfont-gm timidity libav-tools openjdk-8-jdk-headless -y

vbox=`dmidecode -t system | grep -i 'virtualbox' | wc -l`
if [ $vbox -gt 0 ]; then
msg "Install & configure additional software for VirtualBox"
apt install virtualbox-guest-additions-iso virtualbox-guest-utils

if [ $SUDO_USER == "" ]; then
adduser $USER vboxsf
else
adduser $SUDO_USER vboxsf
fi
fi

msg "Clean up"
apt update && apt upgrade -y && apt autoremove -y && apt autoclean -y
}

main "$@"

Feedback welcome!

Pimp my Elementary OS 0.4 (Loki)

Bash, ElementaryOS, Fun

Also das neue schicke Elementary OS ist ja nun verfügbar, jedoch fehlt hier und da das ein oder andere wichtige Tool für mich. Und da ich den Laptop nur als Zweitrechner nutze brauche ich ja kein extra Mailprogramm geschweige denn ein Scanprogramm…

Lange Rede kurzer Sinn: Einiges musste  weg, einiges noch hinzu kommen damit ich mit dem Endergebnis so richtig zufrieden bin…

#!/bin/bash
##
## Usage: loki_post_install [options]
##
## Removes unnecessary and add usefull software to a fresh installed Elementary OS 0.4 (Loki).
## Must be run as root.
##
## Options:
##   -h, --help    Display this message.
##   -d            Display debug information.
##

DBG=0;

main() {
while [ $# -gt 0 ]; do
case $1 in
(-d) DBG=1;shift;;
(-h|--help) usage 2>&1;;
(--) shift; break;;
(-*) usage "$1: unknown option";;
(*) break;;
esac
done
if [[ $(whoami) != "root" ]]; then
echo "This program must be run as root." >&2
exit 1
fi
software
}

usage() {
[ "$*" ] && echo "$0: $*"
sed -n '/^##/,/^$/s/^## \{0,1\}//p' "$0"
exit 2
} 2>/dev/null

msg() {
if [ $DBG -eq 1 ]; then
(echo; echo \*\*\* $1 \*\*\*; echo)
fi
}

software() {
msg "Prepare system"
apt update -y && apt upgrade -y && apt autoremove -y
msg "Remove software"
apt purge maya-calendar pantheon-mail appcenter simple-scan -y
msg "Install software"
apt install zip unzip rar unrar gnome-disk-utility firefox lilypond frescobaldi fluid-soundfont-gm timidity -y
msg "Clean up"
apt update -y && apt upgrade -y && apt autoremove -y
}

main "$@"