#/bin/bash

[ ! -f "$HOME/.ssh/id_ed25519" ] && echo "Please import ssh keys before going further"

# check sudoer for install
groups | grep -q sudo || echo "Please, as root, add $(whoami) to sudo group with : sudo usermod -aG sudo $(whoami), then reboot and relaunch this script"
groups | grep -q sudo || return

sudo apt update
sudo apt install -y yadm  vim-gtk3 vim vim-nox fzf cmake zsh \
  webext-browserpass webext-ublock-origin-firefox curl pass python3 ripgrep fonts-firacode fd-find postgresql rsync \
  nextcloud-desktop tig locate htop  make screenfetch isync notmuch lynx urlview\
  gcc inkscape python3-pip kubectl kubectx imagemagick pdfarranger firefox gpaste-2 jq color-picker
sudo apt autoremove

# récupération yadm si necessaire
[ ! -f "$HOME/.local/bin/passmenu2" ] && yadm init && yadm remote add origin git@git.portenseigne.ovh:pgil/dotfiles.git && yadm fetch --all && yadm checkout main

[ ! -f "$HOME/.local/bin/fd" ] && ln -s $(which fdfind) ~/.local/bin/fd

#config imagemagick
#sudo sed -i '/"PDF"/s/none/read|write/' /etc/ImageMagick-6/policy.xml

sudo chsh -s /bin/bash $USER

# Installation oh my bash
[ ! -d "$HOME/.oh-my-zsh/" ] && bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" || echo "oh-my-zsh installed"

# Installation config specif bash + aliases
grep -q "gil_specific"  "$HOME/.zshrc" && echo "Bash configured" || sed -i -e '$asource "$HOME/.config/bash/gil_specific.sh"\' $HOME/.zshrc
grep -q "Xautolock"  "$HOME/.Xresources" && echo "autolock configured" || sed -i -e '$aXautolock.corners: ----' $HOME/.Xresources

# Installation sdkman
[ ! -d "$HOME/.sdkman/" ] && curl -s "https://get.sdkman.io" | bash

git config --global user.email "gil.portenseigne@nereide.fr"
git config --global user.name "Gil Portenseigne"

echo "Maintenant à installer : Idea-Eclipse,
Nexcloud sync, parsec"
echo "https://github.com/nordtheme/gnome-terminal"
echo "https://fostips.com/install-latest-firefox-non-esr-debian/"
echo "https://freetubeapp.io/"
echo "faire un source .bashrc"

# Install bruno
# sudo mkdir -p /etc/apt/keyrings
# sudo gpg --no-default-keyring --keyring /etc/apt/keyrings/bruno.gpg --keyserver keyserver.ubuntu.com --recv-keys 9FA6017ECABE0266
# echo "deb [signed-by=/etc/apt/keyrings/bruno.gpg] http://debian.usebruno.com/ bruno stable" | sudo tee /etc/apt/sources.list.d/bruno.list
# sudo apt update
# sudo apt install bruno
