parent
109959d263
commit
db8786a981
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Autor: Nils Gerstner
|
||||||
|
|
||||||
|
URL="https://hooks.slack.com/services/TOKENKEY"
|
||||||
|
username="$1"
|
||||||
|
message=$2
|
||||||
|
ICON=":ghost:"
|
||||||
|
|
||||||
|
payload="{
|
||||||
|
\"username\": \"${username}\",
|
||||||
|
\"text\": \"$message\",
|
||||||
|
\"icon_emoji\": \"${ICON}\"
|
||||||
|
}"
|
||||||
|
|
||||||
|
curl -X POST -H "Content-Type: application/json" -d "${payload}" $URL
|
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
myip="$(dig +short myip.opendns.com @resolver1.opendns.com)"
|
||||||
|
#echo "My public IP address is: ${myip}"
|
||||||
|
echo "${myip}"
|
@ -0,0 +1,97 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Author: Nils Gerstner
|
||||||
|
# Last revision: 15 nov 2022 18:00
|
||||||
|
# Version: v0.1
|
||||||
|
# Description:
|
||||||
|
|
||||||
|
#=== VARIABLES ================================================================#
|
||||||
|
|
||||||
|
declare -r SCRIPT_NAME=$(basename "$BASH_SOURCE" .sh)
|
||||||
|
declare -r HELP_MSG="Usage: $SCRIPT_NAME [OPTION]... [ARG]...
|
||||||
|
-h display this help and exit
|
||||||
|
"
|
||||||
|
|
||||||
|
#=== FUNCTIONS ================================================================#
|
||||||
|
|
||||||
|
## Print colored messages
|
||||||
|
_cmsg() {
|
||||||
|
case "$1" in
|
||||||
|
black) COLOR="\033[0;30m" ;;
|
||||||
|
white) COLOR="\033[1;37m" ;;
|
||||||
|
grey) COLOR="\033[1;30m" ;;
|
||||||
|
lgrey) COLOR="\033[0;37m" ;;
|
||||||
|
red) COLOR="\033[0;31m" ;;
|
||||||
|
lred) COLOR="\033[1;31m" ;;
|
||||||
|
green) COLOR="\033[0;32m" ;;
|
||||||
|
lgreen) COLOR="\033[1;32m" ;;
|
||||||
|
brown) COLOR="\033[0;33m" ;;
|
||||||
|
yelow) COLOR="\033[1;33m" ;;
|
||||||
|
blue) COLOR="\033[0;34m" ;;
|
||||||
|
lblue) COLOR="\033[1;34m" ;;
|
||||||
|
purple) COLOR="\033[0;35m" ;;
|
||||||
|
lpurple) COLOR="\033[1;35m" ;;
|
||||||
|
cyan) COLOR="\033[0;36m" ;;
|
||||||
|
lcyan) COLOR="\033[1;36m" ;;
|
||||||
|
nocolor) COLOR="\033[0m" ;;
|
||||||
|
esac
|
||||||
|
printf "${COLOR}${2}\33[0m\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
## exit the shell(default status code: 1) after printing the message to stderr
|
||||||
|
_bail() {
|
||||||
|
echo -ne "$1" >&2
|
||||||
|
exit ${2-1}
|
||||||
|
}
|
||||||
|
|
||||||
|
## print the usage and exit the shell(default status code: 2)
|
||||||
|
_usage() {
|
||||||
|
local status=2
|
||||||
|
if [[ "$1" =~ ^[0-9]+$ ]]; then
|
||||||
|
status=$1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
_bail "${1}$HELP_MSG" $status
|
||||||
|
}
|
||||||
|
|
||||||
|
_failure() {
|
||||||
|
local lineno=$1
|
||||||
|
local msg=$2
|
||||||
|
echo "Failed at $lineno: $msg"
|
||||||
|
}
|
||||||
|
|
||||||
|
#=== SET ENVIRONMENT AND EXIT CONDITIONS ======================================#
|
||||||
|
|
||||||
|
# -e Exit immediately on error
|
||||||
|
# -E ERR trap is inherited by shell functions
|
||||||
|
set -eE -o functrace
|
||||||
|
|
||||||
|
trap '_failure ${LINENO} "$BASH_COMMAND"' ERR
|
||||||
|
|
||||||
|
#=== HANDLE ARGUMENTS =========================================================#
|
||||||
|
|
||||||
|
while getopts ":hie:" opt; do
|
||||||
|
case $opt in
|
||||||
|
i)
|
||||||
|
# Do something
|
||||||
|
#(for ex. execute a function or set a switch variable)
|
||||||
|
;;
|
||||||
|
e)
|
||||||
|
# Option with argument
|
||||||
|
e_argument=${OPTARG}
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
_usage 0
|
||||||
|
;;
|
||||||
|
\?)
|
||||||
|
_usage "Invalid option: -$OPTARG \n"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
shift $OPTIND
|
||||||
|
[[ "$#" -lt 1 ]] && usage "Too few arguments\n"
|
||||||
|
|
||||||
|
#=== MAIN CODE BELOW ==========================================================#
|
||||||
|
|
||||||
|
echo "Start!"
|
||||||
|
|
@ -0,0 +1,44 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
# Author: Nils Gerstner
|
||||||
|
# Last revision: 30. December 2018
|
||||||
|
# Version: v1
|
||||||
|
# Description:
|
||||||
|
|
||||||
|
function _linux() {
|
||||||
|
# Put your Linux related code here
|
||||||
|
}
|
||||||
|
|
||||||
|
function _mac() {
|
||||||
|
# Put your Mac related code here
|
||||||
|
}
|
||||||
|
|
||||||
|
function _cmsg {
|
||||||
|
# Print colored messages
|
||||||
|
# _cmsg color "message"
|
||||||
|
case "$1" in
|
||||||
|
black) COLOR="\033[0;30m" ;;
|
||||||
|
white) COLOR="\033[1;37m" ;;
|
||||||
|
grey) COLOR="\033[1;30m" ;;
|
||||||
|
lgrey) COLOR="\033[0;37m" ;;
|
||||||
|
red) COLOR="\033[0;31m" ;;
|
||||||
|
lred) COLOR="\033[1;31m" ;;
|
||||||
|
green) COLOR="\033[0;32m" ;;
|
||||||
|
lgreen) COLOR="\033[1;32m" ;;
|
||||||
|
brown) COLOR="\033[0;33m" ;;
|
||||||
|
yelow) COLOR="\033[1;33m" ;;
|
||||||
|
blue) COLOR="\033[0;34m" ;;
|
||||||
|
lblue) COLOR="\033[1;34m" ;;
|
||||||
|
purple) COLOR="\033[0;35m" ;;
|
||||||
|
lpurple) COLOR="\033[1;35m" ;;
|
||||||
|
cyan) COLOR="\033[0;36m" ;;
|
||||||
|
lcyan) COLOR="\033[1;36m" ;;
|
||||||
|
nocolor) COLOR="\033[0m" ;;
|
||||||
|
esac
|
||||||
|
printf "${COLOR}${2}\33[0m\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Linux*) _linux ;;
|
||||||
|
Darwin*) _mac ;;
|
||||||
|
*) _cmsg -red "Unknown System\nDo nothing!"
|
||||||
|
esac
|
Loading…
Reference in new issue