base:
    - install:
        arch:
            - base-devel
            - libnotify
            - pacman-contrib # for checkupdates, paccache, pacdiff...
            - pkgfile        # get hint on missing package when command not found
            - python-pip
            - python-setuptools
            - reflector
            - xorg-xinit     # enable xinit to avoid having to type 'startx'
            - ttf-font-awesome
            - ttf-jetbrains-mono
        debian:
            - build-essential
            - libnotify-bin
            - python3-venv
            - python3-pip
            - python3-setuptools
            - xinit          # enable xinit to avoid having to type 'startx'
            - fonts-font-awesome
            - fonts-jetbrains-mono
        both:
            - rsync          # used for backup
            - curl
            - wget
            - xorg
            - numlockx       # activate numlock (set in .xinitrc)
            - notification-daemon
            - udiskie    # automount external drives (set in .xinitrc)
            - xmlstarlet # for clitip
            - pandoc     # for clitip
    - run:
        - sudo ln -rsi dotfiles/dbus/org.freedesktop.Notifications.service /usr/share/dbus-1/services/org.freedesktop.Notifications.service
    - run:
        command: sudo pkgfile -u
        condition: arch

xmodmap:
    - symlink:
        - dotfiles/Xmodmap
        - ~/.Xmodmap

sudoers:
    - run:
        - sudo sed "s/\$USER/$USER/g" dotfiles/sudoers.d/* | sudo tee /etc/sudoers.d/setup-cockpit >/dev/null 2>&1 &&
          sudo chmod 600 /etc/sudoers.d/setup-cockpit

pacman.conf:
    - run:
        command: sudo cp /etc/pacman.conf /etc/pacman.conf.backup
        condition: "[ ! -e /etc/pacman.conf.backup ]"
    - run:
        - sudo sed -i 's/#HookDir/HookDir/' /etc/pacman.conf &&
          sudo sed -i 's/#Color/Color/' /etc/pacman.conf &&
          sudo sed -i 's/#TotalDownload/TotalDownload/' /etc/pacman.conf &&
          sudo sed -i 's/#CheckSpace/CheckSpace/' /etc/pacman.conf &&
          sudo sed -i 's/#VerbosePkgLists/VerbosePkgLists/' /etc/pacman.conf

grub:
    - install:
        arch:
            - grub-theme-vimix
    - run:
        command: sudo cp /etc/default/grub /etc/default/grub.backup
        condition: "[ ! -e /etc/default/grub.backup ]"
    - run:
        - sudo sed -i -E 's/^#?GRUB_DEFAULT.+/GRUB_DEFAULT=saved/' /etc/default/grub &&
          sudo sed -i -E 's@^#?GRUB_THEME.+@GRUB_THEME="/usr/share/grub/themes/Vimix/theme.txt"@' /etc/default/grub &&
          sudo sed -i -E 's/^#?GRUB_SAVEDEFAULT.+/GRUB_SAVEDEFAULT=true/' /etc/default/grub &&
          sudo sed -i -E 's/^#?GRUB_DISABLE_SUBMENU.+/GRUB_DISABLE_SUBMENU=y/' /etc/default/grub &&
          sudo grub-mkconfig -o /boot/grub/grub.cfg

firefox:
    - install:
        arch:
            - firefox
        debian:
            - firefox-esr
    - run:
        - firefox $(sed -n '/^    http/p' firefox_addons.txt)

tor:
    - install:
        - torbrowser-launcher

kitty:
    - install:
        - kitty
    - symlink:
        - dotfiles/kitty.conf
        - ~/.config/kitty/kitty.conf
    - clone:
        - https://github.com/dexpota/kitty-themes.git
        - ~/.git_clones/kitty-themes
    - symlink:
        - ~/.git_clones/kitty-themes/themes/gruvbox_dark.conf
        - ~/.config/kitty/theme.conf

bash:
    - install:
        - bash-completion
    - symlink:
        - dotfiles/bash/bashrc
        - ~/.bashrc
    - symlink:
        - dotfiles/shell/aliases
        - ~/.bash_aliases
    - symlink:
        - dotfiles/bash/bash_profile
        - ~/.bash_profile
    - symlink:
        - dotfiles/bash/inputrc
        - ~/.inputrc
    - clone:
        - https://github.com/magicmonty/bash-git-prompt.git
        - ~/.bash-git-prompt

git:
    - install:
        - git
    - run:
        - . ./secrets &&
          git config --global user.name "${USER}@$(uname -n)";
          git config --global user.email "$GIT_EMAIL";
          git config --global pull.rebase false;
          git config --global alias.br "branch";
          git config --global alias.ci "commit";
          git config --global alias.co "checkout";
          git config --global alias.st "status";
          git config --global alias.logadog "log --all --decorate --oneline --graph";
          git config --global alias.chlog "log --no-merges --oneline --stat @{1}..";
          git config --global alias.df "diff --word-diff=color";
          git config --global diff.tool vimdiff;
          git config --global init.defaultBranch "main"
    - symlink:
        - dotfiles/git/ignore
        - ~/.config/git/ignore

etckeeper:
    - install:
        - etckeeper
    - run:
        - sudo git config --global user.name "root@$(uname -n)";
          sudo git config --global user.email "root@$(uname -n)";
          sudo git config --global init.defaultBranch "main"
    - run:
        command: sudo etckeeper init
        condition: "[ ! -d /etc/.git ]"
    - run:
        - sudo etckeeper commit "First commit"

git-summary:
    - clone:
        - https://gitlab.com/lordadamson/git-summary.git
        - ~/.git_clones/git-summary
    - symlink:
        - ~/.git_clones/git-summary/git-summary
        - ~/.local/bin/git-summary

gitleaks:
    - run:
        command: curl -Lo ~/.local/bin/gitleaks https://github.com/zricethezav/gitleaks/releases/download/v6.2.0/gitleaks-linux-amd64 && chmod +x ~/.local/bin/gitleaks
        condition: "[ ! -e ~/.local/bin/gitleaks ] && [ $(uname -m) = 'x86_64' ]"
    - run:
        command: curl -Lo ~/.local/bin/gitleaks https://github.com/zricethezav/gitleaks/releases/download/v6.2.0/gitleaks-linux-arm && chmod +x ~/.local/bin/gitleaks
        condition: "[ ! -e ~/.local/bin/gitleaks ] && [ ! $(uname -m) = 'x86_64' ]"

talisman:
    - run:
        - curl -o /tmp/install_talisman.bash https://raw.githubusercontent.com/thoughtworks/talisman/master/global_install_scripts/install.bash && /bin/bash /tmp/install_talisman.bash

repos:
    - clone:
        url: git@tunuifranken.info:flyingscorpio/secrets.git
        dest: ~/src/secrets
        branch: main
    - symlink:
        - ~/src/secrets/setup-cockpit/repos.yml
        - ~/setup-cockpit/repos.yml
    - include:
        - repos.yml

pass:
    - install:
        - pass
        - gnupg
    - clone:
        url: git@tunuifranken.info:flyingscorpio/.password-store.git
        dest: ~/.password-store
        branch: main
    - run:
        - gpg --import ~/src/secrets/privkey.asc
    - symlink:
        - dotfiles/gpg/gpg-agent.conf
        - ~/.gnupg/gpg-agent.conf
    - run:
        - sudo cp /usr/bin/passmenu /usr/bin/passmenu-url &&
          sudo sed -i "s/pass show -c/pass show -c2/g" /usr/bin/passmenu-url;
          sudo cp /usr/bin/passmenu /usr/bin/passmenu-user &&
          sudo sed -i "s/pass show -c/pass show -c3/g" /usr/bin/passmenu-user

keepass:
    - install:
        - keepassxc
    - clone:
        - git@tunuifranken.info:flyingscorpio/keepass.git
        - ~/keepass

protonvpn:
    - install:
        debian:
            - openvpn
            - dialog
    - clone:
        url: https://aur.archlinux.org/protonvpn-cli-ng.git
        dest: ~/builds/protonvpn-cli-ng
        condition: arch
    - run:
        command: cd ~/builds/protonvpn-cli-ng && makepkg -cirs --needed
        condition: arch
    - run:
        command: sudo pip3 install protonvpn-cli
        condition: debian
    - run:
        - sudo protonvpn init && sudo protonvpn c -f # you will need to add your credentials by hand during init

mariadb:
    - install:
        - mariadb
    - run:
        command: sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql && sudo systemctl start mysqld.service && sudo mysql_secure_installation
        condition: "find /var/lib/mysql -mindepth 1 | read"

i3:
    - install:
        arch:
            - noto-fonts
            - i3-gaps
            - dmenu         # launch programs
        debian:
            - fonts-noto
            - i3-wm
            - suckless-tools
        both:
            - picom
            - xdg-user-dirs
            - i3blocks
            - i3lock
            - xsettingsd
            - lxappearance
            - scrot         # enable screenshot with Printscreen
            - viewnior
            - hsetroot
    - symlink:
        - dotfiles/i3/config
        - ~/.config/i3/config
    - clone:
        - https://github.com/addy-dclxvi/i3-starterpack.git
        - ~/.git_clones/i3-starterpack
    - symlink:
        - dotfiles/xinitrc
        - ~/.xinitrc
    - symlink:
        - dotfiles/xserverrc
        - ~/.xserverrc
    - symlink:
        - dotfiles/Xresources
        - ~/.Xresources
    - symlink:
        - dotfiles/xsettingsd
        - ~/.xsettingsd
    - symlink:
        - dotfiles/picom.conf
        - ~/.config/picom.conf
    - symlink:
        - dotfiles/picom.conf
        - ~/.config/compton.conf
    - symlink:
        - ~/.git_clones/i3-starterpack/.fonts/icomoon/feather.ttf
        - ~/.fonts/icomoon/feather.ttf
    - run:
        - fc-cache -fv
    - run:
        - xdg-user-dirs-update

i3blocks:
    - install:
        arch:
            - python-feedparser
            - python-matplotlib
        both:
            - sysstat
            - upower
    - symlink:
        - dotfiles/i3/blocks
        - ~/.config/i3blocks/config
    - clone:
        - https://github.com/vivien/i3blocks-contrib.git
        - ~/.git_clones/i3blocks-contrib
    - symlink:
        - dotfiles/i3/scripts/nagstamon
        - ~/.config/i3blocks/scripts/nagstamon
    - symlink:
        src: ~/.git_clones/i3blocks-contrib/apt-upgrades/apt-upgrades
        dest: ~/.config/i3blocks/scripts/apt-upgrades
        condition: debian
    - symlink:
        src: ~/.git_clones/i3blocks-contrib/arch-update/arch-update
        dest: ~/.config/i3blocks/scripts/arch-update
        condition: arch
    - symlink:
        - dotfiles/i3/scripts/arch_linux_news/arch_linux_news
        - ~/.config/i3blocks/scripts/arch_linux_news
    - run:
        command: pip install -U matplotlib feedparser --user
        condition: debian
    - symlink:
        - dotfiles/i3/scripts/corona_stats/corona_stats
        - ~/.config/i3blocks/scripts/corona_stats
    - symlink:
        - dotfiles/i3/scripts/crypto
        - ~/.config/i3blocks/scripts/crypto
    - symlink:
        - dotfiles/i3/scripts/protonvpn
        - ~/.config/i3blocks/scripts/protonvpn
    - symlink:
        - ~/.git_clones/i3blocks-contrib/calendar/calendar
        - ~/.config/i3blocks/scripts/calendar
    - symlink:
        - ~/.git_clones/i3blocks-contrib/temperature/temperature
        - ~/.config/i3blocks/scripts/temperature
    - symlink:
        - ~/.git_clones/i3blocks-contrib/cpu_usage/cpu_usage
        - ~/.config/i3blocks/scripts/cpu_usage
    - symlink:
        - dotfiles/i3/scripts/free_disk_space
        - ~/.config/i3blocks/scripts/free_disk_space

markdown viewer:
    - write:
        - ~/.local/share/mime/packages/text-markdown.xml
        - |
          <?xml version="1.0"?>
          <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
            <mime-type type="text/plain">
              <glob pattern="*.md"/>
              <glob pattern="*.mkd"/>
              <glob pattern="*.markdown"/>
            </mime-type>
          </mime-info>
    - run:
        - update-mime-database ~/.local/share/mime

rust:
    - run:
        command: rustup self uninstall
        condition: "[ -e ~/.cargo ]"
    - install:
        - rustup
    - run:
        - rustup default stable

java:
    - install:
        - jdk-openjdk

vim:
    - install:
        arch:
            - gvim
            - python-pylint
            - base-devel
        debian:
            - vim-gtk
            - pylint3
            - build-essential
            - python3-dev
        both:
            - flake8
            - mypy
            - shellcheck
            - cmake
            - clang
            - npm # for coc
    - run:
        command: /bin/bash ./shellcheck_binary_fix.sh
        condition: arch # some Arch derivatives have this problem (arch32, archarm)
    - symlink:
        - dotfiles/flake8
        - ~/.config/flake8
    - symlink:
        - dotfiles/pylintrc
        - ~/.pylintrc
    - symlink:
        - dotfiles/vim/vimrc
        - ~/.vimrc
    - symlink:
        - dotfiles/vim/colors
        - ~/.vim/colors
    - run:
        command: curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
        condition: "[ ! -e ~/.vim/autoload/plug.vim ]"
    - run:
        - vim +PlugInstall +qall # run this without conditions so it includes added stuff
    - run:
        command: vim +PlugUpgrade +qall
        condition: update
    - run:
        command: vim +PlugUpdate +qall
        condition: update
    - run:
        command: vim +BlackUpgrade +qall
        condition: update
    - run:
        - pip install -U hdl-checker --user

neovim:
    - depend:
        - vim
    - install:
        - arch:
              - python-neovim
        - both:
              - neovim
    - run:
        command: pip install -U neovim --user
        condition: debian
    - run:
        - pip install -U neovim-remote --user
    - symlink:
        - dotfiles/vim/init.vim
        - ~/.config/nvim/init.vim

zsh:
    - install:
        - zsh
        - zsh-completions
        - zsh-autosuggestions
        - zsh-syntax-highlighting
        - zsh-theme-powerlevel10k
    - symlink:
        - dotfiles/zsh/zshrc
        - ~/.zshrc
    - symlink:
        - dotfiles/zsh/zshenv
        - ~/.zshenv
    - symlink:
        - dotfiles/zsh/zprofile
        - ~/.zprofile
    - symlink:
        - dotfiles/zsh/p10k.zsh
        - ~/.p10k.zsh
    - symlink:
        - dotfiles/shell/aliases
        - ~/.zsh_aliases
    - clone:
        url: https://github.com/softmoth/zsh-vim-mode.git
        dest: ~/.git_clones/zsh-vim-mode
        branch: main
    - clone:
        url: https://github.com/zsh-users/zsh-autosuggestions.git
        dest: ~/.git_clones/zsh-autosuggestions
        branch: master
    - clone:
        url: https://github.com/zsh-users/zsh-syntax-highlighting.git
        dest: ~/.git_clones/zsh-syntax-highlighting
        branch: master

pacman_hooks:
    - run:
        - sudo mkdir -p /etc/pacman.d/hooks
    - run:
        command: sudo ln -rsi dotfiles/pacman_hooks/borg_backup.hook /etc/pacman.d/hooks/borg_backup.hook
        condition: "[[ $(uname -n) = 'arch-desktop' ]]"
    - run:
        - sudo ln -rsi dotfiles/pacman_hooks/new_orphan.hook /etc/pacman.d/hooks/new_orphan.hook
    - run:
        - sudo ln -rsi dotfiles/pacman_hooks/pacdiff.hook /etc/pacman.d/hooks/pacdiff.hook
    - run:
        - sudo ln -rsi dotfiles/pacman_hooks/mirrorupgrade.hook /etc/pacman.d/hooks/mirrorupgrade.hook
    - run:
        - sudo ln -rsi dotfiles/pacman_hooks/paccache.hook /etc/pacman.d/hooks/paccache.hook

rsync_backup:
    - run:
        - sudo ln -rsi dotfiles/systemd_timers/rsync_backup.timer /etc/systemd/system/rsync_backup.timer
    - run:
        - sudo ln -rsi dotfiles/systemd_timers/rsync_backup.service /etc/systemd/system/rsync_backup.service
    - run:
        - sudo systemctl enable rsync_backup.timer
    - symlink:
        - ~/src/secrets/setup-cockpit/rsync_backup_excludes
        - ~/setup-cockpit/rsync_backup_excludes

gitea_backup_rsync:
    - run:
        - sudo ln -rsi dotfiles/systemd_timers/gitea_backup_rsync.timer /etc/systemd/system/gitea_backup_rsync.timer
    - run:
        - sudo ln -rsi dotfiles/systemd_timers/gitea_backup_rsync.service /etc/systemd/system/gitea_backup_rsync.service
    - run:
        - sudo systemctl enable gitea_backup_rsync.timer

latex:
    - install:
        arch:
            - texlive-most
            - texlive-lang
            - biber
        debian:
            - texlive-full
    - symlink:
        - dotfiles/latexmkrc
        - ~/.latexmkrc

lilypond:
    - install:
        - lilypond

powershell:
    - clone:
        url: https://aur.archlinux.org/powershell-bin.git
        dest: ~/builds/powershell-bin
        condition: arch
    - run:
        command: cd ~/builds/powershell-bin && makepkg -cirs --needed
        condition: arch

gaming:
    - run:
        command: sudo cp /etc/pacman.conf /etc/pacman.conf.backup
        condition: "[ ! -e /etc/pacman.conf.backup ]"
    - run:
        - 'LINESTART=$(grep -n "\[multilib\]" /etc/pacman.conf | cut -d: -f1 | head -n1); LINEEND=$((LINESTART+1)); sudo sed -i "${LINESTART},${LINEEND} s/^#//" /etc/pacman.conf'
    - install:
        - wine-staging
        - winetricks
        - lutris
        - steam
        - gamemode
        - giflib
        - lib32-giflib
        - libpng
        - lib32-libpng
        - libldap
        - lib32-libldap
        - gnutls
        - lib32-gnutls
        - mpg123
        - lib32-mpg123
        - openal
        - lib32-openal
        - v4l-utils
        - lib32-v4l-utils
        - libpulse
        - lib32-libpulse
        - libgpg-error
        - lib32-libgpg-error
        - alsa-plugins
        - lib32-alsa-plugins
        - alsa-lib
        - lib32-alsa-lib
        - libjpeg-turbo
        - lib32-libjpeg-turbo
        - sqlite
        - lib32-sqlite
        - libxcomposite
        - lib32-libxcomposite
        - libxinerama
        - lib32-libxinerama
        - libgcrypt
        - lib32-libgcrypt
        - ncurses
        - lib32-ncurses
        - opencl-icd-loader
        - lib32-opencl-icd-loader
        - libxslt
        - lib32-libxslt
        - libva
        - lib32-libva
        - gtk3
        - lib32-gtk3
        - gst-plugins-base-libs
        - lib32-gst-plugins-base-libs
        - vulkan-icd-loader
        - lib32-vulkan-icd-loader