commit e4934af0ca949f7c96004f84d0732bde863f0def Author: Jessa Date: Sat Jun 1 10:31:32 2024 -0700 Big Bang diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..855fdcd --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2024 jessa0 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/dc.sh b/dc.sh new file mode 100644 index 0000000..0476df8 --- /dev/null +++ b/dc.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +. /usr/share/bash-completion/completions/docker + +_dc() { + ((COMP_CWORD+=3)) + COMP_WORDS=( docker compose -f /etc/docker/docker-compose.yml "${COMP_WORDS[@]:1}" ) + _docker + return 0 +} + +alias dc="sudo docker compose -f /etc/docker/docker-compose.yml" + +complete -F _dc dc diff --git a/ez.sh b/ez.sh new file mode 100644 index 0000000..b3e8c99 --- /dev/null +++ b/ez.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +ez() { + zone="$1" + file="/etc/bind/dyn/$zone.zone" + + if [ -z "$zone" ]; then + echo "Usage: edit_zone zone" 2>&1 + return 1 + elif [ ! -e "$file" ]; then + echo "zone $zone doesnt exist!" 2>&1 + return 1 + fi + dynamic=0 + if rndc zonestatus "$zone" | grep -q "dynamic: yes"; then + dynamic=1 + rndc sync -clean "$zone" || return $? + rndc freeze "$zone" || return $? + echo "zone $zone frozen" 2>&1 + fi + sudoedit "$file" + if [ $dynamic = 1 ]; then + rndc thaw "$zone" || return $? + fi +} + +_ez() { + if [[ "$COMP_CWORD" -eq 1 ]]; then + COMPREPLY=($(cd "/etc/bind/dyn/*.zone" && compgen -f "${COMP_WORDS[1]}")) + fi +} + +complete -F _ez ez diff --git a/site.sh b/site.sh new file mode 100644 index 0000000..cf4411b --- /dev/null +++ b/site.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +site() { + command="$1" + site="$2" + file="/etc/nginx/sites-available/$site" + link="/etc/nginx/sites-enabled/$site" + + if [ -z "$site" ]; then + echo "Usage: site name" 2>&1 + return 1 + fi + + case "$command" in + create) sudo touch "$file"; return;; + esac + + if [ ! -e "$file" ]; then + echo "Site $site doesnt exist!" 2>&1 + return 1 + fi + + case "$command" in + delete) sudo rm "$file" "$link";; + edit) sudoedit "$file";; + copy) sudo cp "$file" "/etc/nginx/sites-available/$3";; + enable) + if [ ! -e "$link" ]; then + sudo ln -s "../sites-available/$site" "$link" + fi;; + disable) + if [ -e "$link" ]; then + sudo rm "$link" + fi;; + *) + echo "Unknown command $command" 2>&1 + return 1;; + esac +} + +_site() { + if [[ "$COMP_CWORD" -eq 1 ]]; then + COMPREPLY=($(compgen -W "create edit delete copy enable disable" -- "${COMP_WORDS[1]}")) + elif [[ "$COMP_CWORD" -eq 2 ]]; then + case "${COMP_WORDS[1]}" in + edit|enable|delete|copy) dir=sites-available;; + disable) dir=sites-enabled;; + *) return;; + esac + COMPREPLY=($(cd "/etc/nginx/$dir/" && compgen -f "${COMP_WORDS[2]}")) + fi +} + +complete -F _site site