Bryan Roessler il y a 2 ans
Parent
commit
c0cb99330d
8 fichiers modifiés avec 0 ajouts et 307 suppressions
  1. 0 29
      extract
  2. 0 74
      installpkg
  3. 0 79
      prunefiles
  4. 0 29
      random-word-pair
  5. 0 43
      share-link
  6. 0 31
      speedtest-compare
  7. 0 3
      strip-exif
  8. 0 19
      update-git-hooks

+ 0 - 29
extract

@@ -1,29 +0,0 @@
-#!/usr/bin/env bash
-# This script/function will unzip most filetypes automatically
-
-extract () {
-	if [ -f "$1" ] ; then
-		case "$1" in
-		*.tar.bz2) tar xjf "$1" ;;
-		*.tar.gz) tar xzf "$1" ;;
-		*.bz2) bunzip2 "$1" ;;
-		*.rar) unrar e "$1" ;;
-		*.gz) gunzip "$1" ;;
-		*.tar) tar xf "$1" ;;
-		*.tbz2) tar xjf "$1" ;;
-		*.tgz) tar xzf "$1" ;;
-		*.zip) unzip "$1" ;;
-		*.Z) uncompress "$1" ;;
-		*.7z) 7z x "$1" ;;
-		*) echo "$1 cannot be extracted via extract()" ;;
-		esac
-	else
-		echo "$1 is not a valid file"
-	fi
-}
-
-# Allow script to be safely sourced
-if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
-    extract "$@"
-    exit $?
-fi

+ 0 - 74
installpkg

@@ -1,74 +0,0 @@
-#!/usr/bin/env bash
-# Identify host OS and execute package manager install command on input args
-#
-
-installpkg() {
-
-	getOS() {
-
-		# Widely supported method to retrieve host $ID
-		if [[ -e /etc/os-release ]]; then
-		    source /etc/os-release
-		else
-		    echo "No /etc/os-release found!"
-		    echo "Your OS is unsupported!"
-		    return 1
-		fi
-	}
-
-
-	setCmdArr () {
-
-		declare -ga CMD_ARR
-
-		# Create OS-specific package install command arrays
-		if [[ "$ID" == "fedora" ]]; then
-			CMD_ARR=( "dnf" "install" "-y" )
-		elif [[ "$ID" == "centos" && "$VERSION_ID" -ge 8 ]]; then
-			CMD_ARR=( "dnf" "install" "-y" )
-		elif [[ "$ID" == "centos" && "$VERSION_ID" -le 7 ]]; then
-			CMD_ARR=( "yum" "install" "-y" )
-		elif [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
-			CMD_ARR=( "apt-get" "install" "-y" )
-		elif [[ "$ID" == "arch" ]]; then
-			CMD_ARR=( "pacman" "-Syu" )
-		else
-			echo "Your OS is currently unsupported! You are welcome to add your own and submit a PR."
-			return 1
-		fi
-
-		# Append sudo if not running as root
-		[[ "$(whoami)" != "root" ]] && CMD_ARR=( "sudo" "${CMD_ARR[@]}" )
-	}
-
-
-	installPackage() {
-
-		# Check for input arguments
-		if [[ "$#" -ge 1 ]]; then
-			if ! "${CMD_ARR[@]}" "$@"; then
-				echo "Installation failed!"
-				return 1
-			fi
-		else
-			echo "You must supply one or more packages to install!"
-			return 1
-		fi
-	}
-
-
-	main() {
-
-		getOS && \
-		setCmdArr && \
-		installPackage "$@" && \
-        unset CMD_ARR
-	}
-
-	main "$@"
-}
-
-if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
-	installpkg "$@"
-	exit $?
-fi

+ 0 - 79
prunefiles

@@ -1,79 +0,0 @@
-#!/usr/bin/env bash
-# prunefiles, a script/function to remove all but the n latest versions of a file
-#
-
-prunefiles () {
-
-    declare -ag PREFIXES
-    declare -g KEEP_INT=1 # default # of files to keep
-
-    printHelpAndExit () {
-
-    cat <<-'EOF'
-		USAGE:
-		    pruneFiles -k 3 thisfileprefix [thatfileprefix]
-
-		OPTIONS
-		    -k, --keep NUMBER
-		        Keep NUMBER of latest files that matches each file prefix (Default: 1)
-		    -h, --help
-		        Print this help dialog and exit
-	EOF
-
-    # Exit using passed exit code
-    [[ -z $1 ]] && exit 0 || exit "$1"
-
-    }
-
-    parseInput () {
-
-        if _input=$(getopt -o +hk: -l help,keep: -- "$@"); then
-            eval set -- "$_input"
-            while true; do
-                case "$1" in
-                    -k|--keep)
-                        shift && KEEP_INT=$1
-                        ;;
-                    -h|--help)
-                        printHelpAndExit 0
-                        ;;
-                    --)
-                        shift; break
-                        ;;
-                esac
-                shift
-            done
-        else
-            echo "Incorrect option(s) provided"
-            printHelpAndExit 1
-        fi
-
-        PREFIXES=( "$@" )
-    }
-
-
-    findAndRemove () {
-
-        declare prefix file
-
-        for prefix in "${PREFIXES[@]}"; do
-            for file in $(find . -maxdepth 1 -type f -name "${prefix}*" -printf '%T@ %p\n' | sort -r -z -n | tail -n+$((KEEP_INT + 1)) | awk '{ print $2; }'); do
-                rm "$file"
-            done
-        done
-    }
-
-
-    main () {
-        parseInput "$@"
-        findAndRemove
-    }
-
-    main "$@"
-}
-
-# Allow script to be safely sourced
-if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
-    prunefiles "$@"
-    exit $?
-fi

+ 0 - 29
random-word-pair

@@ -1,29 +0,0 @@
-#!/usr/bin/env bash
-# This script will create a random word pair with an underscore ex. turtle_ladder
-
-random_word_pair() {
-    # Constants 
-    local random_words num_random_words random_1 random_2 word_1 word_2
-    random_words=/usr/share/dict/words
-    # total number of non-random words available 
-    num_random_words=$(wc -l $random_words | cut -d" " -f 1)
-    # Get two random integers
-    random_1=$(shuf -i 1-"$num_random_words" -n 1)
-    random_2=$(shuf -i 1-"$num_random_words" -n 1)
-    # Get the nth word
-    word_1=$(sed "${random_1}q;d" "$random_words")
-    word_2=$(sed "${random_2}q;d" "$random_words")
-    # Sanitize words
-    word_1="${word_1,,}"
-    word_1="${word_1//-/}"
-    word_2="${word_2,,}"
-    word_2="${word_2//-/}"
-    echo "${word_1,,}_${word_2,,}"
-    return 0
-}
-
-# Allow this file to be executed directly if not being sourced
-if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
-    random_word_pair
-    exit $?
-fi

+ 0 - 43
share-link

@@ -1,43 +0,0 @@
-#!/usr/bin/env bash
-# Nautilus script for creating one or more shared links
-# Requires wl-clipboard and notify-send 
-
-ssh_server="bryanroessler.com"
-ssh_files_path="/var/www/repos.bryanroessler.com/files"
-www_files_path="https://repos.bryanroessler.com/files"
-
-if [[ "$#" -lt 1 ]]; then
-	echo "You must provide at least one argument"
-	exit 1
-fi
-
-hash wl-copy &>/dev/null || echo "Please install wl-copy (usually in the wl-clipboard package)"
-
-if [[ -v NAUTILUS_SCRIPT_SELECTED_URIS ]]; then
-	readarray -t files <<< "$NAUTILUS_SCRIPT_SELECTED_URIS"
-	files=("${files[@]#file://}")
-	files=("${files[@]//\%20/ }")
-else
-	files=("$@")
-fi
-
-for file in "${files[@]}"; do
-	[[ "$file" == "" ]] && continue
-	echo here
-    fname="${file##*/}"
-    random64=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 64 | head -n 1)
-	echo "rsync -a ${file} ${ssh_server}:${ssh_files_path}/${random64}/"
-	nohup rsync -a "${file}" "${ssh_server}:${ssh_files_path}/${random64}/" &
-	links_array+=("$www_files_path/${random64}/${fname// /%20}")
-done
-
-if [[ "${#links_array[@]}" == 1 ]]; then
-	printf '%s' "${links_array[@]}" | wl-copy
-else
-	printf '%s\n' "${links_array[@]}" | wl-copy
-fi
-
-hash notify-send &>/dev/null &&
-	notify-send -t 3000 -i face-smile "share-link" "File(s) uploaded and link copied to clipboard"
-
-exit 0

+ 0 - 31
speedtest-compare

@@ -1,31 +0,0 @@
-#!/usr/bin/env bash
-# This script will perform speedtests over wireguard and the
-# native connections and print their output
-#
-
-_speedTestData() {
-
-	local pingbps ping_f bps_f bps_int
-	export ping_int mbps_int
-
-	pingbps=$(speedtest-cli --no-upload --csv "$@" | cut -d"," -f7-8)
-	ping_f="${pingbps%,*}" # grab first value
-	ping_int="${ping_f%.*}" # make integer
-	bps_f="${pingbps#*,}" # grab second value
-	bps_int="${bps_f%.*}" # make integer
-	mbps_int=$((bps_int / 1000000)) # convert to mbps
-}
-
-# Test Wireguard using automatic server selection
-if _speedTestData; then
-	echo "Wireguard:"
-	echo -e "\tPing: $ping_int"
-	echo -e "\tMbps: $mbps_int"
-fi
-
-# Test native connection to ISP
-if _speedTestData --server 17170; then
-	echo "Native:"
-	echo -e "\tPing: $ping_int"
-	echo -e "\tMbps: $mbps_int"
-fi

+ 0 - 3
strip-exif

@@ -1,3 +0,0 @@
-#!/usr/bin/env bash
-
-exiftool -all= "$@"

+ 0 - 19
update-git-hooks

@@ -1,19 +0,0 @@
-#!/usr/bin/env bash
-# This script will update the post-receive hooks of multiple bare git repos
-#
-
-for i in /var/lib/git/gogs-repositories/bryan/*/hooks/post-receive; do
-
-    # Get repo name
-    rn="${i%/hooks/post-receive}"
-    rn="${rn##*/}"
-
-    # Don't duplicate the line if it already exists
-    while IFS= read -r line; do
-        [[ "$line" == "git push --mirror git@github.com:cryobry/${rn}" ]] && continue
-    done < "$i"
-
-    # Append the line
-    #echo "git push --mirror git@github.com:cryobry/${rn} to $i"
-    echo "git push --mirror git@github.com:cryobry/${rn}" >> "$i"
-done