- name: t14
  hosts: t14.p.vstill.cz
  vars:
    postgres_server_root: /var/lib/postgres

  tasks:
    - fail:
        msg: possibly wrong server?
      when: ansible_distribution != 'Archlinux'

    - import_role:
        name: vstill_deb

    - name: Enable sudo for wheel
      lineinfile:
        regex: "#? %wheel ALL=\\(ALL\\) ALL"
        line: "%wheel ALL=(ALL) ALL"
        path: /etc/sudoers

    - name: Enable time sync
      systemd:
        service: systemd-timesyncd
        enabled: true
        state: started

    - name: Enable sysrq
      sysctl:
        name: 'kernel.sysrq'
        value: '1'
        sysctl_file: "/etc/sysctl.d/30-sysrq.conf"

    - name: install basic tools
      pacman:
        pkg:
          - vim
          - strace
          - grub
          - efibootmgr
          - dmidecode
          - linux
          - linux-headers
          - smartmontools
          - dhcpcd
          - wpa_supplicant
          - acpi
          - screen
          - base
          - base-devel
          - gdb
          - cgdb
          - valgrind
          - w3m
          - elinks
          - bind
          - moreutils
          - cmake
          - ninja
          - clang
          - wol
          - git
          - git-lfs
          - subversion
          - bash-completion
          - ansible
          - rsync
          - gnupg
          - pinentry
          - inotify-tools
          - zip
          - unzip
          - bmake
          - perl-libwww
          - elfutils
          - patch
          - patchelf
          - man
          - man-pages
          - tree
          - bat
          - grc
          - fd
          - pv
          - wget
          - curl
          - mtr
          - sshfs
          - time
          - graphviz
          - imagemagick
          - pacman-contrib
          - usbutils
          - ethtool
          - lshw
          - bwm-ng
          - llvm
          - parallel

    - name: install nftables
      pacman:
        pkg:
          - nftables
      notify:
        - restart nftables

    - template:
        src: roles/common_deb/templates/nftables.conf.j2
        dest: /etc/nftables.conf
      notify:
        - restart nftables

    - name: enable dhcpcd
      systemd:
        name: dhcpcd
        enabled: true
        state: started

    - name: enable wpa_supplicant
      systemd:
        name: wpa_supplicant@wlp3s0
        enabled: true
        state: started

    - name: Install LaTeX
      pacman:
        pkg:
          - texlive-most
          - texlive-lang
          - texlive-langextra
          - biber

    - name: Install X & stuff
      pacman:
        pkg:
          - xorg-server
          - xorg-apps
#          - xf86-video-amdgpu
          - xmonad
          - xmonad-contrib
          - xmobar
          - xorg-xinit
          - xorg-xlsfonts
          - xdg-utils
          - gnu-free-fonts
          - noto-fonts
          - ttf-bitstream-vera
          - ttf-caladea
          - ttf-carlito
          - ttf-croscore
          - ttf-dejavu
          - ttf-droid
          - ttf-liberation
          - ttf-ubuntu-font-family
          - xorg-fonts
          - xorg-fonts-100dpi
          - xorg-fonts-75dpi
          - xorg-fonts-alias-100dpi
          - xorg-fonts-alias-75dpi
          - xorg-fonts-alias-misc
          - xorg-fonts-misc
          - xclip
          - i3lock
          - firefox
          - chromium
          - thunderbird
          - rxvt-unicode
          - mousepad
          - pavucontrol
          - arandr
          - xcape
          - redshift
          - alsa-utils
          - pulseaudio
          - pulseaudio-alsa
          - pulseaudio-bluetooth
          - tk
          - nmap
          - evince
          - pdfpc
          - thunar
          - gvfs
          - gvfs-smb
          - thunar-archive-plugin
          - xarchiver
          - viewnior
          - tumbler
          - libreoffice-fresh
          - libreoffice-fresh-en-gb
          - libreoffice-fresh-cs
          - libreoffice-fresh-sk
          - xf86-input-wacom
          - discord
          - meld
      notify:
        - font caches


    - name: Install bluetooth
      pacman:
        pkg:
          - bluez-utils
      notify:
        - enable bluetooth

    - name: Xorg font config
      copy:
        content: |
          # Let X.Org know about the custom font directories
          Section "Files"
              FontPath    "/usr/share/fonts/100dpi"
              FontPath    "/usr/share/fonts/75dpi"
              FontPath    "/usr/share/fonts/cantarell"
              FontPath    "/usr/share/fonts/cyrillic"
              FontPath    "/usr/share/fonts/encodings"
              FontPath    "/usr/share/fonts/misc"
              FontPath    "/usr/share/fonts/truetype"
              FontPath    "/usr/share/fonts/TTF"
              FontPath    "/usr/share/fonts/util"
          EndSection
        dest: /etc/X11/xorg.conf.d/all-the-fonts.conf
      notify:
        - font caches

    - name: Haskell
      pacman:
        pkg:
          - ghc
          - darcs
          - cabal-install
          - haskell-quickcheck
          - haskell-hunit
          - haskell-hakyll
          - haskell-base-unicode-symbols
          - haskell-regex-pcre
          - haskell-hint
          - haskell-ieee754
          - hlint

    - name: Misc tools
      pacman:
        pkg:
          - mypy
          - flake8
          - python-pip
          - python-pygments
          - python-dateutil
          - python-flake8-blind-except
          - python-hypothesis
          - python-hunter
          - python-aiohttp
          - python-tzlocal
          - python-antlr4
          - python-pytest
          - python-flask
          - python-flask-wtf
          - python-wtforms
          - python-aiofiles
          - python-systemd
          - python-asyncpg
          - python-psycopg2
          - python-tabulate
          - antlr4
          - inkscape
          - gimp
          - darktable
          - audacity
          - irssi
          - postgresql-libs
          - dotnet-runtime
          - dotnet-sdk
          - code
          - tigervnc
          - pacgraph
          - tidy
          - cloc
          - z3
          - openldap
          - clusterssh
          - ocaml
          - obs-studio
          - kdenlive
          - vlc
          - r
          - sysbench
          - p7zip
          - archiso
          - boost

    - name: Flake8 linters
      pip:
        name:
          - flake8-mutable
          - flake8-annotations
          - flake8-comprehensions
          - flake8-executable
          - flake8-fixme
          - flake8-use-fstring
          - flake8-builtins

    - name: Python libs (mostly for exprtest)
      pip:
        name:
          - pylibacl
          - aiohttp_mako
          - aiohttp_jinja2
          - Flask-Markdown
          - pandoc-include
#        state: latest

    - name: R packages
      command: Rscript --vanilla -e "install.packages('{{item}}', repos=c('http://www.freestatistics.org/cran/'))"
      loop:
        - ggplot2
        - dplyr
        - svglite


    - name: setup kerberos
      copy:
        src: roles/common_deb/files/krb5.conf
        dest: /etc/krb5.conf

    - name: Install flatpak
      pacman:
        pkg:
          - flatpak
      notify:
        - flatpak flathub

    - name: Install misc flatpaks
      community.general.flatpak:
        state: present
        name: '{{item}}'
      loop:
        - com.spotify.Client
        - com.microsoft.Teams
        - us.zoom.Zoom
#        - com.discordapp.Discord

    - name: Systemd power management
      replace:
        path: /etc/systemd/logind.conf
        regexp: '^#?(HandleLidSwitch[^=]*)=.*$'
        replace: '\1=ignore'
      notify:
        - logind reload

    - name: Printing & scanning
      pacman:
        pkg:
          - cups
          - gutenprint
          - sane
          - xsane

    - name: CUPS service
      systemd:
        name: cups.socket
        enabled: True
        state: started

    - name: Disable beeper
      copy:
        content: "blacklist pcspkr"
        dest: /etc/modprobe.d/nobeep.conf

    - name: Install PostgreSQL
      pacman:
        pkg:
          - postgresql      

    - name: Check if Postgres is created
      stat:
        path: '{{postgres_server_root}}/data/PG_VERSION'
      register: postgres_server_created

    - block:
      - name: 'Create {{postgres_server_root}}'
        file:
          path: '{{postgres_server_root}}'
          state: directory
          owner: postgres
          group: postgres
          mode: '0755'

      - name: Init postgres
        command:
          cmd: 'initdb --locale=en_US.UTF-8 -E UTF8  -D {{postgres_server_root}}/data'
          chdir: '{{postgres_server_root}}'
        become: True
        become_user: postgres
      when: not postgres_server_created.stat.exists

    - name: Postgres enabled
      systemd:
        name: postgresql
        enabled: true
        state: started

    - name: Create postgreSQL role for xstill
      postgresql_user:
        login_unix_socket: "/var/run/postgresql/"
        name: xstill

    - name: Create postgreSQL DB for hsExprTest
      postgresql_db:
        login_unix_socket: "/var/run/postgresql/"
        name: exprtest
        owner: xstill

    - name: Photos
      pacman:
        pkg:
          - gphoto2
          - gvfs-gphoto2 

    - name: Containers
      pacman:
        pkg: podman

  handlers:
    - name: font caches
      command: '{{item}}'
      loop:
        - fc-cache
        - mkfontscale
        - mkfontdir

    - name: enable bluetooth
      systemd:
        name: bluetooth
        enabled: true
        state: started

    - name: flatpak flathub
      command: '{{item}}'
      loop:
        - flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
        - flatpak update

    - name: restart nftables
      systemd:
        name: nftables
        enabled: true
        state: restarted

    - name: restart wpa_supplicant
      systemd:
        name: wpa_supplicant@wlp3s0
        state: restarted

    - name: logind reload
      command: systemctl kill -s HUP systemd-logind

# vim: shiftwidth=2 tabstop=2 softtabstop=2 ft=yaml.ansible
