commit c754df18c259954ceae873a9d952a99b81bab595 Author: velvettear Date: Wed Aug 28 15:22:02 2024 +0200 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..3023967 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# .dots + +### personal dot files for proxmox based hosts diff --git a/scripts/notify.sh b/scripts/notify.sh new file mode 100755 index 0000000..f3a251c --- /dev/null +++ b/scripts/notify.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +# author: Daniel Sommer +# license: MIT + +# usage: +# notify.sh [options] +# documentation @ https://docs.ntfy.sh/publish + +url="https://notify.velvettear.de" +user="velvettear" +password="\$Velvet90" + +[[ -z "$1" ]] && printf "error: no topic specified\n" 1>&2 && exit 1 +[[ -z "$2" ]] && printf "error: no payload specified\n" 1>&2 && exit 1 + +url="$url/$1" +payload="$2" + +# check if payload is a file +if [[ -e "$payload" ]]; then + args+=("-T" "$(realpath $payload)" "-H" "Filename: $(basename $payload)") +else + args+=("-d" "$payload") +fi + +# check for valid priority level +function checkPriority() { + prio="$(printf "$1" | tr '[:upper:]' '[:lower:]')" + if [[ "$prio" == "min" ]] || [[ "$prio" == "low" ]] || [[ "$prio" == "default" ]] || [[ "$prio" == "high" ]] || [[ "$prio" == "max" ]] || [[ "$prio" == "urgent" ]]; then + args+=("-H" "Priority: $prio") + fi +} + +# check arguments +index=1 +for arg in "$@"; do + ((index++)) + value="${!index}" + case "$arg" in + -e|--emoji|-i|--icon) + args+=("-H" "Tags: $value") + ;; + -p|--priority) + checkPriority "$value" + ;; + -t|--title) + args+=("-H" "Title: $value") + ;; + esac +done + +echo "user: $user" +echo "pw: $password" +echo "url: $url" +echo "args: ${args[@]}" + +curl -u $user:$password "${args[@]}" $url diff --git a/scripts/prepare-fs.sh b/scripts/prepare-fs.sh new file mode 100755 index 0000000..70fa0ee --- /dev/null +++ b/scripts/prepare-fs.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# author: Daniel Sommer +# license: MIT + +# this script is used in a systemd service file (wanted by other services) + +[[ "$EUID" != 0 ]] && printf "error: permission denied!\n" && exit 1 + +printf "preparing filesystem...\n" + +if [[ ! -d "/var/log/pveproxy" ]]; then + printf "creating directory '/var/log/pveproxy' with owner 'www-data'...\n" + mkdir -p /var/log/pveproxy + chown -R www-data:www-data /var/log/pveproxy +fi + +if [[ ! -d "/var/log/nginx" ]]; then + printf "creating directory '/var/log/nginx' with owner 'www-data'...\n" + mkdir -p /var/log/nginx + chown -R www-data:www-data /var/log/nginx +fi + +printf "finished preparing the filesystem!\n" diff --git a/scripts/restic/j5040.sh b/scripts/restic/j5040.sh new file mode 100755 index 0000000..424ddbd --- /dev/null +++ b/scripts/restic/j5040.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# author: Daniel Sommer +# license: MIT + +[[ "$EUID" != 0 ]] && printf "error: permission denied!\n" >&2 && exit 1 + +directories=( + "/etc" +) + +printf ">> starting restic backup...\n" + +for directory in ${directories[@]}; do + seconds="$SECONDS" + printf "> backing up '"$directory"'...\n" + restic backup --verbose --no-scan --retry-lock 3h "$directory" + printf "> backup of '"$directory"' finished after "$(( $SECONDS - $seconds ))" seconds!\n" +done + +printf ">> restic backup finished after "$SECONDS" seconds!\n" diff --git a/scripts/restic/n100.sh b/scripts/restic/n100.sh new file mode 100755 index 0000000..d59ec3e --- /dev/null +++ b/scripts/restic/n100.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# author: Daniel Sommer +# license: MIT + +[[ "$EUID" != 0 ]] && printf "error: permission denied!\n" >&2 && exit 1 + +directories=( + "/etc" + "/mnt/storage/audiobooks" + "/mnt/storage/comics" + "/mnt/storage/documents" + "/mnt/storage/ebooks" + "/mnt/storage/images" + "/mnt/storage/music" + "/mnt/storage/software" + "/mnt/storage/syncthing" + "/mnt/storage/videos" +) + +printf ">> starting restic backup...\n" + +for directory in ${directories[@]}; do + seconds="$SECONDS" + printf "\n> backing up '"$directory"'...\n" + restic backup --verbose --no-scan --retry-lock 3h "$directory" + printf "> backup of '"$directory"' finished after "$(( $SECONDS - $seconds ))" seconds!\n" +done + +printf ">> restic backup finished after "$SECONDS" seconds!\n" diff --git a/scripts/restic/restic.sh b/scripts/restic/restic.sh new file mode 100755 index 0000000..9c2e483 --- /dev/null +++ b/scripts/restic/restic.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# author: Daniel Sommer +# license: MIT + +# exit on error + +# check permissions +[[ "$EUID" != 0 ]] && printf "error: permission denied!\n" >&2 && exit 1 + +# check if script exists +script="$(dirname $(realpath "$0"))/$(hostname).sh" +[[ ! -x "$script" ]] && printf "error: script '"$script"' does not exist or is not executable!\n" >&2 && exit 1 + +# get hostname +host="$(hostname)" +[[ -z "$host" ]] && host="$HOST" + +# setup restic +export RESTIC_REPOSITORY="rest:http://192.168.100.101:8000" +export RESTIC_PASSWORD="\$Velvet90" +export RESTIC_COMPRESSION="max" +export RESTIC_CACHE_DIR="/var/cache/restic" + +# setup log file +log="/var/log/restic-"$(hostname)".log" + +# source / execute restic script +source "$script" 2>&1 | tee "$log" + +# send a notification when finished +/home/velvettear/.dots/scripts/notify.sh "backups" "$log" --title "$host" --icon "green_circle" diff --git a/scripts/update.sh b/scripts/update.sh new file mode 100755 index 0000000..095433c --- /dev/null +++ b/scripts/update.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# author: Daniel Sommer +# license: MIT + +# debian update script + +# exit on ctrl-c +trap 'printf ""$font_colored_bold"\n>> stopping system update after "$SECONDS" seconds..."$font_default"\n" && exit 1' SIGINT + +# font styles & colors +font_default="\e[0m" +font_colored="\e[32;1m" +font_colored_bold="\e[31;1m" + +[[ "$EUID" != "0" ]] && printf ""$font_colored_bold">> error: permission denied!"$font_default"\n" && exit 1 + +for arg in "$@"; do + case "$arg" in + -n|--noconfirm) + noconfirm="true" + ;; + -r|--reboot) + reboot="true" + ;; + esac +done + +printf ""$font_colored_bold">> system update started..."$font_default"\n" + +printf ""$font_colored"> updating packages..."$font_default"\n" +/usr/bin/apt-get update +[[ "$noconfirm" ]] && /usr/bin/apt-get dist-upgrade -y || /usr/bin/apt-get dist-upgrade + +printf ""$font_colored"> cleaning cache..."$font_default"\n" +rm -rf "/var/cache//usr/bin/apt-get/*" +[[ "$noconfirm" ]] && /usr/bin/apt-get clean -y || /usr/bin/apt-get clean + +printf ""$font_colored"> removing orphaned packages..."$font_default"\n" +[[ "$noconfirm" ]] && /usr/bin/apt-get autoremove --purge -y || /usr/bin/apt-get autoremove --purge + +printf ""$font_colored"> removing \"no valid subscription\" message..."$font_default"\n" +sed -i.bak "s/data.status.* !== 'ACTIVE'/false/I" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js + +printf ""$font_colored"> updating restic..."$font_default"\n" +restic self-update + +#printf ""$font_colored"> installing dark theme..."$font_default"\n" +#bash <(curl -s https://raw.githubusercontent.com/Weilbyte/PVEDiscordDark/master/PVEDiscordDark.sh ) install + +printf ""$font_colored_bold">> system updated finished after "$SECONDS" seconds!"$font_default"\n" + +[[ ! "$reboot" ]] && exit 0 + +timeout="5" +printf ""$font_colored"> rebooting system in " +while [[ "$timeout" -gt "0" ]]; do + printf "$timeout... " + timeout="$(( timeout - 1 ))" + sleep 1 +done +printf "now!"$font_default"\n" +systemctl reboot diff --git a/scripts/zfs-scrub.sh b/scripts/zfs-scrub.sh new file mode 100755 index 0000000..94c7520 --- /dev/null +++ b/scripts/zfs-scrub.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# author: Daniel Sommer +# license: MIT + +[[ "$EUID" != 0 ]] && printf "error: permission denied!\n" && exit 1 + +printf "scrubbing all available zfs pools...\n" + +mapfile -t pools < <(zpool list | tail -n +2 | awk '{print $1}') +for pool in "${pools[@]}"; do + timestamp="$SECONDS" + printf "scrubbing zfs pool '"$pool"'...\n" + zpool scrub -w "$pool" + printf "scrubbing zfs pool '"$pool"' finished after $(( $SECONDS - $timestamp )) seconds!\n" +done + +printf "scrubbing all available zfs pools finished after $SECONDS seconds!\n" diff --git a/systemd/prepare-fs.service b/systemd/prepare-fs.service new file mode 100644 index 0000000..0e67e1b --- /dev/null +++ b/systemd/prepare-fs.service @@ -0,0 +1,11 @@ +[Unit] +Description=filesystem preparation +Before=pveproxy.service +Before=nginx.service + +[Service] +Type=oneshot +ExecStart=/etc/velvettear/scripts/prepare-fs.sh + +[Install] +WantedBy=multi-user.target diff --git a/systemd/restic/restic.service b/systemd/restic/restic.service new file mode 100644 index 0000000..8bdb84c --- /dev/null +++ b/systemd/restic/restic.service @@ -0,0 +1,10 @@ +[Unit] +Description=restic backup + +[Service] +Type=oneshot +ExecStart=/home/velvettear/.dots/scripts/restic/restic.sh +ExecStartPost=/home/velvettear/.dots/scripts/notify.sh "backups" "/var/log/restic-%i.log" --title "%i" --icon "green_circle" + +[Install] +WantedBy=multi-user.target diff --git a/systemd/restic/restic.timer b/systemd/restic/restic.timer new file mode 100644 index 0000000..eba639e --- /dev/null +++ b/systemd/restic/restic.timer @@ -0,0 +1,8 @@ +[Unit] +Description=restic backup + +[Timer] +OnCalendar=*-*-* 00:03:00 + +[Install] +WantedBy=timers.target diff --git a/systemd/zfs/zfs-scrub.service b/systemd/zfs/zfs-scrub.service new file mode 100644 index 0000000..8c41ac6 --- /dev/null +++ b/systemd/zfs/zfs-scrub.service @@ -0,0 +1,9 @@ +[Unit] +Description=scrub all available zfs pools + +[Service] +Type=simple +ExecStart=/etc/velvettear/scripts/zfs-scrub.sh + +[Install] +WantedBy=multi-user.target diff --git a/systemd/zfs/zfs-scrub.timer b/systemd/zfs/zfs-scrub.timer new file mode 100644 index 0000000..e3cb11c --- /dev/null +++ b/systemd/zfs/zfs-scrub.timer @@ -0,0 +1,8 @@ +[Unit] +Description=scrub all available zfs pools weekly + +[Timer] +OnCalendar=Sun *-*-* 08:00:00 + +[Install] +WantedBy=timers.target diff --git a/zsh/zprofile b/zsh/zprofile new file mode 100755 index 0000000..a00476f --- /dev/null +++ b/zsh/zprofile @@ -0,0 +1,71 @@ +#!/usr/bin/env zsh + +# author: Daniel Sommer +# license: MIT + +# export environment variables + +# set .dots directory +export VELVETTEAR_DOTS="$HOME/.dots" + +# set prompt +export PROMPT="%(!.%F{red}.)%n@%m > %/%(!.#.$) %f" + +# set general variables +export USER="$(whoami)" +export HOST="$(hostname)" +export HOSTNAME="$HOST" +export TMP="/tmp" +export TEMP="/tmp" +export TMPDIR="/tmp" + +# set nvim as default editor +export EDITOR="nvim" +export VISUAL="nvim" +export PAGER="less" + +# configure the shell history +export HISTFILE="$HOME/.zhistory" +export SAVEHIST="100" +export HISTSIZE="10000" +export HISTTIMEFORMAT="%d.%m.%Y %H:%M:%S" +export HISTCONTROL="ignoredups" + +# set all kinds of aliases + +# file and directory listings +alias ls="ls --color=auto" +alias la="ls -a --color=auto" +alias ll="ls -l --color=auto" +alias lla="ls -la --color=auto" + +# grep +alias grep="grep --color=auto" +alias fgrep="fgrep --color=auto" +alias egrep="egrep --color=auto" + +# diff +alias diff="diff --color=auto" + +# tar +alias tarp="tar -I pigz -cf -v" +alias untarp="tar -I pigz -xf" + +# general +alias ..="cd .." +alias whereami="realpath ." +alias c="clear" + +# create / delete / copy / move +alias rmr="rm -r" +alias rmrf="rm -rf" +alias cpr="cp -R" +alias cprf="cp -Rf" +alias mkdirp="mkdir -p" + +# applications +alias vi="nvim" +alias vim="nvim" + +# scripts +alias update="sudo $VELVETTEAR_DOTS/scripts/update.sh" diff --git a/zsh/zshrc b/zsh/zshrc new file mode 100755 index 0000000..dceccae --- /dev/null +++ b/zsh/zshrc @@ -0,0 +1,8 @@ +#!/usr/bin/env zsh + +# author: Daniel Sommer +# license: MIT + +# exit if user is not root +[[ "$EUID" != "0" ]] && return +echo "LOGIN AS ROOT"