- Remove bash template file

- Script to bootstrap the dotfiles
This commit is contained in:
Pratik Tripathy
2021-07-06 02:35:29 +05:30
parent b1ea62811d
commit 20da8ce2f9
4 changed files with 99 additions and 175 deletions

View File

@@ -1,5 +1,5 @@
[user]
email = pratik@keepworks.com
email = mail@pratik.live
name = Pratik Tripathy
[core]
autocrlf = input

25
.gitignore vendored
View File

@@ -33,4 +33,27 @@ node_modules/*
# Ignore all minified js files
*.min.js
*.min.js
**app_stat_v2.db
.ssh/*.pub
**/Package Control.cache
**Cache
*.db
*.qmlc
*.qml
*.jsc
**/contents/images
**/contents/fonts
*kpluginindex.json
.directory
.idea/
*.imi
*.jar
*.tar
resharper-host/
tasks/

View File

@@ -1,173 +0,0 @@
#!/usr/bin/env bash
#================================================================
# HEADER
#================================================================
# SYNOPSIS
# ${SCRIPT_NAME} [-hv] [-o[file]] args ...
#
# DESCRIPTION
# This is a script template
# to start any good shell script.
# More details at https://github.com/pratiktri/your_project
#
# OPTIONS
# -o [file], --output=[file] Set log file (default=/dev/null)
# use DEFAULT keyword to autoname file
# The default value is /dev/null.
# -t, --timelog Add timestamp to log ("+%y/%m/%d@%H:%M:%S")
# -x, --ignorelock Ignore if lock file exists
# -h, --help Print this help
# -v, --version Print script information
#
# EXAMPLES
# ${SCRIPT_NAME} -o DEFAULT arg1 arg2
#
#================================================================
# IMPLEMENTATION
# version ${SCRIPT_NAME} (www.uxora.com) 0.0.4
# author Your Name Here
# copyright Copyright (c)
# license GNU General Public License
#
#================================================================
# HISTORY
# 2015/03/01 : mvongvilay : Script creation
# 2015/04/01 : mvongvilay : Add long options and improvements
#
#================================================================
# END OF HEADER
#================================================================
# All pending items here
# TODO
# Get the logging template
# Enable/Disable logging
# Log to STDOUT, File, Syslog - either or all
# Verbose and quite options
# Dates should be standard and non-abiguous
# STDOUT should have bright-yellow to display summary
# Red to display error
# Show the log location at the beginning and end
# Error Handling
# Traps
#### Bash Strict mode
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
set -o pipefail
# Exit on error. Append "|| true" if you expect an error.
set -o errexit
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
set -o nounset
# Exit on error inside any functions or subshells.
set -o errtrace
# Fail-fast checks
[[ "$(id --user)" != "0" ]] && {
echo -e "ERROR: You must be root to run this script.\nUse sudo and execute the script again."
}
usage() {
cat <<USAGE
Usage:
sudo $0 --project-name <name> --wp-source-dir <path> --backup-dir <path> [--storage-quota <size>] [--passphrase-dir <path>]"
-pname, --project-name A Unique name (usually the website name) for this backup
-wp_src, --wp-source-dir Directory where your WordPress website is stored
--backup-dir Directory where backup files will be stored
-quota, --storage-quota [Optional] Unlimited by default
When supplied backups would never exceed this capacity.
Older backups will automatically be deleted to make room for new ones.
-passdir, --passphrase-dir [Optional] /home/[user]/.config/borg by default
Backups keys are stored (in plain-text) at this location.
Use "export BORG_PASSPHRASE" as shown in the example below to avoid saving passphrase to file.
-h, --help Display this information
NOTE:- You MUST specify BORG_PASSPHRASE by export
$ export BORG_PASSPHRASE=<your-passphrase>
$ sudo $0 --project-name "example.com" --wp-source-dir "/var/www/example.com" --backup-dir "/home/me/backup/example.com" --storage-quota 5G --passphrase-dir /root/borg
USAGE
# If user asked to display this information - exit normally
if [[ ! "$#" -eq 0 ]]; then
exit 0
fi
}
# Everything should be inside a function
# main() would contain the start of the script
main() {
# Explicitly Declare all variables as "local"
local SCRIPT_VERSION
local SCRIPT_NAME
readonly SCRIPT_VERSION=1.0, SCRIPT_NAME=wp_borg_backup
################################# Parse Script Arguments #################################
while [[ "${#}" -gt 0 ]]; do
case $1 in
--project-name | -pname)
shift
shift
;;
-h|--help)
echo
usage OK
echo
exit 0
;;
*)
echo
echo "Unknown parameter encounted : $1 - this will be ignored"
echo
shift
;;
esac
done
# Check if mandatory items were provided or not
# if [[ -z "${project_name}" ]]; then
# echo "ERROR: Script requires a project name (--project-name | -pname) parameter" 2>STDERR
# usage
# exit 6
# fi
################################# Parse Script Arguments #################################
######################################### Set up #########################################
# Set variables that you require for the rest of the operations here
local TS
local LOGFILE
# Create the backup directory structure
readonly TS="$(date '+%d_%m_%Y-%H_%M_%S')"
readonly LOGFILE=/tmp/"${SCRIPT_NAME}"_v"${SCRIPT_VERSION}"_"${TS}".log
touch "${LOGFILE}"
echo "You can find the log at ${LOGFILE}"
######################################### Set up #########################################
################################## Operation 1 ##################################
# Do your stuff here
################################## Operation 1 ##################################
}
# Call the main() here
main "$@"

74
bootstrap.sh Executable file
View File

@@ -0,0 +1,74 @@
#!/usr/bin/env bash
usage() {
if [ -n "$1" ]; then
echo ""
echo -e "${CRED}$1${CEND}\n"
fi
echo "Applies all settings stored in the script's directory to your home directory"
echo ""
echo "Usage: $0 [-q|--quiet] [-l|--create-links]"
echo " -q, --quiet No screen outputs"
echo " -l, --create-links Creates soft-links to files in the current directory instead of copying them"
echo ""
echo "Example: bash ./$0 -q --create-links"
}
##################################
# Parse script arguments
##################################
# defaults
QUIET="n"
CREATE_LINKS="n"
while [[ "${#}" -gt 0 ]]; do
case $1 in
-q|--quiet)
QUIET="y"
shift
;;
-l|--create-links)
CREATE_LINKS="y"
shift
;;
-h|--help)
echo
usage
echo
exit 0
;;
*)
usage "Unknown parameter passed: $1" "h"
exit 1
;;
esac
done
main () {
TS=$(date '+%d_%m_%Y-%H_%M_%S')
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
find . -type f ! -name "$0" ! -path '*/.idea/*' ! -path '*/.git/*' ! -name 'LICENSE' ! -name 'README.md' -print0 | while IFS= read -r -d '' file
do
# Replaces `.` with `~` in the found file names
# target_file="${file/./~}"
target_file="${file/.//media/pratik/Projects/Code/dotfiles-test}"
if [[ -f "${target_file}" ]]
then
mv "$target_file" "${target_file}_${TS}" && [[ "$QUIET" == "n" ]] && echo "Existing setting renamed to ${target_file}_${TS}"
fi
if [[ "$CREATE_LINKS" == "y" ]]; then
ln -s "${file/./${SCRIPT_DIR}}" "${target_file}" && [[ "$QUIET" == "n" ]] && echo "Linked ${target_file}"
else
cp "${file/./${SCRIPT_DIR}}" "${target_file}" && [[ "$QUIET" == "n" ]] && echo "Copied ${target_file}"
fi
done;
}
main "$@"