1
0
Fork 0

Remove no longer required scripts

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-08-04 18:57:57 +02:00
parent b0904dabb6
commit a1b6dfec4c
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
7 changed files with 0 additions and 264 deletions

View file

@ -1,23 +0,0 @@
#!/usr/bin/env python
import json, subprocess, os, re, HTMLParser
exportcmd = 'plutil -convert json -o - %s' % os.path.expanduser('~/Library/Preferences/widget-com.apple.widget.stickies.plist')
out = json.loads(subprocess.check_output(exportcmd.split(' ')))
stickies = []
htmlparser = HTMLParser.HTMLParser()
for key in out.keys():
if not '-data' in key:
continue
html = out[key]
text = re.sub('\n+', '\n', '\n'.join(re.split(r'<[^>]*div>', html))).strip()
text = '\n'.join(re.split(r'<br[^>]*>\n?', text))
lines = text.split('\n')
lines = map((lambda parm: htmlparser.unescape(parm).strip()), lines)
text = '\n'.join(lines).strip()
stickies.append(text)
print '\n\n=====\n\n'.join(stickies)

View file

@ -1,104 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright:
# 2017 Knut Ahlers <github.com/Luzifer>
# License:
# Apache v2.0
# https://www.apache.org/licenses/LICENSE-2.0.html
from __future__ import print_function
# included
import json
import os
import sys
import time
# external requirement
import requests
SOURCE_FILE = 'https://ec2instances.info/instances.json'
CACHE_TIME = 7 * 24 * 3600
CACHE_FILE = os.path.expanduser('~/.local/share/itc/instances.json')
REGION_FALLBACK = 'eu-west-1'
def beautify_ecu(ecu):
if ecu == 'variable':
return 'var'
return str(ecu).strip('.0')
def beautify_mem(mem):
return str(mem).strip('.0')
def get_region():
if 'AWS_REGION' in os.environ:
return os.environ['AWS_REGION']
if 'AWS_DEFAULT_REGION' in os.environ:
return os.environ['AWS_DEFAULT_REGION']
return REGION_FALLBACK
def monthly_pricing(hourly_rate):
price = float(hourly_rate) * 24 * 365 / 12
return round(price)
def renew_cache():
least_mod_time = time.time() - CACHE_TIME
if os.path.isfile(CACHE_FILE) and os.path.getmtime(CACHE_FILE) > least_mod_time:
return
try:
os.makedirs(os.path.dirname(CACHE_FILE))
except OSError:
# Creating an existing directory will fail which is okay
pass
with open(CACHE_FILE, 'w') as cf:
cf.write(requests.get(SOURCE_FILE).text)
return
def generate_comment(instance_type):
renew_cache()
region = get_region()
instances = json.loads(open(CACHE_FILE, 'r').read())
for instance in instances:
if instance['instance_type'] != instance_type:
continue
if region not in instance['pricing']:
print('Region "{}" is unknown in pricing table.'.format(region))
return None
return '{vcpu} ({ecu}) / {mem} / {network} / ${price:.0f}'.format(
vcpu=instance['vCPU'],
ecu=beautify_ecu(instance['ECU']),
mem=beautify_mem(instance['memory']),
network=instance['network_performance'],
price=monthly_pricing(
instance['pricing'][region]['linux']['ondemand']),
)
def main(args):
comment = generate_comment(args[1])
if comment is None:
return 1
print(' InstanceTypeComment: {}'.format(comment))
return 0
if __name__ == '__main__':
if len(sys.argv) < 2:
print(
'Please supply an instance type to format: e.g. {} m4.large'.format(sys.argv[0]))
sys.exit(1)
sys.exit(main(sys.argv))

View file

@ -1,47 +0,0 @@
#!/usr/bin/env python2
import os, sys, argparse, boto.ec2
def main():
parser = argparse.ArgumentParser(description='Searches instance IP and connects via SSH')
parser.add_argument('-p', type=int, default=22, metavar='port', help='Port to connect to (default 22)')
parser.add_argument('-u', type=str, default=None, metavar='user', help='User to use for connection (default current username)')
parser.add_argument('instance_id', type=str, help='ID of the instance in format "i-XXXXX"')
args = parser.parse_args()
if None in [os.getenv('EC2_REGION'), os.getenv('AWS_ACCESS_KEY_ID'), os.getenv('AWS_SECRET_ACCESS_KEY')]:
print 'Please provide these environment variables: EC2_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY'
sys.exit(1)
if os.getenv('EC2_REGION') not in [r.name for r in boto.ec2.regions()]:
print 'Region "{}" derived from environment variable EC2_REGION is not a valid region.'.format(os.getenv('EC2_REGION'))
sys.exit(1)
ec2_connection = boto.ec2.connect_to_region(os.getenv('EC2_REGION'),
aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'),
aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY'))
instances = ec2_connection.get_only_instances([args.instance_id])
if len(instances) != 1:
print 'Did not found a single instance for ID {}'.format(args.instance_id)
sys.exit(1)
instance = instances[0]
if instance.private_ip_address is not None:
_call_ssh(instance.private_ip_address, args.u, args.p)
else:
_call_ssh(instance.ip_address, args.u, args.p)
def _call_ssh(ip, user=None, port=None):
args = ['/usr/bin/ssh']
if port is not None:
args.append('-p {}'.format(port))
if user is not None:
args.append('{}@{}'.format(user, ip))
else:
args.append('{}'.format(ip))
os.execv('/usr/bin/ssh', args)
if __name__ == '__main__':
main()

View file

@ -1,5 +0,0 @@
#!/bin/bash
LEN=${1:-72}
pbpaste | fold -sw $LEN | pbcopy

View file

@ -1,39 +0,0 @@
#!/bin/bash
if ! (which vault >/dev/null); then
error "vault is required."
exit 2
fi
# If we can list the environments there is no need to unlock the database
if (awsenv list >/dev/null 2>&1); then
echo "Database already unlocked."
exit 0
fi
# Retrieve key from LastPass
PWD=$(vault read -field=passphrase "/secret/private/awsenv")
# In case Vault exitted non-zero we have no password
if ! [ $? -eq 0 ]; then
echo "Unable to get password. Not trying to unlock."
exit 1
fi
# Fill password to ssh-add utility
expect <<EOF >/dev/null
spawn -ignore HUP awsenv unlock
expect "Password: "
send "$PWD\n"
expect "Database unlocked."
expect eof
EOF
# Check whether awsenv was unlocked
if (awsenv list >/dev/null 2>&1); then
echo "Database unlocked successfully"
exit 0
else
echo "Found passphrase but could not unlock database."
exit 1
fi

View file

@ -1,14 +0,0 @@
#!/bin/bash
set -euxo pipefail
RESULTS_DIR=${RESULTS_DIR:-$(pwd)}
# If the binary is not yet there, do an initialization
[ -f ${HOME}/.bin/vuls ] || ${HOME}/bin/vuls-refresh
[ $(( $(date +%s) - $(stat -c %Y ${HOME}/.cache/vuls/oval.sqlite3) )) -gt 86400 ] && ${HOME}/bin/vuls-refresh
# spawn reporter
exec ${HOME}/.bin/vuls report \
--cvedb-path ${HOME}/.cache/vuls/cve.sqlite3 \
--ovaldb-path ${HOME}/.cache/vuls/oval.sqlite3 \
--results-dir "${RESULTS_DIR}" "$@"

View file

@ -1,32 +0,0 @@
#!/bin/bash
set -euxo pipefail
CACHE_DIR="${HOME}/.cache/vuls"
# Fetch VND database
if [ -f "${CACHE_DIR}/cve.sqlite3" ]; then
# Database exists, only update
docker run --rm -it \
-v "${CACHE_DIR}:/vuls" \
vuls/go-cve-dictionary fetchnvd -last2y
else
# Database does not exist, do a full-fetch
docker run --rm -it \
-v "${CACHE_DIR}:/vuls" \
vuls/go-cve-dictionary fetchnvd -years $(seq 2002 $(date +%Y))
fi
# Fetch OVAL for common systems
docker run --rm -it \
-v "${CACHE_DIR}:/vuls" \
vuls/goval-dictionary fetch-alpine $(seq 3.3 0.1 3.7)
docker run --rm -it \
-v "${CACHE_DIR}:/vuls" \
vuls/goval-dictionary fetch-ubuntu $(seq 12 2 18)
# Ensure vuls binary
curl -sSfL https://github.com/future-architect/vuls/releases/download/v0.4.2/vuls_0.4.2_linux_amd64.tar.gz |
tar -C ${HOME}/.bin -xz vuls