Compare commits
7 Commits
7a7cbb4980
...
9d6c642019
Author | SHA1 | Date |
---|---|---|
david | 9d6c642019 | |
david | 99539d54aa | |
david | da1bb6472f | |
david | 949f57115c | |
david | 95d3f92607 | |
david | b3e12fa198 | |
david | 98ee8363ae |
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2022 david@socialnerds.org
|
||||
Copyright (c) 2023 david@socialnerds.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
51
README.md
51
README.md
|
@ -2,9 +2,19 @@
|
|||
|
||||
My personal collection of handy scripts. mostly bash.
|
||||
|
||||
- [restic_backup.sh](#restic_backup.sh)
|
||||
- [restic-backup.sh](#restic-backup.sh)
|
||||
- [restic-repos.sh](#restic-repos.sh)
|
||||
- [btrfs-snapshots.sh](#btrfs-snapshots.sh)
|
||||
- [odroid-fancontrol.sh](#odroid-fancontrol.sh)
|
||||
|
||||
## restic_backup.sh
|
||||
More:
|
||||
- [lib.sh](#lib.sh)
|
||||
- [template.sh](#template.sh)
|
||||
|
||||
|
||||
---
|
||||
|
||||
## restic-backup.sh
|
||||
|
||||
> This script is my very simple take on how to perform restic backups.
|
||||
|
||||
|
@ -23,7 +33,7 @@ In the config section at the top of the script you can change various options to
|
|||
PASSWORD="/root/.restic-password"
|
||||
REPO="sftp:<remote-server>:/path/to/repository"
|
||||
KEEP=30
|
||||
BIN="/usr/bin/restic"
|
||||
BIN="/usr/bin/restic"
|
||||
OPTIONS="-p $PASSWORD -r $REPO -q"
|
||||
```
|
||||
|
||||
|
@ -48,3 +58,38 @@ or using cron.
|
|||
```
|
||||
|
||||
Happy backuping! :-)
|
||||
|
||||
## restic-repos.sh
|
||||
|
||||
## btrfs-snapshots.sh
|
||||
|
||||
## odroid-fancontrol.sh
|
||||
|
||||
## lib.sh
|
||||
|
||||
## template.sh
|
||||
|
||||
Use this as a base for new scripts, it already has the essentials.
|
||||
```sh
|
||||
# Load lib.sh
|
||||
SCRIPT_LIB="lib.sh"
|
||||
SCRIPT_PATH=$(readlink -f "$0")
|
||||
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
|
||||
if [[ -r "$SCRIPT_DIR/$SCRIPT_LIB" ]]; then
|
||||
source "$SCRIPT_DIR/$SCRIPT_LIB"
|
||||
lib_print "Loading version $LIB_GREEN_BOLD$LIB_VERSION$LIB_CLEAR of $LIB_GREEN_BOLD$LIB_NAME$LIB_CLEAR"
|
||||
else
|
||||
echo "Error: Cannot load library file [$SCRIPT_DIR/$SCRIPT_LIB]"
|
||||
exit 1
|
||||
fi
|
||||
```
|
||||
|
||||
-----
|
||||
|
||||
## watch-containers.sh
|
||||
|
||||
Simple healthchecks script to monitor running containers.
|
||||
|
||||
## switch-desktop.sh
|
||||
|
||||
I think this is only useful with ElementaryOS. I use(d) this with a hot corner to control desktops with the mouse.
|
||||
|
|
|
@ -2,6 +2,13 @@
|
|||
|
||||
# this will take read-only btrfs snapshots and make it available in /srv/snapshots
|
||||
|
||||
# Information
|
||||
NAME="btrfs-snapshots.sh"
|
||||
VERSION="0.2.0"
|
||||
AUTHOR="david@socialnerds.org"
|
||||
LICENSE="MIT"
|
||||
DESCRIPTION="$NAME (v$VERSION) takes snapshots of BTRFS volumes. It is written by $AUTHOR and published unter the $LICENSE license."
|
||||
|
||||
# variables
|
||||
SUBVOLUMES="/"
|
||||
DESTINATION_ROOT=/srv/snapshots
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
S=${IFS}
|
||||
IFS=.
|
||||
for P in $1; do
|
||||
TLD=${P}
|
||||
done
|
||||
IFS=${S}
|
||||
|
||||
echo "TLD: ${TLD}"
|
||||
DNSLIST=$(dig +short ${TLD}. NS)
|
||||
for DNS in ${DNSLIST}; do
|
||||
echo "Checking ${DNS}"
|
||||
dig +norec +nocomments +noquestion +nostats +nocmd @${DNS} $1 NS
|
||||
done
|
|
@ -3,7 +3,7 @@
|
|||
# simple script to clone a virtual machine (vmware)
|
||||
# to another datastore/folder.
|
||||
|
||||
# usage: ./clone_vm.sh <source path> <destination path>
|
||||
# usage: ./clone-vm.sh <source path> <destination path>
|
||||
# source path must be a directory and contain a virtual machine (at least a single .vmdk file)
|
||||
# destination path must a directory, preexist and be empty (to avoid overwriting another machine)
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
# This file is meant to be sourced by another script,
|
||||
# it contains only BASH functions and global variables.
|
||||
|
||||
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
## ##
|
||||
## lib.sh ##
|
||||
## ##
|
||||
## Library for my personal BASH scripts ##
|
||||
## ##
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
|
||||
|
||||
##
|
||||
## Information
|
||||
##
|
||||
|
||||
LIB_NAME="lib.sh"
|
||||
LIB_DESCRIPTION="Library for my personal BASH scripts"
|
||||
LIB_VERSION="0.1.0"
|
||||
LIB_AUTHOR="david@socialnerds.org"
|
||||
LIB_LICENSE="MIT"
|
||||
LIB_WEBSITE="https://git.socialnerds.org/david/scripts"
|
||||
|
||||
|
||||
##
|
||||
## Variables
|
||||
##
|
||||
|
||||
# Reset text formatting
|
||||
LIB_CLEAR="\e[0m"
|
||||
|
||||
# Text settings
|
||||
LIB_BOLD="\e[1m"
|
||||
LIB_UNDERLINE="\e[4m"
|
||||
|
||||
# Text color
|
||||
LIB_RED="\e[31m"
|
||||
LIB_GREEN="\e[32m"
|
||||
LIB_YELLOW="\e[33m"
|
||||
LIB_BLUE="\e[34m"
|
||||
LIB_MAGENTA="\e[35m"
|
||||
LIB_CYAN="\e[36m"
|
||||
LIB_LIGHTGREY="\e[37m"
|
||||
|
||||
# Text color with bold font
|
||||
LIB_RED_BOLD="\e[1;31m"
|
||||
LIB_GREEN_BOLD="\e[1;32m"
|
||||
LIB_YELLOW_BOLD="\e[1;33m"
|
||||
LIB_BLUE_BOLD="\e[1;34m"
|
||||
LIB_MAGENTA_BOLD="\e[1;35m"
|
||||
LIB_CYAN_BOLD="\e[1;36m"
|
||||
LIB_LIGHTGREY_BOLD="\e[1;37m"
|
||||
|
||||
# Background color
|
||||
LIB_RED_BG="\e[41m"
|
||||
LIB_GREEN_BG="\e[42m"
|
||||
LIB_YELLOW_BG="\e[43m"
|
||||
LIB_BLUE_BG="\e[44m"
|
||||
LIB_MAGENTA_BG="\e[45m"
|
||||
LIB_CYAN_BG="\e[46m"
|
||||
LIB_LIGHTGREY_BG="\e[47m"
|
||||
|
||||
# Background color with bold font
|
||||
LIB_RED_BG_BOLD="\e[1;41m"
|
||||
LIB_GREEN_BG_BOLD="\e[1;42m"
|
||||
LIB_YELLOW_BG_BOLD="\e[1;43m"
|
||||
LIB_BLUE_BG_BOLD="\e[1;44m"
|
||||
LIB_MAGENTA_BG_BOLD="\e[1;45m"
|
||||
LIB_CYAN_BG_BOLD="\e[1;46m"
|
||||
LIB_LIGHTGREY_BG_BOLD="\e[1;47m"
|
||||
|
||||
|
||||
##
|
||||
## Functions
|
||||
##
|
||||
|
||||
# Print text message
|
||||
function lib_print() {
|
||||
local LIB_Q=${Q:-0}
|
||||
local LIB_V=${V:-0}
|
||||
if [[ "$1" =~ ^\! ]]; then
|
||||
printf "$LIB_RED_BG_BOLD%b$LIB_CLEAR\n" "${1#\!}"
|
||||
elif [[ "$1" =~ ^\? ]]; then
|
||||
if [ $LIB_V -eq 1 ] && [ $LIB_Q -ne 1 ]; then
|
||||
printf "$LIB_LIGHTGREY%b$LIB_CLEAR\n" "${1#\?}"
|
||||
fi
|
||||
elif [[ $LIB_Q -ne 1 ]]; then
|
||||
printf "%b\n" "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Print script information
|
||||
# including the last 5 changelog entries
|
||||
function lib_print_info() {
|
||||
printf "%12s %b\n%12s %s\n%12s %s\n%12s %s\n%12s %s\n%12s %s\n\n%12s %s\n" \
|
||||
"Name:" "$LIB_BOLD$NAME$LIB_CLEAR" "Version:" "$VERSION" \
|
||||
"Author:" "$AUTHOR" "License:" "$LICENSE" "Web:" "$WEBSITE" \
|
||||
"Description:" "$DESCRIPTION" "Changelog:" "${CHANGELOG[0]}"
|
||||
for i in "${CHANGELOG[@]:1:4}"; do
|
||||
printf "%12s %s\n" "" "$i"
|
||||
done
|
||||
}
|
||||
|
||||
# Print version information
|
||||
function lib_print_version() {
|
||||
printf "%s\n" "$VERSION"
|
||||
}
|
||||
|
||||
# Check for privileges
|
||||
# Returns 0 if the current user is root and 1 if not
|
||||
function lib_amiroot() {
|
||||
if [[ $(whoami) != "root" ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check for command availability
|
||||
# Takes one or a list of space seperated commands. Returns a list of missing commands.
|
||||
function lib_missing_commands() {
|
||||
local MISSING_COMMANDS=""
|
||||
for COMMAND in $@; do
|
||||
if ! $(command -v $COMMAND &>/dev/null); then
|
||||
MISSING_COMMANDS="$MISSING_COMMANDS $COMMAND"
|
||||
fi
|
||||
done
|
||||
echo "${MISSING_COMMANDS# }"
|
||||
}
|
||||
|
||||
# Generate a random alphanumeric string
|
||||
# Optional: Supply length as intager. Default is 16.
|
||||
function lib_gen_string() {
|
||||
LC_ALL=C tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c ${1:-16}; echo
|
||||
}
|
|
@ -1,16 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Odroid HC4 fan control script
|
||||
# My Odroid fan control script
|
||||
# (only tested with an Odroid HC4 running Manjaro)
|
||||
#
|
||||
|
||||
# Information (don't touch unless you're me)
|
||||
NAME="odroid-fancontrol.sh"
|
||||
AUTHOR="david@socialnerds.org"
|
||||
VERSION="0.2.1"
|
||||
LICENSE="GPLv3"
|
||||
LICENSE="MIT"
|
||||
DESCRIPTION="$NAME (v$VERSION) controls the fan speed in an Odroid HC4 (and possibly others) based on temperature. It is written by $AUTHOR and published under the $LICENSE license."
|
||||
|
||||
# Configuration
|
||||
THRESHOLD=46000
|
||||
THRESHOLD=50000
|
||||
DISTANCE=1000
|
||||
INTERVAL=30
|
||||
STEPS=(120 160 210 255)
|
|
@ -0,0 +1,227 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
## ##
|
||||
## restic-backup.sh ##
|
||||
## ##
|
||||
## Simple script to help setup and run ##
|
||||
## periodic Restic backup jobs ##
|
||||
## ##
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
|
||||
|
||||
##
|
||||
## Information
|
||||
##
|
||||
|
||||
NAME="restic-backup.sh"
|
||||
VERSION="0.2.0"
|
||||
AUTHOR="david@socialnerds.org"
|
||||
LICENSE="MIT"
|
||||
DESCRIPTION="A simple script to help setup and run periodic Restic backup jobs."
|
||||
WEBSITE="https://git.socialnerds.org/david/scripts"
|
||||
CHANGELOG=("[2023-10-26][v0.2.0] Complete rewrite"
|
||||
"[2022-01-01][v0.1.0] Initial version")
|
||||
|
||||
##
|
||||
## Configuration
|
||||
##
|
||||
|
||||
EXECUTABLE="$(basename $0)"
|
||||
LIBRARIES="lib.sh"
|
||||
DEPENDENCIES="basename dirname readlink tr head chmod curl restic"
|
||||
REQUIRE_ROOT=0
|
||||
|
||||
# Files
|
||||
PASSWORD="$HOME/.restic-password"
|
||||
REPOSITORY="$HOME/.restic-repository"
|
||||
HEALTHCHECKS="$HOME/.restic-healthchecks"
|
||||
|
||||
# Build the Restic command
|
||||
RESTIC_BINARY="$(command -v restic)"
|
||||
RESTIC_OPTIONS="-q"
|
||||
RESTIC_COMMAND="$RESTIC_BINARY --password-file $PASSWORD --repository-file $REPOSITORY $RESTIC_OPTIONS"
|
||||
|
||||
# How many snapshots should be kept?
|
||||
SNAPSHOTS=32
|
||||
|
||||
|
||||
##
|
||||
## Functions
|
||||
##
|
||||
|
||||
# Print help information
|
||||
function print_help() {
|
||||
printf "%s\n\n%s\n%b\n\n%s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n" \
|
||||
"$DESCRIPTION" "Usage:" "$LIB_BOLD$EXECUTABLE <options> <path or Restic keyword>$LIB_CLEAR" "Options:" \
|
||||
"-c, --checks" "Enable Healthchecks" \
|
||||
"-h, --help" "Print help screen and exit" \
|
||||
"-i, --info" "Print script information and exit" \
|
||||
"-v, --verbose" "More verbose output" \
|
||||
"-q, --quiet" "No output except errors (overrides -v)"
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
## Preflight
|
||||
##
|
||||
|
||||
# Load BASH libraries
|
||||
SCRIPT_PATH=$(readlink -f "$0")
|
||||
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
|
||||
for LIBRARY in $LIBRARIES; do
|
||||
if [[ -r "$SCRIPT_DIR/$LIBRARY" ]]; then
|
||||
#echo "Loading library file [$SCRIPT_DIR/$LIBRARY]"
|
||||
source "$SCRIPT_DIR/$LIBRARY"
|
||||
else
|
||||
echo "Error: Cannot load library file [$SCRIPT_DIR/$LIBRARY]"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Check for root privileges
|
||||
if ! lib_amiroot && [[ $REQUIRE_ROOT -eq 1 ]]; then
|
||||
lib_print "!You need to have root privileges"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for dependencies
|
||||
MISSING_COMMANDS=$(lib_missing_commands $DEPENDENCIES)
|
||||
if [ -n "$MISSING_COMMANDS" ]; then
|
||||
lib_print "!One or more commands missing [$MISSING_COMMANDS]"
|
||||
lib_print "Try installing them with your package manager"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
##
|
||||
## Liftoff
|
||||
##
|
||||
|
||||
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
|
||||
case $1 in
|
||||
-c|--checks)
|
||||
C=1
|
||||
;;
|
||||
-h|--help)
|
||||
H=1
|
||||
;;
|
||||
-i|--info)
|
||||
I=1
|
||||
;;
|
||||
-v|--verbose)
|
||||
V=1
|
||||
;;
|
||||
-q|--quiet)
|
||||
Q=1
|
||||
;;
|
||||
*)
|
||||
lib_print "!Unknown option [$1]"
|
||||
lib_print "Try --help or -h for available options"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ "$1" == '--' ]]; then
|
||||
shift
|
||||
fi
|
||||
|
||||
if [[ $I -eq 1 ]]; then
|
||||
lib_print_info
|
||||
exit 0
|
||||
elif [[ $H -eq 1 ]]; then
|
||||
print_help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
print_help
|
||||
exit 0
|
||||
else
|
||||
# Generate a new password file if it is missing or empty
|
||||
if [[ ! -s $PASSWORD ]]; then
|
||||
lib_gen_string 32 > $PASSWORD
|
||||
chmod 600 $PASSWORD
|
||||
lib_print "New password file generated since it did not exist or was empty [$PASSWORD]"
|
||||
fi
|
||||
|
||||
# Generate a new repo file if it is missing or empty
|
||||
if [[ ! -s $REPOSITORY ]]; then
|
||||
echo -n "Repository URL: "; read -r INPUT
|
||||
echo $INPUT > $REPOSITORY
|
||||
chmod 600 $REPOSITORY
|
||||
lib_print "New repository file generated since it did not exist or was empty [$REPOSITORY]"
|
||||
fi
|
||||
|
||||
# Generate a new healthchecks file if it is missing or empty
|
||||
if [[ ! -s $HEALTHCHECKS ]] && [[ $C -eq 1 ]]; then
|
||||
echo -n "Healthchecks URL: "; read -r INPUT
|
||||
if [[ -n "$INPUT" ]]; then
|
||||
echo "$INPUT" > $HEALTHCHECKS
|
||||
chmod 600 $HEALTHCHECKS
|
||||
lib_print "New healthchecks file generated [$HEALTHCHECKS]"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Initialize a new repo if the URL has no config file
|
||||
if ! $($RESTIC_COMMAND snapshots >/dev/null 2>&1); then
|
||||
if ! $($RESTIC_COMMAND init >/dev/null 2>&1); then
|
||||
lib_print "!A problem occured while initializing a new repository"
|
||||
exit 1
|
||||
fi
|
||||
lib_print "New repository initialized"
|
||||
fi
|
||||
|
||||
# Run the Restic repository check
|
||||
if ! $($RESTIC_COMMAND check >/dev/null 2>&1); then
|
||||
lib_print "!Repository check failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$1" =~ ^/ && -r "$1" ]]; then
|
||||
# Signal Healthchecks start if enabled
|
||||
if [[ "$C" -eq 1 ]]; then
|
||||
HEALTHCHECKS_URL=$(cat $HEALTHCHECKS)
|
||||
curl -fsS -m 10 --retry 5 -o /dev/null $HEALTHCHECKS_URL/start
|
||||
fi
|
||||
# Run the actual backup
|
||||
if ! $($RESTIC_COMMAND backup --one-file-system ${@:2} "$1" >/dev/null 2>&1); then
|
||||
lib_print "!Something went wrong while running backup [$1]"
|
||||
# Signal Healthchecks fail if enabled
|
||||
if [[ "$C" -eq 1 ]]; then
|
||||
curl -fsS -m 10 --retry 5 -o /dev/null $HEALTHCHECKS_URL/fail >/dev/null 2>&1
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
# Delete old snapshots
|
||||
if ! $($RESTIC_COMMAND forget --keep-last $SNAPSHOTS --path "$1" --prune >/dev/null 2>&1); then
|
||||
lib_print "!Something went wrong while deleting old snapshots [$1]"
|
||||
# Signal Healthchecks fail if enabled
|
||||
if [[ "$C" -eq 1 ]]; then
|
||||
curl -fsS -m 10 --retry 5 -o /dev/null $HEALTHCHECKS_URL/fail >/dev/null 2>&1
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
# Signal Healthchecks success if enabled
|
||||
if [[ "$C" -eq 1 ]]; then
|
||||
curl -fsS -m 10 --retry 5 -o /dev/null $HEALTHCHECKS_URL >/dev/null 2>&1
|
||||
fi
|
||||
elif [[ "$1" =~ ^(backup|cache|cat|check|copy|diff|dump|find|forget|generate|help|init|key|list|ls|migrate|mount|prune|recover|repair|restore|rewrite|snapshots|stats|tag|unlock|version)$ ]]; then
|
||||
# Wrapper mode
|
||||
$RESTIC_COMMAND $@
|
||||
else
|
||||
lib_print "!The given path must be absolute and readable [$1]"
|
||||
lib_print "Or you can try a Restic keyword directly for wrapper mode"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
##
|
||||
## Here be dragons
|
||||
##
|
||||
|
||||
exit 0
|
|
@ -1,17 +1,23 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
#
|
||||
# Repository/user management script for Restics's REST server"
|
||||
#
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
## ##
|
||||
## restic-repos.sh ##
|
||||
## ##
|
||||
## Repository/user management script for ##
|
||||
## Restic's REST server ##
|
||||
## ##
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
|
||||
|
||||
# Information
|
||||
RR_NAME="rest-repos.sh"
|
||||
RR_DESCRIPTION="Repository/user management script for Restic's REST server"
|
||||
RR_VERSION="0.1.0"
|
||||
RR_AUTHOR="david@socialnerds.org"
|
||||
RR_LICENSE="GPLv3"
|
||||
NAME="rest-repos.sh"
|
||||
DESCRIPTION="Repository/user management script for Restic's REST server"
|
||||
VERSION="0.1.0"
|
||||
AUTHOR="david@socialnerds.org"
|
||||
LICENSE="MIT"
|
||||
WEBSITE="https://git.socialnerds.org/david/scripts"
|
||||
|
||||
|
||||
# Configuration
|
||||
|
@ -29,42 +35,8 @@ RR_DEPS="htpasswd tr head systemctl find awk sed sort"
|
|||
|
||||
# Text formatting
|
||||
CLEAR="\e[0m"
|
||||
|
||||
# Text settings.
|
||||
BOLD="\e[1m"
|
||||
UNDERLINE="\e[4m"
|
||||
|
||||
# Text color.
|
||||
RED="\e[31m"
|
||||
GREEN="\e[32m"
|
||||
YELLOW="\e[33m"
|
||||
BLUE="\e[34m"
|
||||
MAGENTA="\e[35m"
|
||||
CYAN="\e[36m"
|
||||
|
||||
# Text color with bold font.
|
||||
RED_BOLD="\e[1;31m"
|
||||
GREEN_BOLD="\e[1;32m"
|
||||
YELLOW_BOLD="\e[1;33m"
|
||||
BLUE_BOLD="\e[1;34m"
|
||||
MAGENTA_BOLD="\e[1;35m"
|
||||
CYAN_BOLD="\e[1;36m"
|
||||
|
||||
# Background color.
|
||||
RED_BG="\e[41m"
|
||||
GREEN_BG="\e[42m"
|
||||
YELLOW_BG="\e[43m"
|
||||
BLUE_BG="\e[44m"
|
||||
MAGENTA_BG="\e[45m"
|
||||
CYAN_BG="\e[46m"
|
||||
|
||||
# Background color with bold font.
|
||||
RED_BG_BOLD="\e[1;41m"
|
||||
GREEN_BG_BOLD="\e[1;42m"
|
||||
YELLOW_BG_BOLD="\e[1;43m"
|
||||
BLUE_BG_BOLD="\e[1;44m"
|
||||
MAGENTA_BG_BOLD="\e[1;45m"
|
||||
CYAN_BG_BOLD="\e[1;46m"
|
||||
|
||||
|
||||
# Functions
|
||||
|
@ -81,7 +53,7 @@ function rr_output() {
|
|||
|
||||
function rr_help() {
|
||||
# Print help information
|
||||
rr_output "$RR_DESCRIPTION\n\nUsage:\n$RR_NAME <options> <repo>\n\nOptions:
|
||||
rr_output "$DESCRIPTION\n\nUsage:\n$NAME <options> <repo>\n\nOptions:
|
||||
-l, --list\t\tList repositories
|
||||
-r, --remove\t\tRemove repository
|
||||
-h, --help\t\tHelp screen
|
||||
|
@ -92,7 +64,7 @@ function rr_help() {
|
|||
|
||||
function rr_version() {
|
||||
# Print version information
|
||||
rr_output "Version: $BOLD$RR_VERSION$CLEAR\nAuthor: $RR_AUTHOR\nLicense: $RR_LICENSE"
|
||||
rr_output "Version: $BOLD$VERSION$CLEAR\nAuthor: $AUTHOR\nLicense: $LICENSE"
|
||||
exit 0
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# name: restic_backup.sh
|
||||
# version: 0.1
|
||||
# author: david@socialnerds.org
|
||||
# license: MIT
|
||||
# description: a simple script to automate the restic backup utility.
|
||||
# i created this for my personal use, though you are very
|
||||
# welcome to reuse and improve.
|
||||
|
||||
|
||||
# **** CONFIG ****
|
||||
PASSWORD="/root/.restic-password"
|
||||
REPO="sftp:remote-server.tld:/path/to/repository"
|
||||
KEEP=30
|
||||
BIN="/usr/bin/restic"
|
||||
OPTIONS="-q"
|
||||
|
||||
|
||||
# **** START ****
|
||||
CMD="$BIN -p $PASSWORD -r $REPO $OPTIONS"
|
||||
|
||||
#TODO: check for elevated privileges
|
||||
|
||||
# Generate a new password file if it is missing or empty
|
||||
if [ ! -s $PASSWORD ]; then
|
||||
#echo "error: Password file is empty or does not exist. [$PASSWORD]"
|
||||
#exit 1
|
||||
tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1 > $PASSWORD
|
||||
chmod 600 $PASSWORD
|
||||
echo "warning: New password file generated since it does not exist or is empty. [$PASSWORD]"
|
||||
fi
|
||||
|
||||
# Initialize a new repo if the repo url has no config file
|
||||
$CMD snapshots >/dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
$CMD init >/dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "error: A problem occured while creating a new repository. [$REPO]"
|
||||
exit 1
|
||||
fi
|
||||
echo "warning: New repository initialized. [$REPO]"
|
||||
fi
|
||||
|
||||
# Run the restic repository check
|
||||
$CMD check > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "error: Repository check failed. [$REPO]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# First option must be a readable folder/file
|
||||
if [ $1 ]; then
|
||||
if [ -r $1 ]; then
|
||||
LOCAL=$1
|
||||
else
|
||||
echo "error: The path given does not seem to be readable. [$1]"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "error: Local path must be given as an option."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run the actual backup
|
||||
$CMD backup ${@:2} $LOCAL > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "error: Something went wrong while running backup. [$LOCAL]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Delete old snapshots
|
||||
$CMD forget --keep-last $KEEP --path $LOCAL --prune > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "error: Something went wrong while deleting old snapshots. [$LOCAL]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# **** END ****
|
||||
exit 0
|
|
@ -6,7 +6,7 @@
|
|||
# description: switch to next, previous, specific desktop.
|
||||
# you can also toggle between first and second desktop.
|
||||
#
|
||||
# usage: ./switch_desktop.sh next|prev|<int>|toggle
|
||||
# usage: ./switch-desktop.sh next|prev|<int>|toggle
|
||||
|
||||
num=$(wmctrl -d | grep "*" | awk '{print $1}')
|
||||
lockfile="/tmp/switch_desktop.lock"
|
||||
|
@ -42,4 +42,3 @@ if [ ! -f $lockfile ]; then
|
|||
echo "cleaning up lockfile [$lockfile]"
|
||||
rm $lockfile
|
||||
fi
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
## ##
|
||||
## template.sh ##
|
||||
## ##
|
||||
## Template for creating BASH scripts ##
|
||||
## ##
|
||||
## ## ## ## ## ## ## ## ## ## ## ## ## ##
|
||||
|
||||
|
||||
##
|
||||
## Information
|
||||
## (don't touch unless you are me)
|
||||
##
|
||||
|
||||
NAME="template.sh"
|
||||
DESCRIPTION="Template for creating BASH scripts"
|
||||
VERSION="0.1.1"
|
||||
AUTHOR="david@socialnerds.org"
|
||||
LICENSE="MIT"
|
||||
WEBSITE="https://git.socialnerds.org/david/scripts"
|
||||
CHANGELOG=("[2023-10-26][v0.1.1] Everything is a work in progress"
|
||||
"[2023-10-25][v0.1.0] Initial version")
|
||||
|
||||
|
||||
##
|
||||
## Configuration
|
||||
##
|
||||
|
||||
EXECUTABLE="$(basename $0)"
|
||||
LIBRARIES="lib.sh"
|
||||
DEPENDENCIES="sed awk jq"
|
||||
REQUIRE_ROOT=0
|
||||
|
||||
|
||||
##
|
||||
## Functions
|
||||
##
|
||||
|
||||
# Print help information
|
||||
function print_help() {
|
||||
printf "%s\n\n%s\n%b\n\n%s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n" \
|
||||
"$DESCRIPTION" "Usage:" "$LIB_BOLD$EXECUTABLE <options>$LIB_CLEAR" "Options:" \
|
||||
"-h, --help" "Print help screen and exit" \
|
||||
"-i, --info" "Print script information and exit" \
|
||||
"-v, --verbose" "More verbose output" \
|
||||
"-q, --quiet" "No output except errors (overrides -v)"
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
## Preflight
|
||||
##
|
||||
|
||||
# Load BASH libraries
|
||||
SCRIPT_PATH=$(readlink -f "$0")
|
||||
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
|
||||
for LIBRARY in $LIBRARIES; do
|
||||
if [[ -r "$SCRIPT_DIR/$LIBRARY" ]]; then
|
||||
#echo "Loading library file [$SCRIPT_DIR/$LIBRARY]"
|
||||
source "$SCRIPT_DIR/$LIBRARY"
|
||||
else
|
||||
echo "Error: Cannot load library file [$SCRIPT_DIR/$LIBRARY]"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Check for root privileges
|
||||
if ! lib_amiroot && [[ $REQUIRE_ROOT -eq 1 ]]; then
|
||||
lib_print "!You need to have root privileges"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for dependencies
|
||||
MISSING_COMMANDS=$(lib_missing_commands $DEPENDENCIES)
|
||||
if [[ -n "$MISSING_COMMANDS" ]]; then
|
||||
lib_print "!One or more commands missing [$MISSING_COMMANDS]"
|
||||
lib_print "Try installing them with your package manager"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
##
|
||||
## Liftoff
|
||||
##
|
||||
|
||||
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
H=1
|
||||
;;
|
||||
-i|--info)
|
||||
I=1
|
||||
;;
|
||||
-v|--verbose)
|
||||
V=1
|
||||
;;
|
||||
-q|--quiet)
|
||||
Q=1
|
||||
;;
|
||||
*)
|
||||
lib_print "!Unknown option [$1]"
|
||||
lib_print "Try --help or -h for available options"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ "$1" == '--' ]]; then
|
||||
shift
|
||||
fi
|
||||
|
||||
if [[ $I -eq 1 ]]; then
|
||||
lib_print_info
|
||||
exit 0
|
||||
elif [[ $H -eq 1 ]]; then
|
||||
print_help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
print_help
|
||||
exit 0
|
||||
else
|
||||
lib_print "Supplied option: $1"
|
||||
lib_print "!super error"
|
||||
lib_print "?super test"
|
||||
lib_print "$(lib_gen_string 64)"
|
||||
fi
|
||||
|
||||
|
||||
##
|
||||
## Here be dragons
|
||||
##
|
||||
|
||||
exit 0
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
# **** function definitions ****
|
||||
function usage {
|
||||
echo "usage: ./watch_containers.sh <number> <optional-healthchecks-url>"
|
||||
echo "usage: ./watch-containers.sh <number> <optional-healthchecks-url>"
|
||||
}
|
||||
|
||||
function get_container_count {
|
||||
|
@ -87,4 +87,3 @@ fi
|
|||
|
||||
# **** end ****
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue