From cfa721db33ee996566e51f0f180dcac86c0a19d3 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 26 Sep 2018 17:12:04 +0200 Subject: [PATCH] Added update into dotfiles functions --- zsh/functions.zsh | 13 ++------ zsh/update.zsh | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 zsh/update.zsh diff --git a/zsh/functions.zsh b/zsh/functions.zsh index 4769978..a6a646d 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -42,17 +42,6 @@ vfind() { } ### Others ### -pull-dotfiles() { - current_dir=$PWD - echo Pulling dotfiles... - cd ~/.config/dotfiles && git pull - echo Pulling scripts... - cd ~/.scripts && git pull - echo Pulling oh-my-zsh - cd ~/.config/oh-my-zsh && git pull - cd $current_dir -} - # Recover a vim backup recover() { if [ -f $1 ]; then @@ -100,6 +89,8 @@ makelatex() { cp /home/thomas/.script/classgen/Makefile.latex ./Makefile } +source $HOME/.config/dotfiles/zsh/update.zsh + # cdg : cd to a git repo if [ -d "$GCLONE_PATH" ]; then diff --git a/zsh/update.zsh b/zsh/update.zsh new file mode 100644 index 0000000..b5afaa1 --- /dev/null +++ b/zsh/update.zsh @@ -0,0 +1,75 @@ +pull-dotfiles() { + current_dir=$PWD + echo "\033[32;1m=== Updating dotfiles ===\033[0m" + cd ~/.config/dotfiles && git pull + echo "\033[32;1m=== Updating oh-my-zsh ===\033[0m" + cd ~/.config/oh-my-zsh && git pull + cd $current_dir +} + +update() { + + echo "\033[32;1m=== Starting the update, please enter your password ===\033[0m" + + # Ask for sudo right now + sudo true + + if [ $? -ne 0 ]; then + echo "Could not get sudo..." + exit 1 + fi + + echo "\033[32;1m=== Updating system ===\033[0m" + + # Debian based systems + command -v apt > /dev/null 2>&1 + if [ $? -eq 0 ]; then + sudo apt update -y + if [ $? -eq 0 ]; then + sudo apt upgrade -y + if [ $? -eq 0 ]; then + sudo apt autoremove -y + fi + fi + fi + + # Archlinux based systems + command -v yaourt > /dev/null 2>&1 + if [ $? -eq 0 ]; then + yaourt -Syu + else + command -v pacman > /dev/null 2>&1 + + if [ $? -eq 0 ]; then + sudo pacman -Syu + fi + fi + + # Fedora based systems + command -v dnf > /dev/null 2>&1 + if [ $? -eq 0 ]; then + dnf upgrade + fi + + # Update rust if installed + command -v rustup > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "\033[32;1m=== Updating rustup ===\033[0m" + rustup self update + + echo "\033[32;1m=== Updating rust ===\033[0m" + rustup update + + cargo install-update --help > /dev/null 2>&1 + + if [ $? -eq 0 ]; then + echo "\033[32;1m=== Updating rust packages ===\033[0m" + cargo install-update -ag + fi + fi + + # Update the dotfiles + pull-dotfiles + + echo "\033[32;1m=== Update finished ===\033[0m" +}