Created
August 13, 2019 21:13
-
-
Save sandalsoft/abc6cc7cdecbde101a5b9b73bd5f77bf to your computer and use it in GitHub Desktop.
pi bash functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fixssh() { | |
sed -i '' "$1d" $HOME/.ssh/known_hosts | |
} | |
# set container debug port in package.json | |
function set.container.debug.port () { | |
echo "Setting container port" | |
$BIN/container_debug_port_script package.json | |
print.packagejson.path scripts\[\'ctr:start\'\] | |
file.fetch $TSCONFIG_GIST "./tsconfig.json" | |
} | |
# function remove.npm.modules () { | |
# echo "Removing $1" | |
# npm rm $1 | |
# } | |
# Dependencies: | |
# - curl | |
# - python | |
function GetASN() { | |
local _ip="$1" | |
local _curl_base="curl --request GET" | |
local _timeout="15" | |
_asn=$($_curl_base -ks -m "$_timeout" "http://ip-api.com/json/${_ip}" | \ | |
python -c 'import sys, json; print json.load(sys.stdin)["as"]' 2>/dev/null) | |
_state=$(echo $?) | |
if [[ -z "$_ip" ]] || [[ "$_ip" == "null" ]] || [[ "$_state" -ne 0 ]]; then | |
echo -en "Unsuccessful ASN gathering.\\n" | |
else | |
echo -en "$_ip > $_asn\\n" | |
fi | |
} | |
# Dependencies: | |
# - curl | |
# - jq | |
function DomainResolve() { | |
local _host="$1" | |
local _curl_base="curl --request GET" | |
local _timeout="15" | |
_host_ip=$($_curl_base -ks -m "$_timeout" "https://dns.google.com/resolve?name=${_host}&type=A" | \ | |
jq '.Answer[0].data' | tr -d "\"" 2>/dev/null) | |
if [[ -z "$_host_ip" ]] || [[ "$_host_ip" == "null" ]] ; then | |
echo -en "Unsuccessful domain name resolution.\\n" | |
else | |
echo -en "$_host > $_host_ip\\n" | |
fi | |
} | |
function isConnectedToVPN() { | |
export VPN=`scutil --nc list | grep -v current | grep Connected | awk '{print $7}'` | |
if [[ ! -z "${VPN// }" ]]; then | |
echo true | |
else | |
echo false | |
fi | |
unset VPN | |
} | |
function vpnStatus() { | |
export VPN=`scutil --nc list | grep -v current | grep Connected | awk '{print $7}'` | |
if [[ ! -z "${VPN// }" ]]; then | |
echo "Connected to $VPN" | |
else | |
echo "Not connected to VPN" | |
fi | |
unset VPN | |
} | |
function mac_dot_to_colon() { | |
echo $1 | sed 's!\.!!g;s!\(..\)!\1:!g;s!:$!!' | |
} | |
function mac_colon_to_dot() { | |
echo $1 | sed -e 's/\(..\):\(..\)/\1\2/g' | tr ':[:upper:]' '.[:lower:]' | |
} | |
function mac_colon_to_dash() { | |
echo $1 | sed -e 's/:/-/g' | |
} | |
function get_volumes_from_yaml () { | |
# use ./docker-compose.yml if it exists | |
if [ -f ./docker-compose.yml ]; then | |
# echo "Found docker-compose.yml" | |
INPUT=docker-compose.yml | |
fi | |
# use argv1 if supplied | |
if [ $# -eq 1 ]; then | |
INPUT=$1 | |
# echo "using $1 as input file" | |
fi | |
# echo "Using $INPUT as input file." | |
cat $INPUT | yq .services | jq -c "$JQ_EXPR_UNIQUE_DOCKER_COMPOSE_RELATIVE_PATH_VOLUMES" | |
} | |
function extract_volume_dirs () { | |
get_volumes_from_yaml | tr -d ./ | xargs -n 1 bash -c 'echo ./volumes/$0' | |
} | |
function parse_docker_hub_url () { | |
if [ $# -ne 1 ]; then | |
echo "No URL supplied" | |
exit 1 | |
fi | |
DOCKER_HUB_URL=$1 | |
if [[ $DOCKER_HUB_URL != *"hub.docker.com"* ]]; then | |
echo "Not a hub.docker.com URL" | |
exit 1 | |
fi | |
echo $DOCKER_HUB_URL | grep -o '\w/\w\+[^?]\+' | tail -c+2 | cut -d/ -f3,4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment