Skip to content

Instantly share code, notes, and snippets.

@matkoniecz
Last active December 17, 2019 14:49
Show Gist options
  • Save matkoniecz/4aeaeea001c154792e2ec3706ff9f8df to your computer and use it in GitHub Desktop.
Save matkoniecz/4aeaeea001c154792e2ec3706ff9f8df to your computer and use it in GitHub Desktop.
require "open3"
require 'logger'
# https://ruby-doc.org/stdlib-2.6.5/libdoc/logger/rdoc/Logger.html
# how should I use it, without recreating and without passsing around?
$logger = nil
$error_logger = nil
$fatal_logger = nil
def initilize_loggers
$logger = Logger.new('logfile_all.log')
$logger.sev_threshold = Logger::DEBUG
$error_logger = Logger.new('logfile_error.log')
$error_logger.sev_threshold = Logger::ERROR
$fatal_logger = Logger.new('logfile_fault.log')
$fatal_logger.sev_threshold = Logger::FATAL
end
def close_loggers
$logger.close
$error_logger.close
$fatal_logger.close
end
def main
# from https://stackoverflow.com/q/52747306/4130619
if Process.uid == 0
# We're root!
else
puts("You must run this with root privileges via sudo")
exit 1
end
initilize_loggers()
update_package_data()
install_packages()
standard_package_upgrade()
execute_command("sudo apt-get -qq autoremove -y")
close_loggers()
end
def log(severity, logged)
$logger.log(severity, logged)
$error_logger.log(severity, logged)
$fatal_logger.log(severity, logged)
end
def log_command_result(command, stdout, stderr, status)
if status.success?
log(Logger::INFO, "command <#{command}> succeded with status <#{status}>, stderr <#{stderr}> stdout <#{stdout}>")
else
log(Logger::ERROR, "command <#{command}> failed with status <#{status}>, stderr <#{stderr}> stdout <#{stdout}>")
end
end
def execute_external_command(command)
log(Logger::DEBUG, "will be executing <#{command}>")
stdout, stderr, status = Open3.capture3(command)
log(Logger::DEBUG, "executed <#{command}>")
log_command_result(command, stdout, stderr, status)
return status.success?
end
def execute_command(command, retry_planned: false)
puts command
if execute_external_command(command) == false
if retry_planned
puts " retry needed"
else
puts " this command failed"
end
end
end
def add_apt_repository(name)
if execute_command("sudo add-apt-repository #{name} -y") == false
log(Logger::FATAL, "adding ppa <#{name}> failed")
end
update_package_data()
end
def reboot_wifi
# https://askubuntu.com/questions/597116/how-to-disable-wireless-from-command-line
execute_command("nmcli radio wifi off")
sleep 10
execute_command("nmcli radio wifi on")
end
def install_package(package)
command = "sudo apt-get -qq install #{package} -y"
if execute_command(command, retry_planned: true)
return true
end
log(Logger::WARN, "rebooting wifi and retrying, at least one of my computers has wifi problems solved by rebooting it")
reboot_wifi()
if execute_command(command)
return true
end
log(Logger::FATAL, "after rebooting wifi <#{command}> still failed")
return false
end
def uninstall_package(package)
command = "sudo apt-get -qq remove #{package} -y"
if execute_command(command)
return true
end
log(Logger::FATAL, "uninstalling package <#{package}> failed")
return false
end
def update_package_data
if execute_command("sudo apt-get -qq update")
return true
end
log(Logger::FATAL, "updating package database failed")
return false
end
def standard_package_upgrade
if execute_command("sudo apt-get -qq dist-upgrade -y")
return true
end
log(Logger::FATAL, "upgrading packages failed")
return false
end
def install_packages
# install sending mail on cron error
# originally was using <<< bashism
# https://stackoverflow.com/questions/29166876/sh-1-syntax-error-redirection-unexpected-when-using-backticks-perl
execute_command('echo "postfix postfix/mailname string grisznak" | sudo debconf-set-selections')
execute_command('echo "postfix postfix/main_mailer_type string \'Internet Site\'" | sudo debconf-set-selections')
install_package("postfix")
# cd ripping
install_package("k3b")
# world is not perfect and ideal
# early as keeps changing package name with a good reason (was named libk3b6-extracodecs)
install_package("libk3b7-extracodecs")
# VM
install_package("virtualbox")
# for android studio https://developer.android.com/studio/install.html
install_package("libc6:i386")
install_package("libncurses5:i386")
install_package("libstdc++6:i386")
install_package("lib32z1")
install_package("libbz2-1.0:i386")
# launched by gs (conflicts with mispelled alias for git status)
uninstall_package("ghostscript")
# remove ones that got defaulted for text files
uninstall_package("leafpad")
uninstall_package("gedit")
execute_command("sudo apt-get purge zeitgeist* -y") # <prywatność, fałszywe alarmy w porównywaniu backupów
# minesweeper bait in the main menu
uninstall_package("aptitude")
# disable screen locking
uninstall_package("light-locker")
# remove useless (from 14.04)
# removals of default program may be undone by sudo apt-get -qq install lubuntu-desktop
uninstall_package("xpad")
uninstall_package("gnome-mplayer") # though for me it seems that just ratings are missing - and maybe playlist persistence
uninstall_package("abiword")
uninstall_package("gnumeric")
uninstall_package("audacious")
uninstall_package("leafpad")
# remove useless (from 16.04)
uninstall_package("pidgin")
uninstall_package("pidgin-data")
uninstall_package("sylpheed")
# remove useless (from 18.04)
uninstall_package("kdeconnect")
# useless bit-torrent client
uninstall_package("transmission")
uninstall_package("transmission-gtk")
uninstall_package("transmission-cli")
uninstall_package("transmission-common")
# required for hacking with diffutils GNU project
install_package("help2man")
install_package("autopoint")
install_package("gperf")
install_package("keepass2")
# image viewer able to use trash
uninstall_package("gpicview") # deletes without using trash
# sudo apt-get -qq install gthumb -y
install_package("eog")
# install_package("geeqie") # animated gif support is missing, dead project
# mail client
install_package("claws-mail")
# wanted by Android Studio on 64 bit systems
install_package("lib32stdc++6")
# dictionaries
install_package("aspell-pl")
install_package("aspell-en")
# paint replacement
# sudo apt-get -qq install kolourpaint4 #crashes on save as of autumn 2017
install_package("pinta")
# audio +100%, also, for individual applications
install_package("pavucontrol")
# necessary for scipy python package
install_package("gfortran")
install_package("libopenblas-dev")
install_package("liblapack-dev")
install_package("sqlitebrowser")
# java
# echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
# echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
# add_apt_repository("ppa:webupd8team/java")
# sudo apt-get -qq install oracle-java8-installer
# sudo apt-get -qq install oracle-java8-set-default
install_package("openjdk-11-jdk")
install_package("python")
install_package("python-pip")
install_package("python-dev")
install_package("python3")
install_package("python3-pip")
install_package("python3-dev")
# wanted by rmagick
install_package("imagemagick")
install_package("libmagickcore-dev")
install_package("libmagickwand-dev")
# encoding tool
install_package("enca")
# pdf reader
install_package("okular")
# prtscrn
install_package("shutter")
# multiple monitors
install_package("arandr")
install_package("mnemosyne")
# start menu editor (seriously? Default start menu worse than windows? Why?)
install_package("menulibre")
# commander
# krusader + dependencies
install_package("kompare")
install_package("krename")
install_package("krusader")
# unpackers dependencies for krusader
install_package("arj")
install_package("bzip2")
install_package("cpio")
install_package("dpkg")
install_package("gzip")
install_package("lzma")
install_package("rar")
install_package("tar")
install_package("unrar")
install_package("unzip")
install_package("zip")
install_package("rpm")
install_package("unace")
install_package("lhasa")
install_package("p7zip-full")
# libre office with latest stable
# early access, versions with minor testing but still more usable than fossilized release in the main repo
# http://askubuntu.com/questions/16695/is-there-a-ppa-with-the-latest-version-of-libreoffice/19794#19794
add_apt_repository("ppa:libreoffice/ppa")
# accept ms installer question for one of fonts
# used in at least one of following: vlc libreoffice wine clementine puddletag
execute_command("echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true")
# replaced by official PPA (https://www.clementine-player.org/downloads)
# Clementine is dying - see
# https://github.com/clementine-player/Clementine/graphs/contributors
# ppa has no release for Ubuntu 18, EOL OS are listed
# reported as https://github.com/clementine-player/Website/issues/9
# find mp3 player with automatic scoring of songs based on what is played/skipped
# see https://softwarerecs.stackexchange.com/q/70950/12551
# The repository 'http://ppa.launchpad.net/me-davidsansome/clementine/ubuntu bionic Release' does not have a Release file.
# issue: https://github.com/clementine-player/Clementine/issues/6051
# add_apt_repository("ppa:me-davidsansome/clementine")
install_package("clementine")
# other accesories
install_package("vlc")
install_package("libreoffice")
# sudo apt-get -qq install wine
install_package("puddletag")
install_package("graphviz")
# checker of disk health
install_package("gsmartcontrol")
# cd burning, without kde issues (my 16.04 install was unable to run kde programs without fiddling)
install_package("brasero")
add_apt_repository("ppa:maarten-baert/simplescreenrecorder")
install_package("simplescreenrecorder")
# it enables notify-send: $ notify-send 'Everything computed!'
install_package("libnotify-bin")
# support for video processing
install_package("ffmpeg")
# disk usage display
install_package("baobab")
# epuap reader
install_package("fbreader")
# mono (for maperitive)
install_package("mono-complete")
# S.M.A.R.T. monitoring tool
# install_package("gsmartcontrol -y") #buggy
# change partitions etc
install_package("gparted")
# flash
install_package("flashplugin-installer")
# editor for Markdown and reStructuredText
# includes preview
install_package("retext")
# traceroute command
install_package("traceroute")
# backup
execute_command("sudo gem install --no-user-install backup -v5.0.0.beta.1") # to make possible using it with sudo, see also https://github.com/backup/backup/issues/944
# TODO: replace it with a maintained software
# latex
install_package("texlive-full")
# R language
install_package("r-base")
install_package("r-cran-ggplot2")
install_package("r-cran-gplots")
# http://askubuntu.com/questions/644667/gradle-executing-tasks-runs-forever
install_package("lib32z1")
# user account adding/creation that works
install_package("gnome-control-center")
# play midi files - https://sfxpt.wordpress.com/2015/02/02/how-to-play-midi-files-under-ubuntu-linux/
install_package("freepats")
install_package("timidity")
install_package("timidity-interfaces-extra")
# at the end as it likes to fail
# package ttf-mscorefonts-installer included in lubuntu-restricted-extras has
# "Configuring ttf-mscorefonts-installer" what requires agreement to some stupid microsoft EULA
execute_command("echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections")
execute_command("echo ttf-mscorefonts-installer msttcorefonts/present-mscorefonts-eula note | sudo debconf-set-selections")
install_package("lubuntu-restricted-extras -y")
install_package("lubuntu-restricted-addons -y")
# install todos fromdos commands http://superuser.com/questions/52044/convert-crlfs-to-line-feeds-on-linux/52140#52140
install_package("tofrodos")
# used in crontab
execute_command("sudo gem install --no-user-install rawler")
execute_command("sudo gem install --no-user-install html-proofer")
# for hp printers https://askubuntu.com/questions/575547/how-can-i-install-hp-laserjet-p1102w-on-ubuntu
install_package("hplip")
# selfupgrade pip
execute_command("pip install --upgrade pip")
# genealogy software and its recommended support software
# see https://github.com/gramps-project/gramps#the-following-packages-are-strongly-recommended-to-be-installed
# see https://gramps-project.org/bugs/view_all_bug_page.php
install_package("gramps")
install_package("rcs")
execute_command("pip install --user pillow")
# show tree structure
# https://stackoverflow.com/questions/3455625/linux-command-to-print-directory-structure-in-the-form-of-a-tree
install_package("tree")
# youtube downloader (documented in mnemo)
# sudo apt-get -qq install youtube-dl
execute_command("pip install --user --upgrade youtube_dl")
# SVG editing
install_package("inkscape")
# Vcard file handling
install_package("kontact") # (not a critical package)
# temperature graph - https://askubuntu.com/a/628124/349903
install_package("psensor")
# general programming tools
execute_command("sudo gem install --no-user-install bundler")
install_package("python3-pyqt4") # pyqt4 support for python3 (not a critical package)
# for checking .sh file syntax - shellcheck
# https://github.com/koalaman/shellcheck
# may require also https://github.com/koalaman/shellcheck#in-your-editor
install_package("shellcheck")
execute_command("sudo Rscript helpers/subscripts/install_r_packages.R")
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment