new layout

This commit is contained in:
Nikolas Weger 2019-11-10 13:11:26 +01:00
parent 005541a96f
commit 1ee7a6234a
17 changed files with 2353 additions and 2 deletions

41
bin/hosts Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Path to your hosts file
hostsFile="/etc/hosts"
# Default IP address for host
ip="127.0.0.1"
# Hostname to add/remove.
hostname="$2"
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; exit 111; }
try() { "$@" || die "cannot $*"; }
remove() {
if [ -n "$(grep -P "[[:space:]]$hostname" /etc/hosts)" ]; then
echo "$hostname found in $hostsFile. Removing now...";
try sudo sed -ie "/[[:space:]]$hostname/d" "$hostsFile";
else
yell "$hostname was not found in $hostsFile";
fi
}
add() {
if [ -n "$(grep -P "[[:space:]]$hostname" /etc/hosts)" ]; then
yell "$hostname, already exists: $(grep $hostname $hostsFile)";
else
echo "Adding $hostname to $hostsFile...";
try printf "%s\t%s\n" "$ip" "$hostname" | sudo tee -a "$hostsFile" > /dev/null;
if [ -n "$(grep $hostname /etc/hosts)" ]; then
echo "$hostname was added succesfully:";
echo "$(grep $hostname /etc/hosts)";
else
die "Failed to add $hostname";
fi
fi
}
$@

21
bin/notify Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/php
<?php
$script = array_shift($_SERVER['argv']);
$settings['token'] = 'ayndqf6fdyjo9pua8reusvvb733k1u';
$settings['user'] = 'uesmxehx2bcuyv5prfrw39ema2312f';
$settings['title'] = array_shift($_SERVER['argv']);
$settings['message'] = array_shift($_SERVER['argv']);
$settings['priority'] = 1;
$curl = curl_init("https://api.pushover.net/1/messages.json");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $settings);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($curl);
curl_close($curl);
$json = json_decode($return, true);
if(isset($json['info'])) echo("Result: ${json['info']}");