mirror of
https://github.com/kazhala/dotbare
synced 2024-11-13 13:10:35 +00:00
68 lines
1.5 KiB
Bash
Executable File
68 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# backup all tracked files
|
|
#
|
|
# @params
|
|
# Globals
|
|
# None
|
|
# Arguments
|
|
# None
|
|
|
|
set -e
|
|
set -f
|
|
|
|
mydir="${0%/*}"
|
|
source "${mydir}"/../helper/set_variable.sh
|
|
source "${mydir}"/../helper/git_query.sh
|
|
|
|
function usage() {
|
|
echo -e "Usage: dotbare fbackup [-h] ...\n"
|
|
echo -e "Backup files to ${DOTBARE_BACKUP}"
|
|
echo -e "This is useful when untracking files or migrating on new machines\n"
|
|
echo -e "optional arguments:"
|
|
echo -e " -h\tshow this help message and exit"
|
|
}
|
|
|
|
#######################################
|
|
# backup passed in files while preserving directory info
|
|
# Arguments:
|
|
# $1: files to backup, seperate by \n
|
|
#######################################
|
|
function dotbare_backup() {
|
|
local selected_files="$1"
|
|
while IFS= read -r line; do
|
|
dir_name=$(dirname "${line}")
|
|
[[ ! -d "${DOTBARE_BACKUP}/${dir_name}" ]] && mkdir -p "${DOTBARE_BACKUP}/${dir_name}"
|
|
cp -v "${line}" "${DOTBARE_BACKUP}/${line}"
|
|
done <<< "${selected_files}"
|
|
}
|
|
|
|
individual_file=""
|
|
while getopts ":hs" opt; do
|
|
case "$opt" in
|
|
s)
|
|
individual_file='true'
|
|
;;
|
|
h)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Invalid option: ${OPTARG}" >&2
|
|
usage
|
|
exit 0
|
|
;;
|
|
esac
|
|
done
|
|
|
|
cd "${DOTBARE_TREE}"
|
|
|
|
if [[ -n "${individual_file}" ]]; then
|
|
selected_files=$(get_git_file "select files to backup" "raw")
|
|
else
|
|
selected_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" \
|
|
ls-files --full-name --directory "${DOTBARE_TREE}")
|
|
fi
|
|
|
|
dotbare_backup "${selected_files}"
|