]> danix's work - dots-backup.git/commitdiff
Added script and readme master
authorDanilo M. <redacted>
Fri, 6 Feb 2026 10:26:08 +0000 (11:26 +0100)
committerDanilo M. <redacted>
Fri, 6 Feb 2026 10:26:08 +0000 (11:26 +0100)
README.md [new file with mode: 0644]
dot-backup.sh [new file with mode: 0755]

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..140ae2c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# dots-backup
+
+A simple bash script to backup all my dotfiles and have them available to be easily restored on any system.
\ No newline at end of file
diff --git a/dot-backup.sh b/dot-backup.sh
new file mode 100755 (executable)
index 0000000..aef6fee
--- /dev/null
@@ -0,0 +1,192 @@
+#! /bin/bash
+
+#####################################################################
+#           ___        __   ___                   __                 
+#        __| _/ ____ _/  |_ \_ |__ _____    ____ |  | ____ ________  
+#       / __ | / __ \\   __\ | __ \\__  \ _/ ___\|  |/ /  |  \____ \ 
+#      / /_/ |(  \_\ )|  |   | \_\ \/ __ \_  \___|    \|  |  /  |_\ \
+#      \____ | \____/ |__|   |___  /____  /\___  /__|_ \____/|   ___/
+#           \/                   \/     \/     \/     \/     |__|    
+#
+#      by danix
+#
+#####################################################################
+
+set -euo pipefail
+
+# Colors for output
+GREEN='\033[0;32m'
+BLUE='\033[0;34m'
+YELLOW='\033[1;33m'
+RED='\033[0;31m'
+NC='\033[0m' # No Color
+
+### DIRECTORIES
+WORKDIR=$(pwd)
+# Output directory
+#DEFAULT_OUTPUT_DIR="${HOME}/Programming/GIT/my-dotfiles"
+DEFAULT_OUTPUT_DIR="/tmp/my-dotfiles"
+
+# The list of dotfiles
+DOTFILES=(
+    # Shell configurations
+    ".bashrc"
+    ".bash_profile"
+    ".bash_aliases"
+    ".bash_functions"
+    ".dir_colors"
+    ".lessfilter"
+    ".profile.d"
+
+    # Shell history (optional - comment out if you don't want history)
+    # ".bash_history"
+
+    # Git configuration
+    ".gitconfig"
+    ".gitignore_global"
+    ".gitmessage"
+
+    # Desktop
+    ".fonts"
+    ".icons"
+    ".local/share/applications"
+    ".local/share/icons"
+    ".user-icon.jpg"
+
+    # Editors
+    ".config/nvim"
+    ".config/sublime-text"
+
+    # hyprland
+    ".config/hypr"
+    ".config/wal"
+    ".config/waybar"
+    ".config/qarma.conf"
+
+    # firefox
+    # ".mozilla"
+
+    # thunderbird
+    # ".thunderbird"
+
+    # music players
+    ".config/mpd"
+    ".config/rmpc"
+    ".config/sayonara"
+    ".config/haruna"
+    ".config/harunarc"
+
+    # other programs
+    ".config/bash-notes.rc"
+    ".config/cherrytree"
+    ".config/conky"
+    ".config/draw.io"
+    ".config/featherpad"
+    ".config/htop"
+    ".config/joplin-desktop"
+    ".config/kitty"
+    ".config/lximage-qt"
+    ".config/lxqt"
+    ".config/mimeapps.list"
+    ".config/pcmanfm-qt"
+    ".config/powerline"
+    ".config/qpdfview"
+    ".config/rofi"
+
+    # pandoc
+    ".local/share/pandoc/"
+
+    # my executables
+    "bin"
+
+    ### SYSTEM FILES
+    # bash completion
+    "/etc/bash_completion.d"
+)
+
+# helper function to check if a string ($2) begins with another string ($1)
+beginswith() { 
+    case $2 in 
+        "$1"*)
+            true
+            ;; 
+        *)
+            false
+            ;;
+    esac;
+}
+
+# clear the screen before we output anything
+clear
+
+echo -e "${YELLOW}Local Git Repository: ${NC}"
+if [[ -d $DEFAULT_OUTPUT_DIR ]]; then
+    echo -e "\t${BLUE}$DEFAULT_OUTPUT_DIR ${GREEN} ${NC}"
+    # it exists, so we check for subdirectories
+    #   - home
+    #   - system
+    [ -d $DEFAULT_OUTPUT_DIR/home ] || mkdir -p $DEFAULT_OUTPUT_DIR/home
+    [ -d $DEFAULT_OUTPUT_DIR/system ] || mkdir -p $DEFAULT_OUTPUT_DIR/system
+    # check if we are in a git repository
+    cd $DEFAULT_OUTPUT_DIR
+    if [[ $(git rev-parse --is-inside-work-tree) == "true" ]]; then
+        # we are inside a git repo
+        echo -e "${GREEN}Git Repository already initialized.${NC}"
+    else
+        echo -e "${YELLOW}Initializing Git Repository. Don't forget to add your remotes.${NC}"
+        git init
+        git add .
+    fi
+else
+    echo -e "\t${BLUE}$DEFAULT_OUTPUT_DIR ${RED} ${NC}"
+    # our backup directory doesn't exists, so we make it
+    echo -e "${YELLOW}creating our backup directories${NC}"
+    mkdir -p $DEFAULT_OUTPUT_DIR/{home,system}
+    echo -e "${YELLOW}Initializing Git Repository. Don't forget to add your remotes.${NC}"
+    cd $DEFAULT_OUTPUT_DIR
+    git init
+    git add .
+fi
+
+# reset colors
+echo -e $NC
+
+cd $WORKDIR
+# we iterate all dotfiles in the list
+for i in ${DOTFILES[@]}; do
+    # if it's a file in my home
+    if [[ -f ${HOME}/$i ]]; then
+        echo -e "${GREEN}${HOME}/$i\t  ${NC}"
+        # it exists, we copy it to our output directory
+        rsync -a ${HOME}/$i ${DEFAULT_OUTPUT_DIR}/home/ && echo -e "\t ${GREEN}Copied\t  ${NC}"
+    # if it's a directory in my home
+    elif [[ -d ${HOME}/$i ]]; then
+        echo -e "${BLUE}${HOME}/$i\t  ${NC}"
+        # it exists, we copy it to our output directory
+        rsync -a ${HOME}/$i ${DEFAULT_OUTPUT_DIR}/home/ && echo -e "\t ${GREEN}Copied\t  ${NC}"
+    # if it begins with a / it's a system file/directory 
+    elif beginswith "/" $i; then
+        # if it's a file
+        if [[ -f $i ]]; then
+            echo -e "${GREEN}$i\t  ${NC}"
+            # it exists, we copy it to our output directory
+            rsync -a $i ${DEFAULT_OUTPUT_DIR}/system/ && echo -e "\t ${GREEN}Copied\t  ${NC}"
+        # if it's a directory
+        elif [[ -d $i ]]; then
+            echo -e "${BLUE}$i\t  ${NC}"
+            # it exists, we copy it to our output directory
+            rsync -a $i ${DEFAULT_OUTPUT_DIR}/system/ && echo -e "\t ${GREEN}Copied\t  ${NC}"
+        fi
+    # if it doesn't exists
+    else
+        echo -e "\n${RED}NOT FOUND: ${i}\t  ${NC}\n"
+    fi
+done
+
+echo -e "\n${GREEN}Adding all copied files to git.${NC}"
+cd $DEFAULT_OUTPUT_DIR
+git add .
+# reset colors before exiting
+echo -e $NC
+cd $WORKDIR
+exit 0