From 2bda08fd2f80d90e9e9f4f7846f1a0a149395d2a Mon Sep 17 00:00:00 2001 From: Ethan Paul <24588726+enpaul@users.noreply.github.com> Date: Fri, 4 Dec 2020 14:49:52 -0500 Subject: [PATCH] Add resources directory with baseline common file/templates --- resources/bash/aliases-workstation.sh | 4 ++ resources/bash/aliases.sh | 12 +++++ resources/bash/global.sh | 7 +++ resources/bash/helpers.sh | 18 +++++++ resources/bash/pyenv.sh | 76 +++++++++++++++++++++++++++ resources/motd.j2 | 7 +++ resources/networkd/netdev.j2 | 9 ++++ resources/networkd/network.j2 | 27 ++++++++++ 8 files changed, 160 insertions(+) create mode 100644 resources/bash/aliases-workstation.sh create mode 100644 resources/bash/aliases.sh create mode 100644 resources/bash/global.sh create mode 100644 resources/bash/helpers.sh create mode 100644 resources/bash/pyenv.sh create mode 100644 resources/motd.j2 create mode 100644 resources/networkd/netdev.j2 create mode 100644 resources/networkd/network.j2 diff --git a/resources/bash/aliases-workstation.sh b/resources/bash/aliases-workstation.sh new file mode 100644 index 0000000..e1e7d4e --- /dev/null +++ b/resources/bash/aliases-workstation.sh @@ -0,0 +1,4 @@ +alias doc='cd ~/Documents' +alias dn='cd ~/Downloads' +alias gg='cd ~/Git' +alias explorer='nautilus' diff --git a/resources/bash/aliases.sh b/resources/bash/aliases.sh new file mode 100644 index 0000000..a9dd27a --- /dev/null +++ b/resources/bash/aliases.sh @@ -0,0 +1,12 @@ +alias bk='cd -' +alias fuck='sudo $(history -p \!\!)' +alias ls='ls -lshF --color --group-directories-first --time-style=long-iso' +alias version='uname -orp && lsb_release -a | grep Description' +alias activate='source ./bin/activate' +alias cls='clear' +alias ls='/usr/bin/ls -lshF --color --group-directories-first --time-style=long-iso' +alias gmtime='/usr/bin/date -u --iso-8601=seconds' +alias date='/usr/bin/date --iso-8601=seconds' +alias whatismyip='curl https://icanhazip.com/' +alias uuid="python3 -c 'import uuid; print(uuid.uuid4());'" +alias epoch="python3 -c 'import time; print(time.time());'" diff --git a/resources/bash/global.sh b/resources/bash/global.sh new file mode 100644 index 0000000..942434a --- /dev/null +++ b/resources/bash/global.sh @@ -0,0 +1,7 @@ +function _parse_git_branch() { + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' +} + +export PS1="\[\e[0;97m\]\[\e[37m\e[1m\]\u\[\e[1;94m\]@\[\e[94m\]\H\[\e[0;33m\]\$(_parse_git_branch) \[\e[37m\]\w\[\e[33m\] \[\e[0;97m\]$\[\e[0m\] " +export rc=/home/$USERNAME/.bashrc +export VIRTUALENV_DIR=/home/$USERNAME/.venvs diff --git a/resources/bash/helpers.sh b/resources/bash/helpers.sh new file mode 100644 index 0000000..4bcd4ac --- /dev/null +++ b/resources/bash/helpers.sh @@ -0,0 +1,18 @@ +random() { + if [[ $# -eq 0 ]]; then + num=32 + else + num=$1 + fi + cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $num | head -n 1 +} + +function up() { cd $(eval printf '../'%.0s {1..$1}); } + +function pipin() { pip freeze | grep $1; } + +function passhash() { + read -sp 'Password: ' tmppass; + echo $tmppass | python3 -c 'import crypt; print(crypt.crypt(input(), crypt.mksalt(crypt.METHOD_SHA512)));'; + unset tmppass; +} diff --git a/resources/bash/pyenv.sh b/resources/bash/pyenv.sh new file mode 100644 index 0000000..e53bafb --- /dev/null +++ b/resources/bash/pyenv.sh @@ -0,0 +1,76 @@ +#!/env/bash + +function pyenv () { + usage="Custom Python virtualenv manager +sivenv [list, delete, load, new] [VENV] +Commands: + list List existing virtualenvs (alias: 'ls') + load VENV Activate the virtualenv named VENV (alias: 'source') + new VENV [VERSION] Create and load a new virtualenv named VENV. Optionally VERSION + can be a python version to use for creating the venv. Note that + only python3 versions are supported. + delete VENV Delete the virtualenv named VENV (alias: 'rm')"; + + if [ $# -eq 0 ]; then + echo "Error: no command specified" >&2; + echo "$usage"; + return 1; + fi; + + case $1 in + "-h"| "--help") + echo "$usage"; + return 0;; + "ls"| "list") + lsvenv "$VIRTUALENV_DIR";; + "rm"| "delete") + if [ $# -ne 2 ]; then + echo "Error: no virtualenv specified" >&2; + return 1; + fi; + rm --recursive --force "${VIRTUALENV_DIR:?}/$2";; + "source" | "load") + if [ $# -ne 2 ]; then + echo "Error: no virtualenv specified" >&2; + return 1; + fi; + # shellcheck source=/dev/null + source "$VIRTUALENV_DIR/$2/bin/activate";; + "new") + if [ $# -lt 2 ]; then + echo "Error: no virtualenv specified" >&2; + return 1; + fi; + if [ $# -eq 3 ]; then + version="$3"; + else + version="3"; + fi + if ! command -v "python$version" &>/dev/null; then + echo "Error: no interpreter found for python version '$version'" >&2; + return 2; + fi + + if python$version -m venv "$VIRTUALENV_DIR/$2"; then + echo "New virtualenv '$2' created using $(command -v python$version)" >&2; + # shellcheck source=/dev/null + source "$VIRTUALENV_DIR/$2/bin/activate" + else + return $?; + fi;; + *) + echo "Error: unknown command '$1'" >&2; + echo "$usage"; + return 1;; + esac +} + +function lsvenv () { + venvs=() + for item in /usr/bin/ls -d "$1"/*/; do + if stat "${item}/bin/activate" &>/dev/null; then + venvs+=("$(basename "$item")"); + fi + done + echo "${venvs[*]}" +} diff --git a/resources/motd.j2 b/resources/motd.j2 new file mode 100644 index 0000000..4fdc8aa --- /dev/null +++ b/resources/motd.j2 @@ -0,0 +1,7 @@ + + //////////// //// //// /////////// + //// ////// //// //// //// + //////// //// /// //// /////////// + //// //// ////// //// + //////////// //// //// {{ omni_description | default('Omni Network System') }} + _______________________________{{ omni_description | default('Omni Network System') | length * '\\' }}\ diff --git a/resources/networkd/netdev.j2 b/resources/networkd/netdev.j2 new file mode 100644 index 0000000..3f364b4 --- /dev/null +++ b/resources/networkd/netdev.j2 @@ -0,0 +1,9 @@ +# ANSIBLE MANAGED FILE - DO NOT EDIT +[NetDev] +Name={{ item.0.key }} +Kind=vlan + +[VLAN] +Id={{ item.1 }} + +# EOF diff --git a/resources/networkd/network.j2 b/resources/networkd/network.j2 new file mode 100644 index 0000000..e251a56 --- /dev/null +++ b/resources/networkd/network.j2 @@ -0,0 +1,27 @@ +# ANSIBLE MANAGED FILE - DO NOT EDIT +[Match] +Name={{ item.key }} + +[Network] +DHCP={{ 'Yes' if item.value['dhcp'] | default(false) == true else 'No' }} +IPv6AcceptRA={{ 'Yes' if item.value['dhcp6'] | default(false) == true else 'No' }} +{% if item.value['addresses'] is defined %} +{% for ip_addr in item.value['addresses'] %} +Address={{ ip_addr }} +{% endfor %} +{% endif %} +{% if item.value['dns'] is defined %} +{% for dns_server in item.value['dns'] %} +DNS={{ dns_server }} +{% endfor %} +{% endif %} +{% if item.value['gateway'] is defined %} +Gateway={{ item.value['gateway'] }} +{% endif %} +{% if item.value['vlans'] is defined %} +{% for vlan_tag in item.value['vlans'] %} +VLAN={{ item.key }}.{{ vlan_tag }} +{% endfor %} +{% endif %} + +# EOF