Compare commits
No commits in common. "master" and "f7866cc982d9705a0866238a40d2a28598f7e2b8" have entirely different histories.
master
...
f7866cc982
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
.DS_Store
|
||||
*.prod
|
||||
*.log
|
||||
|
40
bash/bashrc/package.sh
Normal file
40
bash/bashrc/package.sh
Normal file
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
IS_CYGWIN=false
|
||||
|
||||
case $( uname -a | awk '{ print $1 }' ) in
|
||||
Darwin) # although this is deprecated, Mac still use it
|
||||
PERM="+111"
|
||||
;;
|
||||
# Linux) ;& // Fall through does not support in OS X
|
||||
CYGWIN*)
|
||||
PERM="/111"
|
||||
IS_CYGWIN=true
|
||||
;;
|
||||
*)
|
||||
PERM="/111"
|
||||
;;
|
||||
esac
|
||||
|
||||
function __func_head() {
|
||||
echo "Usage:" ${FUNCNAME[1]} $1
|
||||
}
|
||||
|
||||
function __func_help() {
|
||||
# echo "Usage:" ${FUNCNAME[1]} $1
|
||||
echo " ${FUNCNAME[1]} $1"
|
||||
}
|
||||
|
||||
# Run through all sources
|
||||
SDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/sources
|
||||
|
||||
if [ -d "$SDIR" ]; then
|
||||
echo "Begin source:"
|
||||
for i in $( find $SDIR -maxdepth 1 -type f -perm $PERM | sort )
|
||||
do
|
||||
echo " Source:" $( basename $i )
|
||||
. $i
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo " .. failed"
|
||||
fi
|
||||
done
|
||||
fi
|
225
bash/bashrc/rbashrc
Normal file
225
bash/bashrc/rbashrc
Normal file
@ -0,0 +1,225 @@
|
||||
# If not running interactively, don't do anything
|
||||
case $- in
|
||||
*i*) ;;
|
||||
*) return;;
|
||||
esac
|
||||
|
||||
__SCRIPT=$BASH_SOURCE
|
||||
echo $BASH_SOURCE | grep -q "^$( pwd )"
|
||||
if [ $? -ne 0 ]; then
|
||||
__SCRIPT=$( pwd )/$BASH_SOURCE
|
||||
fi
|
||||
|
||||
# Source global definitions
|
||||
if [ -f /etc/bashrc ]; then
|
||||
. /etc/bashrc
|
||||
fi
|
||||
|
||||
# Source for Custom bash ENV
|
||||
if [ -f ~/.rbashenv ]; then
|
||||
. ~/.rbashenv
|
||||
fi
|
||||
|
||||
# don't put duplicate lines or lines starting with space in the history.
|
||||
# See bash(1) for more options
|
||||
HISTCONTROL=ignoreboth
|
||||
|
||||
# append to the history file, don't overwrite it
|
||||
shopt -s histappend
|
||||
|
||||
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
|
||||
HISTSIZE=1000
|
||||
HISTFILESIZE=2000
|
||||
|
||||
# check the window size after each command and, if necessary,
|
||||
# update the values of LINES and COLUMNS.
|
||||
shopt -s checkwinsize
|
||||
|
||||
# If set, the pattern "**" used in a pathname expansion context will
|
||||
# match all files and zero or more directories and subdirectories.
|
||||
#shopt -s globstar
|
||||
|
||||
# make less more friendly for non-text input files, see lesspipe(1)
|
||||
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
||||
|
||||
# set variable identifying the chroot you work in (used in the prompt below)
|
||||
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
|
||||
debian_chroot=$(cat /etc/debian_chroot)
|
||||
fi
|
||||
|
||||
# set a fancy prompt (non-color, unless we know we "want" color)
|
||||
case "$TERM" in
|
||||
xterm-color) color_prompt=yes;;
|
||||
esac
|
||||
|
||||
# Alias definitions.
|
||||
# You may want to put all your additions into a separate file like
|
||||
# ~/.bash_aliases, instead of adding them here directly.
|
||||
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
|
||||
|
||||
if [ -f ~/.bash_aliases ]; then
|
||||
. ~/.bash_aliases
|
||||
fi
|
||||
|
||||
# enable programmable completion features (you don't need to enable
|
||||
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
|
||||
# sources /etc/bash.bashrc).
|
||||
if ! shopt -oq posix; then
|
||||
if [ -f /usr/share/bash-completion/bash_completion ]; then
|
||||
. /usr/share/bash-completion/bash_completion
|
||||
elif [ -f /etc/bash_completion ]; then
|
||||
. /etc/bash_completion
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -x "/usr/bin/gpg-agent" ]; then
|
||||
GPG_ENV="$HOME/.gnupg/environment"
|
||||
|
||||
function __start_agent {
|
||||
gpg-agent --daemon > "${GPG_ENV}"
|
||||
chmod 600 "${GPG_ENV}"
|
||||
. "${GPG_ENV}" > /dev/null
|
||||
}
|
||||
|
||||
if [ -f "${GPG_ENV}" ]; then
|
||||
. "${GPG_ENV}" > /dev/null
|
||||
|
||||
gpg-agent > /dev/null 2>&1
|
||||
[ "$?" -ne 0 ] && { __start_agent; }
|
||||
else
|
||||
__start_agent;
|
||||
fi
|
||||
fi
|
||||
|
||||
BASHL_UUID="<UUID>"
|
||||
export BASH_SDIR=/tmp/$BASHL_UUID
|
||||
[ ! -d "$BASH_SDIR" ] && mkdir "$BASH_SDIR"
|
||||
|
||||
|
||||
function __cryptd {
|
||||
echo "<PASSWD>" | gpg --batch -q --cipher-algo AES256 --passphrase-fd 0 -o "$2" -d "$1"
|
||||
}
|
||||
|
||||
function __crypte {
|
||||
echo "<PASSWD>" | gpg --batch -q --cipher-algo AES256 --passphrase-fd 0 -o "$1.enc" -c "$1"
|
||||
mv "$1.enc" "$1"
|
||||
}
|
||||
__CFILE=""
|
||||
function __cacheDownload {
|
||||
MLINK=$( echo "$1" | md5sum )
|
||||
|
||||
__CFILE=$BASH_SDIR/$MLINK
|
||||
|
||||
if [ ! -f "$__CFILE" ]; then
|
||||
__download "$1" > "$__CFILE"
|
||||
__crypte "$__CFILE"
|
||||
fi
|
||||
}
|
||||
|
||||
function __download {
|
||||
which curl 2>&1 > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
curl -s "$1"
|
||||
return;
|
||||
fi
|
||||
|
||||
which wget 2>&1 > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
wget -qO- "$1"
|
||||
return;
|
||||
fi
|
||||
}
|
||||
|
||||
function __uuid {
|
||||
local __out=$1
|
||||
|
||||
which uuidgen 2>&1 > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
local uuid=$( uuidgen )
|
||||
else
|
||||
local uuid=$( cat /proc/sys/kernel/random/uuid )
|
||||
fi
|
||||
eval $__out="'$uuid'"
|
||||
}
|
||||
|
||||
function rbash_upgrade {
|
||||
echo "Updating $__SCRIPT"
|
||||
__uuid TMPID
|
||||
TMPFILE=/tmp/$TMPID
|
||||
__download "https://git.astropenguin.net/?p=utils.git;a=blob_plain;f=bash/bashrc/rbashrc;hb=HEAD" > $TMPFILE
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
MC_NAME="<MACHINE_NAME>"
|
||||
MCC_NAME="<MACHINE_COLORED_NAME>"
|
||||
else
|
||||
MC_NAME=$1
|
||||
MCC_NAME=$2
|
||||
fi
|
||||
|
||||
__uuid UUID
|
||||
__uuid PASS
|
||||
PMC_NAME=$( echo "#_MACHINE_NAME_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
||||
PMCC_NAME=$( echo "#_MACHINE_COLORED_NAME_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
||||
UUID_TOK=$( echo "#_UUID_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
||||
PASS_TOK=$( echo "#_PASSWD_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
||||
COLOR_CODE_TOK=$( echo "#_COLOR_CODE_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
||||
COLOR_CODE=$(( $RANDOM * 6 / 32767 + 1 ))
|
||||
|
||||
sed -i \
|
||||
-e "s/$PMC_NAME/$MC_NAME/g" \
|
||||
-e "s/$PMCC_NAME/$MCC_NAME/g" \
|
||||
-e "s/$UUID_TOK/$UUID/g" \
|
||||
-e "s/$PASS_TOK/$PASS/g" \
|
||||
-e "s/$COLOR_CODE_TOK/$COLOR_CODE/g" \
|
||||
$TMPFILE
|
||||
|
||||
mv $TMPFILE $__SCRIPT
|
||||
. $__SCRIPT
|
||||
}
|
||||
|
||||
function rbash_run {
|
||||
echo "Getting: $1"
|
||||
__cacheDownload "https://git.astropenguin.net/?p=utils.git;a=blob_plain;f=$1;hb=HEAD"
|
||||
shift
|
||||
__uuid TMPID
|
||||
TMPFILE=/tmp/$TMPID
|
||||
__cryptd "$__CFILE" "$TMPFILE"
|
||||
|
||||
chmod 700 "$TMPFILE"
|
||||
"$TMPFILE" "$@"
|
||||
rm "$TMPFILE"
|
||||
}
|
||||
|
||||
export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '
|
||||
export EDITOR=vim
|
||||
|
||||
# User specific aliases and functions
|
||||
echo "Source:"
|
||||
function __ns {
|
||||
if [ -z "$2" ]; then
|
||||
FPATH="sources/$1"
|
||||
else
|
||||
FPATH=$1
|
||||
fi
|
||||
|
||||
echo " $1"
|
||||
__cacheDownload "https://git.astropenguin.net/?p=utils.git;a=blob_plain;f=bash/bashrc/$FPATH;hb=HEAD"
|
||||
shift
|
||||
__uuid TMPID
|
||||
TMPFILE=/tmp/$TMPID
|
||||
__cryptd "$__CFILE" "$TMPFILE"
|
||||
. $TMPFILE
|
||||
rm $TMPFILE
|
||||
}
|
||||
|
||||
__ns "package.sh" 1
|
||||
__ns "10_aliases"
|
||||
__ns "20_fast-greps"
|
||||
__ns "30_mysql"
|
||||
__ns "40_go-command"
|
||||
__ns "41_pivot-command"
|
||||
|
||||
# Source for additional rc
|
||||
if [ -f ~/.bashrc_local ]; then
|
||||
. ~/.bashrc_local
|
||||
fi
|
@ -1,8 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ssh-agent key lifetime
|
||||
alias ssh-add="ssh-add -t 43200"
|
||||
|
||||
SSH_ENV="$HOME/.ssh/environment"
|
||||
|
||||
function start_agent {
|
@ -25,14 +25,16 @@ alias p4='pushd +4'
|
||||
alias o=popd
|
||||
alias d='dirs -v'
|
||||
|
||||
# default grep opts
|
||||
alias grep='grep --color=auto --exclude-dir .git'
|
||||
# fast greps
|
||||
alias grep='grep --color=auto --exclude=\.svn'
|
||||
alias grepphp='grep -n --include=*.php'
|
||||
alias grepjs='grep -n --include=*.js'
|
||||
|
||||
# Wget prefix
|
||||
alias wget='wget --directory-prefix="$HOME/Downloads"'
|
||||
|
||||
# ssh-agent key lifetime
|
||||
alias ssh-add="ssh-add -t 43200"
|
||||
|
||||
# Pretty print sqlite3
|
||||
alias sqlite3="sqlite3 -header -column"
|
||||
|
||||
# Kubernetes
|
||||
alias kconf='kubectl config'
|
37
bash/bashrc/sources/11_vs_env
Executable file
37
bash/bashrc/sources/11_vs_env
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
if ! $IS_CYGWIN; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -n "$FrameworkVersion" ]; then
|
||||
alias vsshell='echo "FrameworkVersion $FrameworkVersion"'
|
||||
return
|
||||
fi
|
||||
|
||||
BAT_DIR=~/.local/lib/bat
|
||||
mkdir -p $BAT_DIR
|
||||
|
||||
VS_SHELL_BAT=$BAT_DIR/vs-env.bat
|
||||
|
||||
function vsshell {
|
||||
_SHELL=$( cygpath -w -a $VS_SHELL_BAT )
|
||||
cmd /c "$_SHELL"
|
||||
exit
|
||||
}
|
||||
|
||||
if [ -f "$VS_SHELL_BAT" ]; then
|
||||
_PATH=$( cygpath "$( grep -o "^@REM FILE_PATH: .\+" "$VS_SHELL_BAT" | cut -c 17- )" )
|
||||
if [ -f "$_PATH" ]; then
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
START_MENU="$( cygpath $ProgramData )/Microsoft/Windows/Start Menu/"
|
||||
|
||||
_PATH=$( find "$START_MENU" -name "*Command Prompt*" | grep "Visual Studio" | grep x64 | grep Native | xargs -I % readshortcut % -r | grep -o "\"\([^\"]\+\)\"" )
|
||||
|
||||
echo "@echo off" > "$VS_SHELL_BAT"
|
||||
echo "@REM FILE_PATH: ${_PATH:1:-1}" >> "$VS_SHELL_BAT"
|
||||
echo "CALL $_PATH" >> "$VS_SHELL_BAT"
|
||||
echo "START $( where mintty ) -i /Cygwin-Terminal.ico -" >> "$VS_SHELL_BAT"
|
34
bash/bashrc/sources/20_fast-greps
Executable file
34
bash/bashrc/sources/20_fast-greps
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
function grepmysql () {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "MySQL_SERVER_NAME [WITH_OPTIONS]"
|
||||
echo
|
||||
else
|
||||
if [[ -z "$2" ]]; then
|
||||
grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $2 }'
|
||||
else
|
||||
grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $2" "$3 }'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function grepdb () {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "DB_NAME"
|
||||
echo
|
||||
else
|
||||
grep $1 ~/.db_pass | awk 'BEGIN{FS=":"}{ print $2 }'
|
||||
fi
|
||||
}
|
||||
|
||||
function greptype() {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "TYPE GREP_ARGS"
|
||||
echo
|
||||
else
|
||||
CMD="grep --color=auto -n --include=*.$1"
|
||||
shift
|
||||
$CMD $@
|
||||
fi
|
||||
}
|
@ -1,18 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
function grepmysql {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "MySQL_SERVER_NAME [WITH_OPTIONS]"
|
||||
echo
|
||||
else
|
||||
if [[ -z "$2" ]]; then
|
||||
grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $2 }'
|
||||
else
|
||||
grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $2" "$3 }'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function mysqlo () {
|
||||
if [ -z "$1" ]; then
|
||||
__func_head "SERVER_NAME"
|
@ -29,25 +29,19 @@ function _begin_sel() {
|
||||
}
|
||||
|
||||
function go() {
|
||||
local i _GO
|
||||
local i
|
||||
ARG1=$1; ARG2=$2; ARG3=$3;
|
||||
|
||||
if [[ -z "$ARG1" ]]; then
|
||||
__func_head "[MODE] SITE TARGET_DIR [..SLICE]"
|
||||
__func_help "up [MODE] TARGET_DIR"
|
||||
__func_help "down [MODE] TARGET_DIR [..SLICE]"
|
||||
__func_help "compiler commands use \"go help\""
|
||||
echo
|
||||
return 1
|
||||
fi
|
||||
|
||||
NAV=false
|
||||
case "$ARG1" in
|
||||
bug|build|clean|doc|env|fix|fmt|generate|get|install|list|mod|work|run|test|tool|version|vet|help)
|
||||
_GO=$( which go )
|
||||
"$_GO" $@
|
||||
return $?
|
||||
;;
|
||||
p)
|
||||
shift
|
||||
CC='pushd' ;;
|
16
bash/bashrc/sources/50_blog
Executable file
16
bash/bashrc/sources/50_blog
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
function blog () {
|
||||
if [[ -z `command -v cj` ]]; then
|
||||
echo "Cannot find cj"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "CONTENT(CJ)"
|
||||
echo
|
||||
else
|
||||
FILE=$(date +%Y%m%d)
|
||||
echo "$1 " | xargs -d' ' cj >> ~/blog/$FILE
|
||||
fi
|
||||
}
|
21
bash/bashrc/sources/60_diagnostics
Executable file
21
bash/bashrc/sources/60_diagnostics
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
function catlog () {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "FILE"
|
||||
echo " Will exclude:"
|
||||
cat ~/.settings/checklog_exclude | awk '{ print " "$1 }'
|
||||
echo
|
||||
else
|
||||
GZIP=
|
||||
file "$1" | grep gzip > /dev/null && GZIP=true
|
||||
|
||||
EXCLUDE=$(awk '{ printf("(%s)|", $1) }' ~/.settings/checklog_exclude | sed 's/|$//')
|
||||
|
||||
if [ $GZIP ]; then
|
||||
gunzip -c $1 | egrep -v $EXCLUDE
|
||||
else
|
||||
egrep -v $EXCLUDE $1
|
||||
fi
|
||||
fi
|
||||
}
|
96
bash/cronbackup/backup.sh
Normal file
96
bash/cronbackup/backup.sh
Normal file
@ -0,0 +1,96 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./config.sh
|
||||
|
||||
# IO Redirection
|
||||
exec > $LOGFILE
|
||||
exec 2> $ERRLOG
|
||||
|
||||
|
||||
if [[ -n $BMOUNT ]] && ! grep -qs $BMOUNT /proc/mounts; then
|
||||
echo Mounting $BMOUNT ...
|
||||
mount $BMOUNT
|
||||
MOUNTED=$?
|
||||
fi
|
||||
|
||||
if ! [ -d $BAKDIR ]; then
|
||||
mkdir $BAKDIR
|
||||
fi
|
||||
|
||||
|
||||
echo Begin backup schedule:
|
||||
echo Date: $(date)
|
||||
|
||||
while read line; do
|
||||
|
||||
# substring first char
|
||||
firstChr=${line::1}
|
||||
|
||||
# if line is not empty and does not start with "#"
|
||||
|
||||
if [ $firstChr ] && [ $firstChr != "#" ]; then
|
||||
|
||||
# file and arguments are seperated by ":"
|
||||
IFS=':' read -ra ARGS <<< "$line"
|
||||
|
||||
# Get file
|
||||
FILE=${ARGS[0]}
|
||||
|
||||
# if file exists
|
||||
if [ -a $FILE ]; then
|
||||
|
||||
# filename
|
||||
FILENAME=$(basename $FILE)
|
||||
|
||||
# set the backup name YYYYMMDDhhmm
|
||||
BACKUPFILE=$(date +$FILENAME.%Y%m%d%H%M.tar.gz)
|
||||
|
||||
# exclude file
|
||||
EXCLUDE="exclude/${ARGS[1]}"
|
||||
|
||||
CHDIR=$(dirname $FILE)
|
||||
|
||||
if [ -d $FILE ]; then
|
||||
CHDIR="$FILE/../"
|
||||
fi
|
||||
|
||||
if [ -f $EXCLUDE ]; then
|
||||
tar zcf "$BAKDIR/$BACKUPFILE" -C $CHDIR $FILENAME -X $EXCLUDE
|
||||
else
|
||||
tar zcf "$BAKDIR/$BACKUPFILE" -C $CHDIR $FILENAME
|
||||
fi
|
||||
|
||||
# count backup file
|
||||
fCount=$(ls $BAKDIR/$FILENAME.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].tar.gz|wc -l)
|
||||
|
||||
echo " Check for existing backups "$FILENAME \(Have: $fCount\)
|
||||
|
||||
# keep up to X backups
|
||||
if [ $fCount -ne $KEEP ]; then
|
||||
|
||||
# delete count
|
||||
dCount=`expr $fCount - $KEEP`
|
||||
|
||||
# loop over files
|
||||
for files in $BAKDIR/*$FILENAME*.gz; do
|
||||
if [ 0 -lt $dCount ]; then
|
||||
|
||||
# remove expired file
|
||||
echo " Removing expired backup: "$files
|
||||
rm "$files";
|
||||
|
||||
# dCount --
|
||||
dCount=$((dCount-1));
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
fi
|
||||
# echo --\> $line
|
||||
done < backup_list
|
||||
|
||||
if [[ "$MOUNTED" = 0 ]]; then
|
||||
umount $BMOUNT
|
||||
fi
|
11
bash/cronbackup/backup_list
Normal file
11
bash/cronbackup/backup_list
Normal file
@ -0,0 +1,11 @@
|
||||
# git backups
|
||||
/home/git/repositories/blogAPI.git
|
||||
/home/git/repositories/wenku8.git
|
||||
/home/git/repositories/wenku8-android.git
|
||||
/home/git/repositories/MetroSSH.git
|
||||
/home/git/repositories/wconv.git
|
||||
/home/git/repositories/utils.git
|
||||
|
||||
# www
|
||||
/var/www/wenku8
|
||||
/var/www/file:file.txt
|
9
bash/cronbackup/config.sh
Normal file
9
bash/cronbackup/config.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash`
|
||||
|
||||
LOGFILE=backup.log
|
||||
ERRLOG=backup_errors.log
|
||||
|
||||
BMOUNT=/mnt/backup
|
||||
BAKDIR=$BMOUNT/backup/cron
|
||||
|
||||
KEEP=7
|
13
bash/cygwin/bin/cyg-import-key
Executable file
13
bash/cygwin/bin/cyg-import-key
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
PUBKEY_URL="https://cygwin.com/key/pubring.asc"
|
||||
|
||||
TMP=$( mktemp )
|
||||
|
||||
function __o { rm $TMP; }
|
||||
trap __o EXIT
|
||||
|
||||
|
||||
curl "$PUBKEY_URL" > $TMP
|
||||
|
||||
gpg2 --import $TMP
|
2
bash/cygwin/bin/cyg-update
Executable file
2
bash/cygwin/bin/cyg-update
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
/opt/setup-x86_64.exe -qg
|
27
bash/cygwin/bin/cyg-update-installer
Executable file
27
bash/cygwin/bin/cyg-update-installer
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
SETUP_BIN="/opt/setup-x86_64.exe"
|
||||
|
||||
SIG_URL="https://cygwin.com/setup-x86_64.exe.sig"
|
||||
SETUP_URL="https://cygwin.com/setup-x86_64.exe"
|
||||
|
||||
TMP_BIN=$( mktemp )
|
||||
TMP_SIG=$( mktemp )
|
||||
|
||||
function __o { rm $TMP_BIN; rm $TMP_SIG; }
|
||||
trap __o EXIT
|
||||
|
||||
echo "Downloading Signature ..."
|
||||
curl -s "$SIG_URL" > $TMP_SIG
|
||||
echo "Downloading setup binary ..."
|
||||
curl -s "$SETUP_URL" > $TMP_BIN
|
||||
|
||||
echo "Verifying Signature ..."
|
||||
gpg2 -q --verify $TMP_SIG $TMP_BIN
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ERROR: Bad Signature!"
|
||||
else
|
||||
echo "Installing setup"
|
||||
cp $TMP_BIN $SETUP_BIN
|
||||
chmod +x $SETUP_BIN
|
||||
fi
|
11
bash/cygwin/bin/mkuserdirs
Executable file
11
bash/cygwin/bin/mkuserdirs
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
PROFILE=$( cygpath $USERPROFILE )
|
||||
for i in $( ls $PROFILE | grep -o "^[A-Z][a-z]\+$" ); do
|
||||
ln -vs "$PROFILE/$i" $HOME/
|
||||
done
|
||||
|
||||
# Package Directory
|
||||
PKG_DIR="$APPDATA/../Local/Packages"
|
||||
if [ -d "$PKG_DIR" ]; then
|
||||
ln -vs "$PKG_DIR" $HOME/
|
||||
fi
|
32
bash/cygxcolors/Solarized
Normal file
32
bash/cygxcolors/Solarized
Normal file
@ -0,0 +1,32 @@
|
||||
! Common
|
||||
|
||||
#define S_yellow #b58900
|
||||
#define S_orange #cb4b16
|
||||
#define S_red #dc322f
|
||||
#define S_magenta #d33682
|
||||
#define S_violet #6c71c4
|
||||
#define S_blue #268bd2
|
||||
#define S_cyan #2aa198
|
||||
#define S_green #859900
|
||||
|
||||
! Dark
|
||||
|
||||
#define S_base03 #222222
|
||||
#define S_base02 #073642
|
||||
#define S_base01 #586e75
|
||||
#define S_base00 #657b83
|
||||
#define S_base0 #839496
|
||||
#define S_base1 #93a1a1
|
||||
#define S_base2 #eee8d5
|
||||
#define S_base3 #fdf6e3
|
||||
|
||||
! Light
|
||||
|
||||
! #define S_base03 #fdf6e3
|
||||
! #define S_base02 #eee8d5
|
||||
! #define S_base01 #93a1a1
|
||||
! #define S_base00 #839496
|
||||
! #define S_base0 #657b83
|
||||
! #define S_base1 #586e75
|
||||
! #define S_base2 #073642
|
||||
! #define S_base3 #002b36
|
3
bash/cygxcolors/Xdefaults
Normal file
3
bash/cygxcolors/Xdefaults
Normal file
@ -0,0 +1,3 @@
|
||||
XTerm*font: 9x15
|
||||
XTerm*saveLines: 1000
|
||||
XTerm*geometry: 145x35
|
80
bash/cygxcolors/applyXColors.sh
Executable file
80
bash/cygxcolors/applyXColors.sh
Executable file
@ -0,0 +1,80 @@
|
||||
#!/bin/bash
|
||||
|
||||
CONF_FILE=$1
|
||||
TARGET_X=~/.Xdefaults
|
||||
|
||||
[ ! -f $CONF_FILE ] && exit;
|
||||
|
||||
function getColor() {
|
||||
if [[ -n "$1" ]]; then
|
||||
grep -E "^[ ]*#define.+S_$1[ ]+" $CONF_FILE | awk '{print $3}'
|
||||
fi
|
||||
}
|
||||
|
||||
X_BEGIN_STR="!! ~~~~ BEGIN COLOR SETTINGS ~~~~ !!"
|
||||
X_END_STR="!! ~~~~ END COLOR SETTINGS ~~~~ !!"
|
||||
ORIGX=""
|
||||
|
||||
if [ -f $TARGET_X ]; then
|
||||
SKIP=false
|
||||
while read line;
|
||||
do
|
||||
if [ "$line" = "$X_BEGIN_STR" ]; then
|
||||
SKIP=true
|
||||
continue
|
||||
elif [ "$line" = "$X_END_STR" ]; then
|
||||
SKIP=false
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ $SKIP = false ] && [ -n "$line" ]; then
|
||||
ORIGX="$ORIGX$line\n"
|
||||
fi
|
||||
|
||||
done < $TARGET_X
|
||||
fi
|
||||
|
||||
CNAMES=( yellow orange red magenta violet blue cyan green base0 base1 base2 base3 base00 base01 base02 base03 )
|
||||
declare -A COLORS=()
|
||||
|
||||
for i in "${CNAMES[@]}"
|
||||
do
|
||||
COLORS[$i]=$( getColor $i )
|
||||
done
|
||||
|
||||
|
||||
SETTINGS=""
|
||||
|
||||
function push_val() {
|
||||
SETTINGS=$SETTINGS"$1\n"
|
||||
}
|
||||
|
||||
push_val
|
||||
push_val "$X_BEGIN_STR"
|
||||
push_val "*VT100*background: ${COLORS['base03']}"
|
||||
push_val "*VT100*foreground: ${COLORS['base0']}"
|
||||
push_val "*VT100*fading: 40"
|
||||
push_val "*VT100*fadeColor: ${COLORS['base08']}"
|
||||
push_val "*VT100*cursorColor: ${COLORS['base1']}"
|
||||
push_val "*VT100*pointerColorBackground: ${COLORS['base01']}"
|
||||
push_val "*VT100*pointerColorForeground: ${COLORS['base1']}"
|
||||
|
||||
push_val "*VT100*color0: ${COLORS['base02']}"
|
||||
push_val "*VT100*color1: ${COLORS['red']}"
|
||||
push_val "*VT100*color2: ${COLORS['green']}"
|
||||
push_val "*VT100*color3: ${COLORS['yellow']}"
|
||||
push_val "*VT100*color4: ${COLORS['blue']}"
|
||||
push_val "*VT100*color5: ${COLORS['magenta']}"
|
||||
push_val "*VT100*color6: ${COLORS['cyan']}"
|
||||
push_val "*VT100*color7: ${COLORS['base2']}"
|
||||
push_val "*VT100*color8: ${COLORS['base03']}"
|
||||
push_val "*VT100*color9: ${COLORS['orange']}"
|
||||
push_val "*VT100*color10: ${COLORS['base01']}"
|
||||
push_val "*VT100*color11: ${COLORS['base00']}"
|
||||
push_val "*VT100*color12: ${COLORS['base0']}"
|
||||
push_val "*VT100*color13: ${COLORS['violet']}"
|
||||
push_val "*VT100*color14: ${COLORS['base1']}"
|
||||
push_val "*VT100*color15: ${COLORS['base3']}"
|
||||
push_val "$X_END_STR"
|
||||
|
||||
echo -e "$ORIGX\n$SETTINGS" > $TARGET_X
|
26
bash/dumpcolors
Normal file
26
bash/dumpcolors
Normal file
@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# This file echoes a bunch of color codes to the
|
||||
# terminal to demonstrate what's available. Each
|
||||
# line is the color code of one forground color,
|
||||
# out of 17 (default + 16 escapes), followed by a
|
||||
# test use of that color on all nine background
|
||||
# colors (default + 8 escapes).
|
||||
#
|
||||
|
||||
T='gYw' # The test text
|
||||
|
||||
echo -e "\n 40m 41m 42m 43m\
|
||||
44m 45m 46m 47m";
|
||||
|
||||
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
|
||||
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
|
||||
' 36m' '1;36m' ' 37m' '1;37m';
|
||||
do FG=${FGs// /}
|
||||
echo -en " $FGs \033[$FG $T "
|
||||
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
|
||||
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
|
||||
done
|
||||
echo;
|
||||
done
|
||||
echo
|
30
bash/hostconf/apply.sh
Executable file
30
bash/hostconf/apply.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -f $1 ]; then
|
||||
source $1
|
||||
fi
|
||||
|
||||
uname | grep -q Linux
|
||||
LINUX=$?
|
||||
|
||||
if [ "$LINUX" -eq "0" ]; then
|
||||
HOST=/etc/hosts
|
||||
else
|
||||
HOST=/cygdrive/c/Windows/System32/drivers/etc/hosts
|
||||
fi
|
||||
|
||||
if [ ${HOSTNAMES[0]+1} ]; then
|
||||
for i in {0..99};
|
||||
do
|
||||
if [ ${HOSTNAMES[$i]+1} ]; then
|
||||
XID="# Automated Host Def. Id. $i"
|
||||
if grep -q "$XID" $HOST; then
|
||||
|
||||
REC=$( echo "s/.*$XID$/${HOSTNAMES[$i]}\ $XID/g" | sed "s/\ /\\\ /g" )
|
||||
sed -i "$REC" $HOST
|
||||
else
|
||||
echo ${HOSTNAMES[$i]} $XID >> $HOST
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
7
bash/hostconf/noconf
Normal file
7
bash/hostconf/noconf
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
HOSTNAMES=()
|
||||
|
||||
for i in {0..99}; do
|
||||
HOSTNAMES[$i]=""
|
||||
done
|
324
bash/rbashrc
324
bash/rbashrc
@ -1,324 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# If not running interactively, don't do anything
|
||||
case $- in
|
||||
*i*) ;;
|
||||
*) return;;
|
||||
esac
|
||||
|
||||
__SCRIPT=$BASH_SOURCE
|
||||
RBASH_HOME="$HOME/.rbash"
|
||||
RBASH_SOURCES="$RBASH_HOME/sources"
|
||||
RBASH_CONFIG="$RBASH_HOME/config"
|
||||
RBASH_ENV="$RBASH_HOME/env"
|
||||
RBASH_REMOTE="https://git.k8s.astropenguin.net"
|
||||
RBASH_REPO="penguin/utils"
|
||||
RBASH_PATH="bash"
|
||||
RBASH_MERGED="$RBASH_SOURCES/merged"
|
||||
RBASH_BIN="$RBASH_HOME/bin"
|
||||
|
||||
RHOSTNAME="<HOSTNAME>"
|
||||
RDOMAIN="<DOMAIN>"
|
||||
RCOLOR="<RCOLOR>"
|
||||
|
||||
if [ "$RHOSTNAME" == "<HOSTNAME"">" ]; then
|
||||
RHOSTNAME="\u"
|
||||
RDOMAIN="@"$( hostname -s )
|
||||
RCOLOR=$(( $RANDOM * 6 / 32767 + 1 ))
|
||||
fi
|
||||
|
||||
# Source global definitions
|
||||
if [ -f /etc/bashrc ]; then
|
||||
. /etc/bashrc
|
||||
fi
|
||||
|
||||
# don't put duplicate lines or lines starting with space in the history.
|
||||
# See bash(1) for more options
|
||||
HISTCONTROL=ignoreboth
|
||||
|
||||
# append to the history file, don't overwrite it
|
||||
shopt -s histappend
|
||||
|
||||
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
|
||||
HISTSIZE=1000
|
||||
HISTFILESIZE=2000
|
||||
|
||||
# check the window size after each command and, if necessary,
|
||||
# update the values of LINES and COLUMNS.
|
||||
shopt -s checkwinsize
|
||||
|
||||
# If set, the pattern "**" used in a pathname expansion context will
|
||||
# match all files and zero or more directories and subdirectories.
|
||||
#shopt -s globstar
|
||||
|
||||
# make less more friendly for non-text input files, see lesspipe(1)
|
||||
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
||||
|
||||
# set variable identifying the chroot you work in (used in the prompt below)
|
||||
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
|
||||
debian_chroot=$(cat /etc/debian_chroot)
|
||||
fi
|
||||
|
||||
# set a fancy prompt (non-color, unless we know we "want" color)
|
||||
case "$TERM" in
|
||||
xterm-color) color_prompt=yes;;
|
||||
esac
|
||||
|
||||
# Alias definitions.
|
||||
# You may want to put all your additions into a separate file like
|
||||
# ~/.bash_aliases, instead of adding them here directly.
|
||||
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
|
||||
|
||||
if [ -f ~/.bash_aliases ]; then
|
||||
. ~/.bash_aliases
|
||||
fi
|
||||
|
||||
# enable programmable completion features (you don't need to enable
|
||||
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
|
||||
# sources /etc/bash.bashrc).
|
||||
if ! shopt -oq posix; then
|
||||
if [ -f /usr/share/bash-completion/bash_completion ]; then
|
||||
. /usr/share/bash-completion/bash_completion
|
||||
elif [ -f /etc/bash_completion ]; then
|
||||
. /etc/bash_completion
|
||||
fi
|
||||
fi
|
||||
|
||||
function __func_head() { echo "Usage:" ${FUNCNAME[1]} $1; }
|
||||
function __func_help() { echo " ${FUNCNAME[1]} $1"; }
|
||||
|
||||
function __download {
|
||||
which curl 2>&1 > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
curl -s "$1"
|
||||
return $?
|
||||
fi
|
||||
|
||||
which wget 2>&1 > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
wget -qO- "$1"
|
||||
return $?
|
||||
fi
|
||||
}
|
||||
|
||||
function rbash_cache {
|
||||
local CACHE_FILE
|
||||
MLINK=$( echo "$1" | md5sum | cut -d' ' -f1 )
|
||||
|
||||
CACHE_FILE="$RBASH_SOURCES/$MLINK"
|
||||
|
||||
if [ ! -f "$CACHE_FILE" ]; then
|
||||
__download "$1" > "$CACHE_FILE"
|
||||
fi
|
||||
|
||||
chmod 700 "$CACHE_FILE"
|
||||
echo -n "$CACHE_FILE"
|
||||
}
|
||||
|
||||
_RBASH_LOADED=
|
||||
mkdir -p "$RBASH_SOURCES" "$RBASH_BIN"
|
||||
|
||||
if [ ! -f "$RBASH_SOURCES/merged" ]; then
|
||||
_RBASH_MERGE_START=1
|
||||
fi
|
||||
|
||||
function rbash_load {
|
||||
local f path
|
||||
|
||||
if [ -z "$_RBASH_MERGE_START" ]; then
|
||||
if [ -n "$_RBASH_LOADED" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -f "$RBASH_MERGED" ]; then
|
||||
source $RBASH_MERGED
|
||||
if [ $? -eq 0 ]; then
|
||||
_RBASH_LOADED=1
|
||||
return 0
|
||||
fi
|
||||
rm "$RBASH_MERGED"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Load: $1"
|
||||
f=`rbash_cache "$RBASH_REMOTE/$RBASH_REPO/raw/branch/master/$RBASH_PATH/$1"`
|
||||
source "$f"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "echo \"Load: $1\"" >> "$RBASH_MERGED"
|
||||
cat "$f" >> "$RBASH_SOURCES/merged"
|
||||
else
|
||||
echo " ..failed"
|
||||
echo "echo \"Skipped: $1\". Use rbash-reload to try load this again." >> "$RBASH_MERGED"
|
||||
fi
|
||||
|
||||
chmod 700 "$RBASH_MERGED"
|
||||
}
|
||||
|
||||
function rbash-reload {
|
||||
_RBASH_LOADED=
|
||||
_RBASH_MERGE_START=1
|
||||
rm -f "$RBASH_SOURCES/merged"
|
||||
source "$RBASH_CONFIG"
|
||||
_RBASH_MERGE_START=
|
||||
}
|
||||
|
||||
function rbash-upgrade {
|
||||
echo "Updating $__SCRIPT"
|
||||
|
||||
local TMPFILE _P_HOSTNAME _P_DOMAIN _P_COLOR
|
||||
|
||||
TMPFILE=$( mktemp )
|
||||
__download "$RBASH_REMOTE/$RBASH_REPO/raw/branch/master/$RBASH_PATH/rbashrc" > $TMPFILE
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
RHOSTNAME=$1
|
||||
RDOMAIN=$2
|
||||
fi
|
||||
|
||||
_P_HOSTNAME="<HOSTNAME"">"
|
||||
_P_DOMAIN="<DOMAIN"">"
|
||||
_P_COLOR_CODE="<RCOLOR"">"
|
||||
|
||||
sed -i \
|
||||
-e "s/$_P_HOSTNAME/$RHOSTNAME/g" \
|
||||
-e "s/$_P_DOMAIN/$RDOMAIN/g" \
|
||||
-e "s/$_P_COLOR_CODE/$RCOLOR/g" \
|
||||
$TMPFILE
|
||||
|
||||
mv $TMPFILE $__SCRIPT
|
||||
|
||||
# Clean up the old dir
|
||||
if [ $? -eq 0 ] && [ -d "$RBASH_SOURCES" ]; then
|
||||
rm -r "$RBASH_SOURCES"
|
||||
fi
|
||||
|
||||
source $__SCRIPT
|
||||
}
|
||||
|
||||
function rbash-run {
|
||||
local f
|
||||
echo "Getting: $1"
|
||||
|
||||
f=`rbash_cache "$RBASH_REMOTE/$RBASH_REPO/raw/branch/master/$1"`
|
||||
shift
|
||||
|
||||
"$f" "$@"
|
||||
}
|
||||
|
||||
function _require_jq {
|
||||
which jq 2>&1 > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo This command requires jq.
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
declare -A _RBASH_DICT
|
||||
function rbash-list {
|
||||
_require_jq || return 1
|
||||
|
||||
echo "Available sources:"
|
||||
local _k
|
||||
for i in `__download "$RBASH_REMOTE/api/v1/repos/$RBASH_REPO/contents/$RBASH_PATH/sources/" | jq -r '.[].name'`; do
|
||||
_k=`echo -n $i | grep -o "^[0-9]\+"`
|
||||
_RBASH_DICT["s$_k"]=$i
|
||||
grep -q -e "^rbash_load \"sources/$i\"\$" "$RBASH_CONFIG"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo " * $i"
|
||||
else
|
||||
echo " $i"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function r2ensource {
|
||||
rbash-list || return 1
|
||||
|
||||
local _id _sel _tmp _en
|
||||
_en=()
|
||||
read -p "Enter the script id XX, delimited by space: " _ids
|
||||
for _id in $_ids; do
|
||||
_sel=${_RBASH_DICT["s$_id"]}
|
||||
if [ -z "$_sel" ]; then
|
||||
echo "No such id $_id"
|
||||
return 1
|
||||
fi
|
||||
|
||||
grep -q -e "^rbash_load \"sources/$_sel\"\$" "$RBASH_CONFIG"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "\"$_sel\" is already enabled."
|
||||
continue
|
||||
fi
|
||||
|
||||
_en+=("$_sel")
|
||||
done
|
||||
|
||||
_tmp=$( mktemp )
|
||||
cp "$RBASH_CONFIG" "$_tmp"
|
||||
for _id in "${_en[@]}"; do
|
||||
echo "rbash_load \"sources/$_id\"" >> $_tmp
|
||||
echo "Enabling $_id"
|
||||
done
|
||||
sort $_tmp > "$RBASH_CONFIG"
|
||||
rm -r "$_tmp" "$RBASH_SOURCES"
|
||||
}
|
||||
|
||||
function r2dissource {
|
||||
echo "Currently enabled sources:"
|
||||
grep -e "^rbash_load \"sources/" "$RBASH_CONFIG" | cut -c 21- | tr -d '"' | sed "s/^/ $1/g"
|
||||
|
||||
local _id _dis _opts
|
||||
_dis=()
|
||||
read -p "Enter the script id XX, delimited by space: " _ids
|
||||
for _id in $_ids; do
|
||||
_dis+=("$( grep -e "^rbash_load \"sources/${_id}_" "$RBASH_CONFIG" )")
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "No such id: $_id"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
_opts=""
|
||||
for _id in "${_dis[@]}"; do
|
||||
_opts="-e \"^$( echo -n $_id | sed 's/"/\\"/g' )$\" $_opts"
|
||||
echo "Disabling "$( echo -n $_id | sed 's/rbash_load \"sources\/\([^"]\+\)"/\1/g' )
|
||||
done
|
||||
|
||||
_dis=$( mktemp )
|
||||
sh -c "grep -v $_opts \"$RBASH_CONFIG\"" > $_dis
|
||||
sort $_dis > $RBASH_CONFIG
|
||||
rm -r "$_dis" "$RBASH_SOURCES"
|
||||
}
|
||||
|
||||
_SHELLD="\$"
|
||||
case $OSTYPE in
|
||||
cygwin)
|
||||
net session > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
_SHELLD="#"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
export PS1="This is ${RHOSTNAME}\e[1;3${RCOLOR}m${RDOMAIN}\e[0m: \w\n$_SHELLD "
|
||||
export EDITOR=vim
|
||||
export PATH="$RBASH_BIN:$PATH"
|
||||
|
||||
# Source for custom bash env, allows overriding
|
||||
if [ -f "$RBASH_ENV" ]; then
|
||||
source "$RBASH_ENV"
|
||||
fi
|
||||
|
||||
# Create default source config
|
||||
if [ ! -f "$RBASH_CONFIG" ]; then
|
||||
cat <<___DEFAULT___ > "$RBASH_CONFIG"
|
||||
rbash_load "sources/10_aliases"
|
||||
rbash_load "sources/12_shortcuts"
|
||||
rbash_load "sources/20_fast-greps"
|
||||
rbash_load "sources/40_go-command"
|
||||
rbash_load "sources/41_pivot-command"
|
||||
___DEFAULT___
|
||||
chmod 600 "$RBASH_CONFIG"
|
||||
fi
|
||||
|
||||
source "$RBASH_CONFIG"
|
@ -1,19 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function sanitize-perms {
|
||||
chown $USER.$USER . -R
|
||||
find . -type d -exec chmod 755 {}\;
|
||||
find . -type f -exec chmod 644 {}\;
|
||||
}
|
||||
|
||||
# Kubernetes
|
||||
function kres {
|
||||
local _O _D
|
||||
_O="-ocustom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name"
|
||||
_D="[0-9A-Za-z\-]"
|
||||
if [ -z "$3" ]; then
|
||||
kubectl get $1 -A $_O | grep "$2"
|
||||
else
|
||||
kubectl get $1 -A $_O | grep "$_D*$2$_D*\s\+$_D*$3$_D*"
|
||||
fi
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
which gpg-agent 2>&1 > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
GPG_ENV="$HOME/.gnupg/environment"
|
||||
|
||||
function __start_agent {
|
||||
gpg-agent --daemon > "${GPG_ENV}"
|
||||
chmod 600 "${GPG_ENV}"
|
||||
. "${GPG_ENV}" > /dev/null
|
||||
}
|
||||
|
||||
if [ -f "${GPG_ENV}" ]; then
|
||||
. "${GPG_ENV}" > /dev/null
|
||||
|
||||
gpg-agent > /dev/null 2>&1
|
||||
[ "$?" -ne 0 ] && { __start_agent; }
|
||||
else
|
||||
__start_agent;
|
||||
fi
|
||||
fi
|
@ -1,496 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
_SQLITE=$( which sqlite3 2>&1 )
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "sqlite3 is missing" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "test" | openssl enc -e -aes-256-cbc -pbkdf2 -k test 2>/dev/null > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "openssl does not exists nor support pbkdf2" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
_AUTH_DB=$RBASH_HOME/keystore.db
|
||||
_AUTH_SECRET=
|
||||
_KSTORE_DEF_PROP=${_KSTORE_DEF_PROP:-val}
|
||||
_KSTORE_DEC_FAILED="$RBASH_HOME/.decypt-failed"
|
||||
_KSTORE_TABLE=store
|
||||
|
||||
if [ -f "$RBASH_HOME/keystore.secret" ]; then
|
||||
_AUTH_SECRET=$( cat "$RBASH_HOME/keystore.secret" )
|
||||
fi
|
||||
|
||||
|
||||
function kstore {
|
||||
case $1 in
|
||||
add) shift; _kstoreadd "$@" ;;
|
||||
del) shift; _kstoredel "$@" ;;
|
||||
get) shift; _kstoreget "$@" ;;
|
||||
list) shift; _kstorelist "$@" ;;
|
||||
query) shift; _kstorequery "$@" ;;
|
||||
update) shift; _kstoreupdate "$@" ;;
|
||||
search) shift; _kstoresearch $@ ;;
|
||||
secret) shift; _kstoresecret $@ ;;
|
||||
*)
|
||||
__func_head "add [key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
__func_help "update [key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
__func_help "get [key] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
__func_help "del [key] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
__func_help "list"
|
||||
__func_help "search [key] [prop]"
|
||||
__func_help "secret ..."
|
||||
__func_help "upload s3-compatible-provider-name"
|
||||
__func_help "query SQL"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
return $?
|
||||
}
|
||||
|
||||
function _kstore {
|
||||
local CUR=${COMP_WORDS[COMP_CWORD]}
|
||||
local SCOPE=${COMP_WORDS[COMP_CWORD-1]}
|
||||
local t
|
||||
|
||||
COMPREPLY=()
|
||||
|
||||
case "$SCOPE" in
|
||||
kstore)
|
||||
COMPREPLY=( $(compgen -W "add del get list query update search secret" -- $CUR) )
|
||||
return
|
||||
;;
|
||||
get|update)
|
||||
COMPREPLY=( $(compgen -W "$( _kstorequery "SELECT DISTINCT key FROM $_KSTORE_TABLE" )" -- $CUR) )
|
||||
;;
|
||||
esac
|
||||
|
||||
t=${COMP_WORDS[COMP_CWORD-2]}
|
||||
case "$t" in
|
||||
get|update)
|
||||
t=`_kstorequote "$SCOPE"`
|
||||
COMPREPLY=( $(compgen -W "$( _kstorequery "SELECT DISTINCT prop FROM $_KSTORE_TABLE WHERE key = '$t'" )" -- $CUR) )
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
complete -F _kstore kstore
|
||||
|
||||
function _kstoresecret {
|
||||
case "$1" in
|
||||
clear) shift; _kstoresecret-clear "$@" ;;
|
||||
config) shift; _kstoresecret-config "$@" ;;
|
||||
change) shift; _kstoresecret-change "$@" ;;
|
||||
*)
|
||||
__func_head "clear"
|
||||
__func_help "config"
|
||||
__func_help "change"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function _kstoreinit {
|
||||
if [ ! -f "$_AUTH_DB" ]; then
|
||||
cat <<___SQL___ | $_SQLITE "$_AUTH_DB"
|
||||
CREATE TABLE IF NOT EXISTS $_KSTORE_TABLE (
|
||||
key TEXT NOT NULL
|
||||
, prop TEXT NOT NULL
|
||||
, data TEXT
|
||||
, PRIMARY KEY( key ASC, prop ASC )
|
||||
);
|
||||
___SQL___
|
||||
chmod 600 "$_AUTH_DB"
|
||||
fi
|
||||
kstore secret config
|
||||
}
|
||||
|
||||
function _kstorequote {
|
||||
echo -n "$1" | sed -e "s/'/''/g"
|
||||
}
|
||||
|
||||
function _kstoreenc {
|
||||
if [ -z "$_AUTH_SECRET" ]; then
|
||||
echo "Secret key is not set yet" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$1" == "-" ]; then
|
||||
openssl enc -e -aes-256-cbc -pbkdf2 -k "$_AUTH_SECRET" -a -A
|
||||
elif [ -f "$1" ]; then
|
||||
openssl enc -e -aes-256-cbc -pbkdf2 -k "$_AUTH_SECRET" -a -A -in "$1"
|
||||
else
|
||||
echo -n "$1" | openssl enc -e -aes-256-cbc -pbkdf2 -k "$_AUTH_SECRET" -a -A
|
||||
fi
|
||||
}
|
||||
|
||||
function _kstoredec {
|
||||
if [ -z "$_AUTH_SECRET" ]; then
|
||||
echo "Secret key is not set yet" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
openssl enc -d -aes-256-cbc -pbkdf2 -k "$_AUTH_SECRET" -a -A
|
||||
_code=$?
|
||||
if [ $_code -ne 0 ]; then
|
||||
touch $_KSTORE_DEC_FAILED
|
||||
return $_code
|
||||
fi
|
||||
}
|
||||
|
||||
function _kstoresecret-auto {
|
||||
case $OSTYPE in
|
||||
darwin*) _kstoresecret-macos "$@" ;;
|
||||
cygwin) _kstoresecret-cygwin "$@" ;;
|
||||
*)
|
||||
echo "$OSTYPE is Not supported yet" >&2
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function _kstoresecret-cygwin {
|
||||
local _A
|
||||
|
||||
which kstorecred 2>/dev/null > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
_kstoredl-kstorecred
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
get)
|
||||
_A=$( kstorecred get )
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
_AUTH_SECRET="$_A"
|
||||
;;
|
||||
set)
|
||||
kstorecred set "$_AUTH_SECRET"
|
||||
;;
|
||||
del)
|
||||
kstorecred del
|
||||
;;
|
||||
*)
|
||||
echo "Unknown action: $1" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function _kstoresecret-macos {
|
||||
local _A
|
||||
case $1 in
|
||||
get)
|
||||
_A=`security find-generic-password -a default -gs rbash-kstore 2>&1 | grep ^password | cut -c 11-`
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
_AUTH_SECRET="${_A:1:-1}"
|
||||
;;
|
||||
set)
|
||||
security add-generic-password -a default -s rbash-kstore -w "$_AUTH_SECRET"
|
||||
;;
|
||||
del)
|
||||
security delete-generic-password -a default -s rbash-kstore
|
||||
;;
|
||||
*)
|
||||
echo "Unknown action: $1" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function _kstoresecret-config {
|
||||
local _CONFIRM
|
||||
if [ -f "$_KSTORE_DEC_FAILED" ]; then
|
||||
rm $_KSTORE_DEC_FAILED
|
||||
_AUTH_SECRET=
|
||||
fi
|
||||
if [ -z "$_AUTH_SECRET" ]; then
|
||||
|
||||
_kstoresecret-auto get
|
||||
if [ -n "$_AUTH_SECRET" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
read -sp "Enter passphrase: " _AUTH_SECRET
|
||||
echo
|
||||
if [ -z "$_AUTH_SECRET" ]; then
|
||||
echo "Passphrase cannot be empty" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
case $OSTYPE in
|
||||
cygwin|darwin*)
|
||||
read -p "Save this password to OS's keystore? (y/n): " _CONFIRM
|
||||
if [ "$_CONFIRM" != "y" ]; then
|
||||
return 0
|
||||
fi
|
||||
_kstoresecret-auto set
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
function _kstoresecret-change {
|
||||
_kstoresecret-config
|
||||
|
||||
local _NEW_SECRET i _key _prop _O_SECRET _BAK
|
||||
read -sp "Enter the new passphrase: " _NEW_SECRET
|
||||
echo
|
||||
read -sp "Enter the passphrase again: " i
|
||||
echo
|
||||
if [ "$i" != "$_NEW_SECRET" ]; then
|
||||
echo "Passphrase mismatched" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
_BAK=$( mktemp )
|
||||
cp "$_AUTH_DB" "$_BAK"
|
||||
|
||||
echo "Backed up at $_BAK"
|
||||
|
||||
_O_SECRET="$_AUTH_SECRET"
|
||||
for i in `$_SQLITE -list "$_AUTH_DB" "SELECT _ROWID_ FROM $_KSTORE_TABLE;"`; do
|
||||
_AUTH_SECRET=$_O_SECRET
|
||||
_key=`$_SQLITE -list "$_AUTH_DB" "SELECT key FROM $_KSTORE_TABLE WHERE _ROWID_ = $i;"`
|
||||
_key=`_kstorequote "$_key"`
|
||||
_prop=`$_SQLITE -list "$_AUTH_DB" "SELECT prop FROM $_KSTORE_TABLE WHERE _ROWID_ = $i;"`
|
||||
_prop=`_kstorequote "$_prop"`
|
||||
_val=`kstore get "$_key" "$_prop"`
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Current passphrase is incorrect?" >&2
|
||||
return 1
|
||||
fi
|
||||
_AUTH_SECRET=$_NEW_SECRET
|
||||
|
||||
echo Updating: [$_key] [$_prop]
|
||||
kstore update "$_key" "$_val" "$_prop"
|
||||
done
|
||||
|
||||
_kstoresecret-auto get
|
||||
if [ -n "$_AUTH_SECRET" ]; then
|
||||
_kstoresecret-auto del 2>&1 > /dev/null
|
||||
|
||||
_AUTH_SECRET=$_NEW_SECRET
|
||||
_kstoresecret-auto set
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "New passphrase saved in OS's keystore."
|
||||
fi
|
||||
fi
|
||||
|
||||
_AUTH_SECRET=$_NEW_SECRET
|
||||
}
|
||||
|
||||
function _kstoresecret-clear {
|
||||
unset _AUTH_SECRET
|
||||
_kstoresecret-auto del
|
||||
}
|
||||
|
||||
function _kstoreupdate {
|
||||
if [ -z "$1" ]; then
|
||||
__func_head "[key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
return 1
|
||||
fi
|
||||
_kstoreinit || return 1
|
||||
local _key _val _prop
|
||||
_key=`_kstorequote "$1"`
|
||||
_val=`_kstoreenc "$2"`
|
||||
_val=`_kstorequote "$_val"`
|
||||
_prop=`_kstorequote "${3:-$_KSTORE_DEF_PROP}"`
|
||||
_cond="key = '$_key' AND prop = '$_prop'"
|
||||
$_SQLITE "$_AUTH_DB" "UPDATE $_KSTORE_TABLE SET data = '$_val' WHERE $_cond;"
|
||||
}
|
||||
|
||||
function _kstoreadd {
|
||||
if [ -z "$1" ]; then
|
||||
__func_head "[key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
return 1
|
||||
fi
|
||||
_kstoreinit || return 1
|
||||
local _key _val _prop
|
||||
_key=`_kstorequote "$1"`
|
||||
_val=`_kstoreenc "$2"`
|
||||
_val=`_kstorequote "$_val"`
|
||||
_prop=`_kstorequote "${3:-$_KSTORE_DEF_PROP}"`
|
||||
$_SQLITE "$_AUTH_DB" \
|
||||
"INSERT INTO $_KSTORE_TABLE ( key, prop, data )
|
||||
VALUES( '$_key', '$_prop', '$_val' );"
|
||||
}
|
||||
|
||||
function _kstoreget {
|
||||
if [ -z "$1" ]; then
|
||||
__func_head "[key] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
return 1
|
||||
fi
|
||||
_kstoreinit || return 1
|
||||
local _key _prop _cond
|
||||
_key=`_kstorequote "$1"`
|
||||
_prop=`_kstorequote "${2:-$_KSTORE_DEF_PROP}"`
|
||||
_cond="key = '$_key' AND prop = '$_prop'"
|
||||
|
||||
$_SQLITE "$_AUTH_DB" "SELECT 1111 FROM $_KSTORE_TABLE WHERE $_cond;" | grep -q 1111
|
||||
if [ $? -eq 0 ]; then
|
||||
$_SQLITE -list "$_AUTH_DB" "SELECT ( data ) FROM $_KSTORE_TABLE WHERE $_cond;" | _kstoredec
|
||||
else
|
||||
echo "\"$1\" not found (prop: $_prop)" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function _kstoredel {
|
||||
if [ -z "$1" ]; then
|
||||
__func_head "[key] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
return 1
|
||||
fi
|
||||
_kstoreinit || return 1
|
||||
|
||||
local _CONFIRM _key _prop _cond
|
||||
_key=`_kstorequote "$1"`
|
||||
_prop=`_kstorequote "${2:-$_KSTORE_DEF_PROP}"`
|
||||
_cond="key = '$_key' AND prop = '$_prop'"
|
||||
|
||||
$_SQLITE "$_AUTH_DB" "SELECT 1111 FROM $_KSTORE_TABLE WHERE $_cond;" | grep -q 1111
|
||||
if [ $? -eq 0 ]; then
|
||||
$_SQLITE "$_AUTH_DB" "SELECT * FROM $_KSTORE_TABLE WHERE $_cond;"
|
||||
echo
|
||||
read -p "Delete this entry (yes/no)? " _CONFIRM
|
||||
if [ "$_CONFIRM" == "yes" ]; then
|
||||
$_SQLITE "$_AUTH_DB" "DELETE FROM $_KSTORE_TABLE WHERE $_cond;"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "deleted"
|
||||
fi
|
||||
else
|
||||
echo "action canceled"
|
||||
fi
|
||||
else
|
||||
echo "\"$1\" not found (prop: $_prop)" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
function _kstoredl-s3au {
|
||||
local p tmp _NAME
|
||||
|
||||
p="https://git.k8s.astropenguin.net/penguin/s3-arch-utils/raw/branch/master"
|
||||
_CSUM=$1
|
||||
_NAME=$2
|
||||
|
||||
tmp=$( mktemp )
|
||||
__download "$p/$_NAME" > $tmp
|
||||
sha256sum $tmp | grep -q "$_CSUM"
|
||||
if [ $? -eq 0 ]; then
|
||||
_NAME=$( basename "${_NAME//_/-}" .sh )
|
||||
mv $tmp "$RBASH_BIN/$_NAME"
|
||||
chmod +x "$RBASH_BIN/$_NAME"
|
||||
echo "> $RBASH_BIN/$_NAME"
|
||||
else
|
||||
echo "$_NAME: Signature mismatch"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function _kstoredl-kstorecred {
|
||||
local p tmp _NAME
|
||||
|
||||
_NAME="kstorecred"
|
||||
p="https://penguins-workspace.s3.ap-southeast-1.astropenguin.net/keystore/kstorecred.exe"
|
||||
_CSUM="031b4474b8eb8deafbb96df73b79f8b654fd3c2209f041fd34cb6f494791bcd4"
|
||||
|
||||
tmp=$( mktemp )
|
||||
__download "$p" > $tmp
|
||||
sha256sum $tmp | grep -q "$_CSUM"
|
||||
if [ $? -eq 0 ]; then
|
||||
mv $tmp "$RBASH_BIN/$_NAME"
|
||||
chmod +x "$RBASH_BIN/$_NAME"
|
||||
echo "> $RBASH_BIN/$_NAME"
|
||||
else
|
||||
echo "$_NAME: Signature mismatch"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function _kstoreinit-s3au {
|
||||
_kstoredl-s3au "574d106cdced150fa6e04a9437d356d8688035cb2c63a045fa0d4ead8b3ec941" "arch_delete_aws4.sh" || return 1
|
||||
_kstoredl-s3au "ce04b3f90b7d9a2578587c8ff841186810d977545943fb4a8234a6d6e9f7b568" "arch_delete_many_aws4.sh" || return 1
|
||||
_kstoredl-s3au "31709a639fab27b5ba071dd4c843fd3e90d4cea07bbb055c08c9720d31a8d11d" "arch_download_aws4.sh" || return 1
|
||||
_kstoredl-s3au "0bee6f925a41f496f66654062b49ea2a1cc55d877f4617d56bf91244aaf0be51" "arch_getacl_aws4.sh" || return 1
|
||||
_kstoredl-s3au "dcb89894e78351af702fabb521cf1cf6ca512db9cd4cf3c70631bb1e51ab9340" "arch_list_aws4.sh" || return 1
|
||||
_kstoredl-s3au "e90d197e4f965f88c30f8ff4b0a43ee4b5d656032781f1647770637fff0b9481" "arch_upload_aws4.sh" || return 1
|
||||
}
|
||||
|
||||
function _kstoreupload-db {
|
||||
local _T _W
|
||||
|
||||
_kstoreinit || return 1
|
||||
|
||||
_T=$( date +%Y%m%d%H%M%S )
|
||||
echo $_T > "$RBASH_HOME/keystore.latest"
|
||||
|
||||
which arch-upload-aws4 2>&1 > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
_kstoreinit-s3au
|
||||
fi
|
||||
|
||||
_kstoreenc $_AUTH_DB > "$RBASH_HOME/$_T.enc"
|
||||
arch-upload-aws4 "keystore/$_T.enc" "$RBASH_HOME/$_T.enc"
|
||||
arch-upload-aws4 "keystore/latest" "$RBASH_HOME/keystore.latest"
|
||||
|
||||
rm "$RBASH_HOME/$_T.enc"
|
||||
rm "$RBASH_HOME/keystore.latest"
|
||||
}
|
||||
|
||||
function _kstoredownload-db {
|
||||
local _T _DOMAIN _URL _TMP _CONFIRM
|
||||
kstore secret config || return 1
|
||||
|
||||
_DOMAIN="penguins-workspace.s3.ap-southeast-1.astropenguin.net"
|
||||
|
||||
_T=$( __download "https://$_DOMAIN/keystore/latest" )
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
_TMP=$( mktemp )
|
||||
__download "https://$_DOMAIN/keystore/$_T.enc" | _kstoredec > $_TMP
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
_T=$( $_SQLITE "$_TMP" "SELECT COUNT( * ) FROM $_KSTORE_TABLE" )
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -f "$_AUTH_DB" ]; then
|
||||
read -p "Replace existing db? (yes/no): " _CONFIRM
|
||||
if [ "$_CONFIRM" == "yes" ]; then
|
||||
_T="$_AUTH_DB.old.$( date +%Y%m%d%H%M%S )"
|
||||
mv "$_AUTH_DB" "$_T"
|
||||
mv $_TMP $_AUTH_DB
|
||||
echo "Original copy: $_T"
|
||||
else
|
||||
echo "action canceled"
|
||||
rm $_TMP
|
||||
fi
|
||||
else
|
||||
mv $_TMP $_AUTH_DB
|
||||
fi
|
||||
}
|
||||
|
||||
function _kstoresearch {
|
||||
local _termk _termp _cond
|
||||
_termk=`_kstorequote "$1"`
|
||||
_termp=`_kstorequote "$2"`
|
||||
_cond="key LIKE '%$_termk%' AND prop LIKE '%$_termp%'"
|
||||
|
||||
$_SQLITE -header -column "$_AUTH_DB" "SELECT key, prop, length( data ) FROM $_KSTORE_TABLE WHERE $_cond;"
|
||||
}
|
||||
|
||||
function _kstorelist {
|
||||
$_SQLITE -header -column "$_AUTH_DB" "SELECT key, prop, length( data ) FROM $_KSTORE_TABLE;"
|
||||
}
|
||||
|
||||
function _kstorequery {
|
||||
$_SQLITE "$_AUTH_DB" "$@"
|
||||
}
|
@ -1,217 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
declare -f kstore > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "kcontext depends on kstore"
|
||||
return 1
|
||||
fi
|
||||
|
||||
function kcontext {
|
||||
case $1 in
|
||||
k8s) shift; _kcontext-k8s "$@" ;;
|
||||
docker) shift; _kcontext-docker "$@" ;;
|
||||
s3-arch) shift; _kcontext-s3-arch "$@" ;;
|
||||
*)
|
||||
__func_head "k8s ..."
|
||||
__func_help "s3-arch ..."
|
||||
__func_help "docker ..."
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
return $?
|
||||
}
|
||||
|
||||
function _kcontext {
|
||||
local CUR=${COMP_WORDS[COMP_CWORD]}
|
||||
local SCOPE=${COMP_WORDS[COMP_CWORD-1]}
|
||||
|
||||
COMPREPLY=()
|
||||
|
||||
case "$SCOPE" in
|
||||
kcontext)
|
||||
COMPREPLY=( $(compgen -W "k8s docker s3-arch" -- $CUR) )
|
||||
;;
|
||||
k8s|s3-arch)
|
||||
COMPREPLY=( $(compgen -W "use del list save" -- $CUR) )
|
||||
return
|
||||
;;
|
||||
use|del)
|
||||
SCOPE=${COMP_WORDS[COMP_CWORD-2]}
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$SCOPE" in
|
||||
k8s|s3-arch)
|
||||
COMPREPLY=( $(compgen -W "$( kcontext $SCOPE list )" -- $CUR) )
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
complete -F _kcontext kcontext
|
||||
|
||||
function _kcontext-k8s {
|
||||
local _NAME _CONF
|
||||
case $1 in
|
||||
list)
|
||||
kstore query -list "SELECT SUBSTR( prop, 5 ) FROM $_KSTORE_TABLE WHERE key = 'kcontext' AND prop LIKE 'k8s.%'"
|
||||
return $?
|
||||
;;
|
||||
save)
|
||||
_NAME=$( kubectl config current-context )
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
kstore get "kcontext" "k8s.$_NAME" 2> /dev/null > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
read -p "Replace existing config for \"$_NAME\"? (y/n): " _CONFIRM
|
||||
if [ "$_CONFIRM" != "y" ]; then
|
||||
return 0
|
||||
fi
|
||||
kubectl config view --minify --flatten | kstore update "kcontext" - "k8s.$_NAME"
|
||||
return $?
|
||||
else
|
||||
kubectl config view --minify --flatten | kstore add "kcontext" - "k8s.$_NAME"
|
||||
return $?
|
||||
fi
|
||||
;;
|
||||
use)
|
||||
_NAME=$2
|
||||
if [ -z "$_NAME" ]; then
|
||||
echo "Please specify a context name" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
_CONF="$RBASH_HOME/k8s.conf"
|
||||
kstore get "kcontext" "k8s.$_NAME" > "$_CONF"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "No such context: $_NAME" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
chmod 600 "$_CONF"
|
||||
|
||||
echo $KUBECONFIG | grep "$_CONF" -q
|
||||
|
||||
case $OSTYPE in
|
||||
cygwin)
|
||||
_CONF=$( cygpath -w "$_CONF" )
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
export KUBECONFIG="$_CONF"
|
||||
else
|
||||
export KUBECONFIG="$_CONF:$KUBECONFIG"
|
||||
fi
|
||||
;;
|
||||
del)
|
||||
_NAME=$2
|
||||
if [ -z "$_NAME" ]; then
|
||||
echo "Please specify a context name" >&2
|
||||
return 1
|
||||
fi
|
||||
kstore get "kcontext" "k8s.$_NAME" 2> /dev/null > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
read -p "Delete context \"$_NAME\"? (y/n): " _CONFIRM
|
||||
if [ "$_CONFIRM" != "y" ]; then
|
||||
return 0
|
||||
fi
|
||||
kstore query "DELETE FROM $_KSTORE_TABLE WHERE key = 'kcontext' AND prop = 'k8s.$_NAME'"
|
||||
return $?
|
||||
else
|
||||
echo "No such context: $_NAME" >&2
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
__func_head "list"
|
||||
__func_help "save"
|
||||
__func_help "use NAME"
|
||||
__func_help "del NAME"
|
||||
;;
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
|
||||
function _kcontext-s3-arch {
|
||||
local _NAME _CONFIRM _URL _AUTH
|
||||
case $1 in
|
||||
list)
|
||||
kstore query -list "SELECT SUBSTR( prop, 16 ) FROM $_KSTORE_TABLE WHERE key = 'kcontext' AND prop LIKE 's3-arch.bucket.%'"
|
||||
return $?
|
||||
;;
|
||||
save)
|
||||
_NAME=$2
|
||||
if [ -z "$_NAME" ]; then
|
||||
echo "Please specify a context name" >&2
|
||||
return 1
|
||||
fi
|
||||
if [ -n "$ARCH_S3_BUCKET_URL" ] && [ -n "$ARCH_S3_AUTH" ]; then
|
||||
kstore get "kcontext" "s3-arch.bucket.$_NAME" 2> /dev/null > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
read -p "Replace existing config for \"$_NAME\"? (y/n): " _CONFIRM
|
||||
if [ "$_CONFIRM" != "y" ]; then
|
||||
return 0
|
||||
fi
|
||||
kstore update "kcontext" "$ARCH_S3_BUCKET_URL" "s3-arch.bucket.$_NAME"
|
||||
kstore update "kcontext" "$ARCH_S3_AUTH" "s3-arch.auth.$_NAME"
|
||||
return $?
|
||||
else
|
||||
kstore add "kcontext" "$ARCH_S3_BUCKET_URL" "s3-arch.bucket.$_NAME"
|
||||
kstore add "kcontext" "$ARCH_S3_AUTH" "s3-arch.auth.$_NAME"
|
||||
return $?
|
||||
fi
|
||||
else
|
||||
echo "No s3-arch settings can be found in env" >&2
|
||||
fi
|
||||
;;
|
||||
use)
|
||||
_NAME=$2
|
||||
if [ -z "$_NAME" ]; then
|
||||
echo "Please specify a context name" >&2
|
||||
return 1
|
||||
fi
|
||||
_URL=$( kstore get "kcontext" "s3-arch.bucket.$_NAME" 2> /dev/null )
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "No such context: $_NAME" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
_AUTH=$( kstore get "kcontext" "s3-arch.auth.$_NAME" 2> /dev/null )
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "No such context: $_NAME" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
export ARCH_S3_BUCKET_URL=$_URL
|
||||
export ARCH_S3_AUTH=$_AUTH
|
||||
;;
|
||||
del)
|
||||
_NAME=$2
|
||||
if [ -z "$_NAME" ]; then
|
||||
echo "Please specify a context name" >&2
|
||||
return 1
|
||||
fi
|
||||
kstore get "kcontext" "s3-arch.bucket.$_NAME" 2> /dev/null > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
read -p "Delete context \"$_NAME\"? (y/n): " _CONFIRM
|
||||
if [ "$_CONFIRM" != "y" ]; then
|
||||
return 0
|
||||
fi
|
||||
kstore query "DELETE FROM $_KSTORE_TABLE WHERE key = 'kcontext' AND prop = 's3-arch.bucket.$_NAME'"
|
||||
kstore query "DELETE FROM $_KSTORE_TABLE WHERE key = 'kcontext' AND prop = 's3-arch.auth.$_NAME'"
|
||||
return $?
|
||||
else
|
||||
echo "No such context: $_NAME" >&2
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
__func_head "list"
|
||||
__func_help "save NAME"
|
||||
__func_help "use NAME"
|
||||
__func_help "del NAME"
|
||||
;;
|
||||
esac
|
||||
return 1
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Written with the help of chatgpt o3-mini
|
||||
function klabels {
|
||||
local header=
|
||||
local padding=
|
||||
local trim_length=
|
||||
local line_text=
|
||||
local first_line=
|
||||
local max_key_length=0
|
||||
local max_label_length=0
|
||||
local key=
|
||||
local value=
|
||||
local filter_value="$1"
|
||||
local filter_key="$2"
|
||||
|
||||
while IFS= read -r line; do
|
||||
if [ -z "$header" ]; then
|
||||
header="$line"
|
||||
padding="${header//LABELS/}"
|
||||
padding="${padding//?/ }"
|
||||
echo "$header"
|
||||
trim_length=${#padding}
|
||||
continue
|
||||
fi
|
||||
|
||||
line_text="${line:0:trim_length}"
|
||||
first_line=
|
||||
IFS=',' read -ra labels <<< "${line:trim_length}"
|
||||
|
||||
# Calculate the maximum key length to align key=value pairs
|
||||
for label in "${labels[@]}"; do
|
||||
key="${label%%=*}"
|
||||
max_key_length=$(( ${#key} > max_key_length ? ${#key} : max_key_length ))
|
||||
done
|
||||
|
||||
# Loop through labels and align them
|
||||
for label in "${labels[@]}"; do
|
||||
key="${label%%=*}"
|
||||
value="${label#*=}"
|
||||
|
||||
if [ -n "$filter_key" ] && ! [[ "$key" == *$filter_key* ]] ; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ -n "$filter_value" ] && ! [[ "$value" == *$filter_value* ]] ; then
|
||||
continue
|
||||
fi
|
||||
|
||||
|
||||
# Format the label to align the '=' sign
|
||||
printf -v formatted_label "%-${max_key_length}s = %s" "$key" "$value"
|
||||
|
||||
if [ -z "$first_line" ]; then
|
||||
first_line=1
|
||||
|
||||
# Print a line separator based on the longest key length
|
||||
separator_length=$((max_key_length + trim_length))
|
||||
printf "%${separator_length}s\n" | tr ' ' "-"
|
||||
|
||||
echo "$line_text$formatted_label"
|
||||
else
|
||||
echo "$padding$formatted_label"
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
alias grepphp='grep -n --include=*.php'
|
||||
alias grepjs='grep -n --include=*.js'
|
||||
|
||||
function grept {
|
||||
if [[ -z "$1" ]]; then
|
||||
__func_head "TYPE GREP_ARGS"
|
||||
echo
|
||||
else
|
||||
CMD="grep --color=auto -n --include=*.$1"
|
||||
shift
|
||||
$CMD $@
|
||||
fi
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function grepo {
|
||||
grep --color=always "$1" . -r | awk '{ count++; print " ["count"] "$0 } '
|
||||
echo -n "Select number to open: "
|
||||
read num
|
||||
|
||||
IFS="
|
||||
"
|
||||
CHOICES=( `grep -n "$1" . -r | awk 'BEGIN{ FS=":" }{ print "notepad /g "$2" "$1 }'` )
|
||||
bash -c ${CHOICES[$(( num - 1 ))]}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function mkuserdirs {
|
||||
|
||||
local PKG_DIR i IFS=$'\n'
|
||||
for i in $( reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" \
|
||||
| grep "^ [A-Za-z ]\+" \
|
||||
| tr -d '\r' \
|
||||
| sed -e "s/.\+REG_EXPAND_SZ[ ]\+//g"
|
||||
); do
|
||||
|
||||
if [[ "$i" =~ .*"\\AppData\\".* ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ "$i" =~ "%USERPROFILE".* ]]; then
|
||||
i=$USERPROFILE${i/\%USERPROFILE\%/}
|
||||
fi
|
||||
|
||||
ln -vs "$( cygpath "$i" )" $HOME/
|
||||
done
|
||||
|
||||
# Package Directory
|
||||
PKG_DIR=$( cygpath "$APPDATA/../Local/Packages" )
|
||||
if [ -d "$PKG_DIR" ]; then
|
||||
ln -vs "$PKG_DIR" $HOME/
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function init-mintty {
|
||||
cat <<___MINTTY___ > $HOME/.minttyrc
|
||||
BoldAsFont=no
|
||||
CursorType=block
|
||||
Columns=120
|
||||
Rows=30
|
||||
ForegroundColour=131,148,150
|
||||
BackgroundColour=0,20,43
|
||||
CursorColour=220,50,47
|
||||
Black=7,54,66
|
||||
BoldBlack=0,43,54
|
||||
Red=220,50,47
|
||||
BoldRed=203,75,22
|
||||
Green=133,153,0
|
||||
BoldGreen=88,110,117
|
||||
Yellow=181,137,0
|
||||
BoldYellow=101,123,131
|
||||
Blue=38,139,210
|
||||
BoldBlue=131,148,150
|
||||
Magenta=211,54,130
|
||||
BoldMagenta=108,113,196
|
||||
Cyan=42,161,152
|
||||
BoldCyan=147,161,161
|
||||
White=238,232,213
|
||||
BoldWhite=253,246,227
|
||||
Transparency=low
|
||||
Locale=C
|
||||
Charset=UTF-8
|
||||
Font=Consolas
|
||||
Scrollbar=none
|
||||
FontHeight=14
|
||||
___MINTTY___
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
for i in $( find /opt/ -maxdepth 1 -name node-v\*-win-x64 -type d ); do
|
||||
echo " Selected node binary @$i"
|
||||
export PATH=$PATH:"$i"
|
||||
break
|
||||
done
|
||||
|
||||
for i in $( find /opt/ -maxdepth 1 -name nmap-\* -type d ); do
|
||||
echo " Selected nmap binary @$i"
|
||||
export PATH=$PATH:"$i"
|
||||
break
|
||||
done
|
||||
|
||||
if [ -n "$FrameworkVersion" ]; then
|
||||
alias vsshell='echo "FrameworkVersion $FrameworkVersion"'
|
||||
return
|
||||
fi
|
||||
|
||||
BAT_DIR=~/.local/lib/bat
|
||||
mkdir -p $BAT_DIR
|
||||
|
||||
VS_SHELL_BAT=$BAT_DIR/vs-env.bat
|
||||
|
||||
function vsshell {
|
||||
_SHELL=$( cygpath -w -a $VS_SHELL_BAT )
|
||||
cmd /c "$_SHELL"
|
||||
exit
|
||||
}
|
||||
|
||||
if [ -f "$VS_SHELL_BAT" ]; then
|
||||
_PATH=$( cygpath "$( grep -o "^@REM FILE_PATH: .\+" "$VS_SHELL_BAT" | cut -c 17- )" )
|
||||
if [ ! -f "$_PATH" ]; then
|
||||
START_MENU="$( cygpath $ProgramData )/Microsoft/Windows/Start Menu/"
|
||||
|
||||
_PATH=$( find "$START_MENU" -name "*Command Prompt*" | grep "Visual Studio" | grep x64 | grep Native | xargs -I % readshortcut % -r | grep -o "\"\([^\"]\+\)\"" )
|
||||
|
||||
echo "@echo off" > "$VS_SHELL_BAT"
|
||||
echo "@REM FILE_PATH: ${_PATH:1:-1}" >> "$VS_SHELL_BAT"
|
||||
echo "CALL $_PATH" >> "$VS_SHELL_BAT"
|
||||
echo "START $( where mintty ) -i /Cygwin-Terminal.ico -" >> "$VS_SHELL_BAT"
|
||||
fi
|
||||
fi
|
@ -1,39 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function git-config-as {
|
||||
local SHA NAME EMAIL
|
||||
SHA=$1
|
||||
if [ -z "$1" ]; then
|
||||
SHA=HEAD
|
||||
fi
|
||||
NAME=$( git log $SHA -1 --pretty=format:%aN )
|
||||
EMAIL=$( git log $SHA -1 --pretty=format:%ae )
|
||||
|
||||
git config user.name "$NAME"
|
||||
git config user.email "$EMAIL"
|
||||
echo "Configured as \"$NAME <$EMAIL>\""
|
||||
}
|
||||
|
||||
function git-amend-author {
|
||||
NAME=$( git config user.name )
|
||||
EMAIL=$( git config user.email )
|
||||
|
||||
git commit --amend --no-edit --author "$NAME <$EMAIL>"
|
||||
}
|
||||
|
||||
|
||||
if [ ! -f "$HOME/.gitconfig" ]; then
|
||||
cat << ___CONF___ > "$HOME/.gitconfig"
|
||||
[alias]
|
||||
la = log --graph --full-history --date-order --all --pretty=format:'%Cred%h%Creset %ad %C(bold blue)[%an]%Creset | %C(white)%s%Creset %C(yellow)%d%Creset' --date=relative
|
||||
|
||||
[color]
|
||||
ui = auto
|
||||
[core]
|
||||
excludesfile = ~/gitignore
|
||||
[push]
|
||||
default = tracking
|
||||
[credential]
|
||||
helper = store
|
||||
___CONF___
|
||||
fi
|
@ -1,21 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function dumpcolors {
|
||||
# Reference: https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
|
||||
T='gYw' # The test text
|
||||
|
||||
echo -e "\n 40m 41m 42m 43m\
|
||||
44m 45m 46m 47m";
|
||||
|
||||
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
|
||||
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
|
||||
' 36m' '1;36m' ' 37m' '1;37m';
|
||||
do FG=${FGs// /}
|
||||
echo -en " $FGs \033[$FG $T "
|
||||
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
|
||||
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
|
||||
done
|
||||
echo;
|
||||
done
|
||||
echo
|
||||
}
|
5
deprecated/bash/amuleComplete.sh
Normal file
5
deprecated/bash/amuleComplete.sh
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
cd /opt/utils
|
||||
fileName=$(java Main_mod $1)
|
||||
cd /media/Misc/Temp
|
||||
mv $1 $fileName
|
496
deprecated/php/ByteArray.php
Normal file
496
deprecated/php/ByteArray.php
Normal file
@ -0,0 +1,496 @@
|
||||
<?php
|
||||
class ERROR {
|
||||
const INVALID_DATA = 1;
|
||||
const UNDEFINED_DATA = 2;
|
||||
const TYPE_MISSMATCH = 3;
|
||||
|
||||
const READ_ONLY = 11;
|
||||
const GREATER_COMPARATIVE = 21;
|
||||
|
||||
const EOF = 100;
|
||||
|
||||
function __construct($type, $a, $b)
|
||||
{
|
||||
throw new Exception($type);
|
||||
}
|
||||
}
|
||||
|
||||
class ByteArray extends ArrayObject {
|
||||
private $position = 0;
|
||||
public function ByteArray($str = NULL) {
|
||||
if(is_string($str)) {
|
||||
$length = strlen($str);
|
||||
for($i = 0; $i < $length; $i ++)
|
||||
$this[] = ord($str[$i]);
|
||||
}
|
||||
}
|
||||
//<editor-fold defaultstate="collapsed" desc="Cryptographic">
|
||||
public function encrypt() {
|
||||
|
||||
}
|
||||
public function decrypt() {
|
||||
|
||||
}
|
||||
//</editor-fold>
|
||||
//<editor-fold defaultstate="collapsed" desc="GET,SET,OFFSET.SET">
|
||||
public function __get($prop) {
|
||||
switch($prop) {
|
||||
case 'length':
|
||||
return count($this);
|
||||
break;
|
||||
case 'position':
|
||||
return $this->position;
|
||||
break;
|
||||
case 'byteAvailable' :
|
||||
return count($this) - $this->position;
|
||||
break;
|
||||
default :
|
||||
return "Property($prop) is undefined";
|
||||
}
|
||||
}
|
||||
public function __set($prop, $val) {
|
||||
try {
|
||||
switch ($prop) {
|
||||
case 'length':
|
||||
if (is_int($val)) {
|
||||
$l = count($this);
|
||||
if ($val < $l) {
|
||||
if ($val > -1) {
|
||||
while ($val < count($this)) {
|
||||
$this->offsetUnset(count($this) - 1);
|
||||
}
|
||||
} else {
|
||||
new ERROR(ERROR::INVALID_DATA, "length($val)");
|
||||
}
|
||||
} else {
|
||||
while (count($this) < $val)
|
||||
$this[] = 0;
|
||||
}
|
||||
} else {
|
||||
new ERROR(ERROR::TYPE_MISSMATCH, "($val)", 'an integer');
|
||||
}
|
||||
break;
|
||||
case 'position':
|
||||
if (is_int($val)) {
|
||||
$l = count($this);
|
||||
if ($val < $l) {
|
||||
if ($val > -1) {
|
||||
$this->position = $val;
|
||||
} else {
|
||||
new ERROR(ERROR::INVALID_DATA, "length($val)");
|
||||
}
|
||||
} else {
|
||||
new ERROR(ERROR::GREATER_COMPARATIVE, "Position($val)", "length($l)");
|
||||
}
|
||||
} else {
|
||||
new ERROR(ERROR::TYPE_MISSMATCH, "($val)", 'an integer');
|
||||
}
|
||||
break;
|
||||
case 'byteAvailable' :
|
||||
new ERROR(ERROR::READ_ONLY, "Property($prop)");
|
||||
break;
|
||||
default :
|
||||
new ERROR(ERROR::UNDEFINED_DATA, "property($prop)");
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
echo $e;
|
||||
}
|
||||
}
|
||||
public function offsetSet($i, $val) {
|
||||
try {
|
||||
if(is_int($val)) {
|
||||
if($i > -1) {
|
||||
while(count($this) < $i)
|
||||
$this[] = 0;
|
||||
parent::offsetSet($i, $val & 0xff);
|
||||
} else if($i == NULL) {
|
||||
parent::offsetSet(count($this), $val & 0xff);
|
||||
} else {
|
||||
new ERROR(ERROR::TYPE_MISSMATCH, "index($val)");
|
||||
}
|
||||
} else {
|
||||
new ERROR(ERROR::TYPE_MISSMATCH, "($val)", 'an integer');
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
echo $e;
|
||||
}
|
||||
}
|
||||
//</editor-fold>
|
||||
public function compress() {
|
||||
$str = gzcompress($this->save());
|
||||
$this->clear();
|
||||
$this->ByteArray($str);
|
||||
}
|
||||
public function deflate() {
|
||||
$str = gzuncompress($this->save());
|
||||
$this->clear();
|
||||
$this->ByteArray($str);
|
||||
}
|
||||
public function save() {
|
||||
$str = '';
|
||||
foreach($this as $i)
|
||||
$str .= chr($i);
|
||||
return $str;
|
||||
}
|
||||
public function clear() {
|
||||
$this->length = 0;
|
||||
$this->position = 0;
|
||||
}
|
||||
// <editor-fold defaultstate="collapsed" desc="ReadUtils">
|
||||
public function readBoolean() {
|
||||
$p = $this->getPos();
|
||||
if ($p)
|
||||
return (bool) $this[$p];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
public function readByte() {
|
||||
//Returns -128 ~ 127
|
||||
$p = $this->getPos();
|
||||
if(is_int($p)) {
|
||||
$p = $this[$p];
|
||||
return $p < 128 ? $p : $p - 256;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
public function readBytes(ByteArray $b, $p = 0, $l = 0) {
|
||||
try {
|
||||
if (($this->position + $l) < count($this)) {
|
||||
if ($l > 0 || ($l = count($this))) {
|
||||
for ($i = 0; $i < $l; $i++)
|
||||
$b[$p + $i] = $this->readByte();
|
||||
} else {
|
||||
new ERROR(ERROR::UNDEFINED_DATA);
|
||||
}
|
||||
} else {
|
||||
new ERROR(ERROR::EOF);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo $e;
|
||||
}
|
||||
}
|
||||
public function readDouble() {
|
||||
//Reads an IEEE 754 double-precision (64-bit) floating-point number from the byte stream.
|
||||
$s = $this->tobin($this->readByte())
|
||||
.$this->tobin($this->readByte())
|
||||
.$this->tobin($this->readByte())
|
||||
.$this->tobin($this->readByte())
|
||||
.$this->tobin($this->readByte())
|
||||
.$this->tobin($this->readByte())
|
||||
.$this->tobin($this->readByte())
|
||||
.$this->tobin($this->readByte());
|
||||
if($s*1 == 0)
|
||||
return 0;
|
||||
return $this->decodeIEEE($s);
|
||||
}
|
||||
|
||||
public function readFloat() {
|
||||
//Reads an IEEE 754 single-precision (32-bit) floating-point number from the byte stream.
|
||||
$s = $this->tobin($this->readByte())
|
||||
.$this->tobin($this->readByte())
|
||||
.$this->tobin($this->readByte())
|
||||
.$this->tobin($this->readByte());
|
||||
if($s*1 == 0)
|
||||
return 0;
|
||||
return $this->decodeIEEE($s);
|
||||
}
|
||||
public function readInt() {
|
||||
//Returns -2147483648 ~ 2147483647
|
||||
if(($s = hexdec($this->tohex($this->readByte())
|
||||
.$this->tohex($this->readByte())
|
||||
.$this->tohex($this->readByte())
|
||||
.$this->tohex($this->readByte())))
|
||||
> 2147483647)
|
||||
$s -= 4294967296;
|
||||
return $s;
|
||||
}
|
||||
public function readMultiByte($length, $charSet) {
|
||||
}
|
||||
public function readShort() {
|
||||
if(($s = hexdec($this->tohex($this->readByte())
|
||||
.$this->tohex($this->readByte())))
|
||||
> 32767)
|
||||
$s -= 65536;
|
||||
return $s;
|
||||
}
|
||||
public function readUnsignedByte() {
|
||||
return hexdec($this->tohex($this->readByte()));
|
||||
}
|
||||
public function readUnsignedInt() {
|
||||
return hexdec($this->tohex($this->readByte())
|
||||
.$this->tohex($this->readByte())
|
||||
.$this->tohex($this->readByte())
|
||||
.$this->tohex($this->readByte()));
|
||||
}
|
||||
public function readUnsignedShort() {
|
||||
return hexdec($this->tohex($this->readByte())
|
||||
.$this->tohex($this->readByte())
|
||||
.$this->tohex($this->readByte())
|
||||
.$this->tohex($this->readByte()));
|
||||
}
|
||||
public function readUTF() {
|
||||
}
|
||||
public function readUTFBytes() {
|
||||
}
|
||||
// </editor-fold>
|
||||
// <editor-fold defaultstate="collapsed" desc="WriteUtils">
|
||||
public function writeBoolean($b) {
|
||||
try {
|
||||
if (is_bool($b)) {
|
||||
new ERROR(ERROR::TYPE_MISSMATCH, "($b)");
|
||||
} else {
|
||||
if ($this->position < count($this))
|
||||
$b ? ($this[$this->getPos()] = 1) : ($this[$this->getPos()] = 0);
|
||||
else
|
||||
$b ? ($this[] = 1) : ($this[] = 0);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo $e;
|
||||
}
|
||||
}
|
||||
public function writeByte($b) {
|
||||
if($this->position < count($this)) {
|
||||
$this[$this->getPos()] = $b;
|
||||
} else {
|
||||
$this[] = $b;
|
||||
$this->getPos();
|
||||
}
|
||||
}
|
||||
public function writeBytes(ByteArray $b, $p = 0, $l = 0) {
|
||||
try {
|
||||
if ($l > 0 || ($l = count($b))) {
|
||||
for ($i = 0; $i < $l; $i++)
|
||||
$this->writeByte($b[$p + $i]);
|
||||
} else {
|
||||
new ERROR(ERROR::UNDEFINED_DATA);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo $e;
|
||||
}
|
||||
}
|
||||
public function writeDouble($num) {
|
||||
if($num == 0) {
|
||||
$num = str_pad('', 64, '0');
|
||||
} else {
|
||||
$num = $this->encodeIEEE($num, 8)."\n";
|
||||
}
|
||||
for($i = 0; $i < 64; $i += 8)
|
||||
$this->writeByte(bindec(substr($num, $i, 8)));
|
||||
}
|
||||
public function writeFloat($num) {
|
||||
if($num == 0) {
|
||||
$num = str_pad('', 32, '0');
|
||||
} else {
|
||||
$num = $this->encodeIEEE($num, 4)."\n";
|
||||
}
|
||||
for($i = 0; $i < 32; $i += 8)
|
||||
$this->writeByte(bindec(substr($num, $i, 8)));
|
||||
}
|
||||
public function writeInt($num) {
|
||||
$this->writeByte($num >> 24 & 0xFF);
|
||||
$this->writeByte($num >> 16 & 0xFF);
|
||||
$this->writeByte($num >> 8 & 0xFF);
|
||||
$this->writeByte($num & 0xFF);
|
||||
}
|
||||
public function writeMultiByte($length, $charSet) {
|
||||
}
|
||||
public function writeShort($num) {
|
||||
$this->writeByte($num >> 8 & 0xFF);
|
||||
$this->writeByte($num & 0xFF);
|
||||
}
|
||||
public function writeUnsignedInt($num) {
|
||||
$this->writeByte($num >> 56 & 0xFF);
|
||||
$this->writeByte($num >> 48 & 0xFF);
|
||||
$this->writeByte($num >> 40 & 0xFF);
|
||||
$this->writeByte($num >> 32 & 0xFF);
|
||||
$this->writeByte($num >> 24 & 0xFF);
|
||||
$this->writeByte($num >> 16 & 0xFF);
|
||||
$this->writeByte($num >> 8 & 0xFF);
|
||||
$this->writeByte($num & 0xFF);
|
||||
}
|
||||
public function writeUTF() {
|
||||
}
|
||||
public function writeUTFBytes() {
|
||||
}
|
||||
//</editor-fold>
|
||||
//<editor-fold defaultstate="collapsed" desc="IEEE convertions">
|
||||
private function decodeIEEE($str) {
|
||||
$s = $str[0] ? -1:1;
|
||||
if(($l = strlen($str)) == 8) {
|
||||
$e = bindec(substr($str, 1, 3)) - 3;
|
||||
$m = substr($str, 4, 8);
|
||||
} else if($l == 16) {
|
||||
|
||||
} else if($l == 32) {
|
||||
$e = bindec(substr($str, 1, 8)) - 127;
|
||||
$m = '1'.substr($str, 9, 32);
|
||||
} else if($l == 64) {
|
||||
$e = bindec(substr($str, 1, 11)) - 1023;
|
||||
$m = '1'.substr($str, 12, 64);
|
||||
}
|
||||
if((++ $e) > 0) {
|
||||
$m1 = substr($m, 0, $e);
|
||||
$m2 = substr($m, $e);
|
||||
} else {
|
||||
while($e < 0) {
|
||||
$m = '0'.$m;
|
||||
$e ++;
|
||||
}
|
||||
$m1 = 0;
|
||||
$m2 = $m;
|
||||
}
|
||||
$str = 0;
|
||||
$e = strlen($m1);
|
||||
for($i = 0; $i < $e; $i ++) {
|
||||
if($m1[$i]) {
|
||||
$str += $m1[$i]*pow(2, ($e - 1) - $i);
|
||||
}
|
||||
}
|
||||
$e = strlen($m2);
|
||||
for($i = 0; $i < $e; $i ++) {
|
||||
if($m2[$i]) {
|
||||
$str += $m2[$i]*pow(2, -($i + 1));
|
||||
}
|
||||
}
|
||||
return $str*$s;
|
||||
}
|
||||
private function encodeIEEE($num, $byte) {
|
||||
try {
|
||||
if(is_numeric($num)) {
|
||||
$s = $num > 0 ? 0:1;
|
||||
$m1 = $s ? -1*$num : 1*$num;
|
||||
$num = explode('.', $num);
|
||||
$m1 = $num[0]*1;
|
||||
if(count($num) > 1)
|
||||
$m2 = '0.'.$num[1];
|
||||
else $m2 = '0';
|
||||
if($byte == 1) {
|
||||
|
||||
} else if($byte == 2) {
|
||||
|
||||
} else if($byte == 4) {
|
||||
$e = 8;
|
||||
$f = 23;
|
||||
$b = 127;
|
||||
} else if($byte == 8) {
|
||||
$e = 11;
|
||||
$f = 52;
|
||||
$b = 1023;
|
||||
} else {
|
||||
new ERROR(ERROR::INVALID_DATA, "byte($byte)");
|
||||
}
|
||||
$num = '';
|
||||
if($m1 > 1) {
|
||||
$m1 = decbin($m1);
|
||||
$e = str_pad(decbin(strlen($m1) - 1 + $b), $e, '0', STR_PAD_LEFT);
|
||||
} else if($m1 == 1) {
|
||||
$e = '0'.str_pad('', $e - 1, '1');
|
||||
}
|
||||
$num .= $m1;
|
||||
$f *= 2;
|
||||
for($i = 0; $i < $f; $i ++) {
|
||||
$m2 *= 2;
|
||||
if($m2 >= 1) {
|
||||
$num .= '1';
|
||||
$m2 -= 1;
|
||||
} else {
|
||||
$num .= '0';
|
||||
}
|
||||
}
|
||||
if($m1 == 0) {
|
||||
for($m1 = 0; $num[0] == '0'; $m1 --) {
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
$e = str_pad(decbin($m1 + $b), $e, '0', STR_PAD_LEFT);
|
||||
}
|
||||
$num = substr($num, 1, $f *= .5);
|
||||
$num || ($num = str_pad('', $f, '0'));
|
||||
return "$s$e$num";
|
||||
} else {
|
||||
new ERROR(ERROR::INVALID_DATA, $num);
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
echo $e;
|
||||
}
|
||||
}
|
||||
//</editor-fold>
|
||||
private function getPos() {
|
||||
|
||||
try {
|
||||
if ($this->position < count($this))
|
||||
return $this->position++;
|
||||
else
|
||||
new ERROR(ERROR::EOF);
|
||||
} catch (Exception $e) {
|
||||
echo $e;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
private function tobin($num) {
|
||||
$num = $num < 0 ? $num + 256:$num;
|
||||
$num = decbin($num);
|
||||
while(strlen($num) != 8) {
|
||||
$num = '0'.$num;
|
||||
}
|
||||
return $num;
|
||||
}
|
||||
private function tohex($num) {
|
||||
return (($num = ($num < 0) ? $num + 256:$num) < 16) ? '0'.dechex($num):dechex($num);
|
||||
}
|
||||
}
|
||||
//* Tests
|
||||
$a = new ByteArray();
|
||||
$a->writeInt(12345);
|
||||
$a->writeShort(11223);
|
||||
$a->writeUnsignedInt(1125434357);
|
||||
$a->position = 0;
|
||||
echo "ReadInt: ";
|
||||
echo $a->readInt()."\n";
|
||||
echo "ReadShort: ";
|
||||
echo $a->readShort()."\n";
|
||||
echo "readUnsignedShort: ";
|
||||
echo $a->readUnsignedInt()."\n";
|
||||
$a->position = 0;
|
||||
$a->writeDouble(1);
|
||||
$a->writeDouble(0);
|
||||
$a->writeDouble(1.00123);
|
||||
$a->writeDouble(0.2156);
|
||||
$a->writeDouble(100);
|
||||
$a->writeDouble(1012.1234);
|
||||
|
||||
$a->writeFloat(2);
|
||||
$a->writeFloat(1);
|
||||
$a->writeFloat(0);
|
||||
$a->writeFloat(0.00123);
|
||||
$a->writeFloat(23.2156);
|
||||
$a->writeFloat(150);
|
||||
$a->writeFloat(132.1);
|
||||
$a->position = 0;
|
||||
echo "readDouble: ";
|
||||
echo $a->readDouble()."\n";
|
||||
echo "readDouble: ";
|
||||
echo $a->readDouble()."\n";
|
||||
echo "readDouble: ";
|
||||
echo $a->readDouble()."\n";
|
||||
echo "readDouble: ";
|
||||
echo $a->readDouble()."\n";
|
||||
echo "readDouble: ";
|
||||
echo $a->readDouble()."\n";
|
||||
echo "readDouble: ";
|
||||
echo $a->readDouble()."\n";
|
||||
|
||||
echo "readFloat: ";
|
||||
echo $a->readFloat()."\n";
|
||||
echo "readFloat: ";
|
||||
echo $a->readFloat()."\n";
|
||||
echo "readFloat: ";
|
||||
echo $a->readFloat()."\n";
|
||||
echo "readFloat: ";
|
||||
echo $a->readFloat()."\n";
|
||||
echo "readFloat: ";
|
||||
echo $a->readFloat()."\n";
|
||||
echo "readFloat: ";
|
||||
echo $a->readFloat()."\n";
|
||||
|
||||
//*/
|
||||
?>
|
55
php/astropenguin/botanical/Args.php
Normal file
55
php/astropenguin/botanical/Args.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace astropenguin\botanical;
|
||||
use ArrayObject;
|
||||
|
||||
class Args
|
||||
{
|
||||
//parseOptions utilitiese by tgckpg
|
||||
static function PARSE ( $argStream, $handler )
|
||||
{
|
||||
//Chop first useless argument -- argv[0]
|
||||
array_shift ( $argStream ) ;
|
||||
//Initiate ArrayObject for iterator
|
||||
$arrayobject = new ArrayObject ( $argStream ) ;
|
||||
//Initiate iterator for iteration
|
||||
$iterator = $arrayobject->getIterator();
|
||||
|
||||
//If options is set first
|
||||
if( $iterator->valid() && preg_match ( '/^-\w$/', $iterator->current() ) )
|
||||
{
|
||||
//iterate through whole argument stream
|
||||
for ( ; $iterator->valid(); $iterator->next() )
|
||||
{
|
||||
//Check if reached next option
|
||||
if( preg_match ( '/^-\w$/', $opts = $iterator->current() ) )
|
||||
{
|
||||
//Get current options
|
||||
$currOpt = $opts;
|
||||
//echo "$currOpt\n";
|
||||
//Test if next stream is an option
|
||||
for ( $iterator->next(); $iterator->valid(); $iterator->next() )
|
||||
{
|
||||
if ( preg_match ( '/^-\w$/', $opts = $iterator->current() ) )
|
||||
{
|
||||
//echo "$currOpt $opts\n";
|
||||
$handler($currOpt);
|
||||
$currOpt = $opts;
|
||||
} else break;
|
||||
//var_dump($iterator->valid());
|
||||
}
|
||||
}//End if
|
||||
//echo "$currOpt $opts\n";
|
||||
$handler($currOpt, $opts);
|
||||
//A temporary fix for infinite loop
|
||||
if(!$iterator->valid()) break;
|
||||
}// End for
|
||||
}
|
||||
// If option is not set first.
|
||||
else
|
||||
{
|
||||
//Try other approach.
|
||||
}
|
||||
// End if
|
||||
}
|
||||
}
|
31
php/astropenguin/package.php
Normal file
31
php/astropenguin/package.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
# ########################################
|
||||
# File: package.php
|
||||
# Description:
|
||||
# Namespace Package Loader
|
||||
#
|
||||
# Created on: 22 July 2014
|
||||
# Last Modified: Tue 22 Jul 2014 02:37:14 PM HKT
|
||||
# by: penguin
|
||||
# ##################
|
||||
|
||||
IF( !function_exists( '___astropenguin_autoload' ) ):
|
||||
|
||||
define( "_APPATH_", dirname( __FILE__ ) . '/' );
|
||||
|
||||
function ___astropenguin_autoload( $classname )
|
||||
{
|
||||
if( strncmp( $classname, 'astropenguin\\', 12 ) === 0 )
|
||||
{
|
||||
$classfile = str_replace( '\\', '/', substr( $classname, 12 ) );
|
||||
$result = @include_once _APPATH_ . $classfile . '.php';
|
||||
if( !$result )
|
||||
{
|
||||
trigger_error( "Failed to include $classfile" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( '___astropenguin_autoload' );
|
||||
|
||||
ENDIF;
|
58
php/pkgstat.php
Normal file
58
php/pkgstat.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
function delUponExit()
|
||||
{
|
||||
if(is_file('/tmp/php.apt_history.log'))
|
||||
unlink('/tmp/php.apt_history.log');
|
||||
}
|
||||
|
||||
register_shutdown_function('delUponExit');
|
||||
|
||||
$i = 1;
|
||||
exec("ls /var/log/apt/history.log.*.gz", $list);
|
||||
|
||||
foreach($list as $entry)
|
||||
{
|
||||
$lines = gzfile($entry);
|
||||
file_put_contents("/tmp/php.apt_history.log", $lines, FILE_APPEND);
|
||||
}
|
||||
|
||||
$list = null;
|
||||
exec("cat /var/log/apt/history.log >> /tmp/php.apt_history.log");
|
||||
exec('cat /tmp/php.apt_history.log |egrep --regexp=\'^Commandline:\sapt-get\s[(install)(remove)(purge)]\'|awk \'{print $3" "$4}\'', $list);
|
||||
|
||||
$i = 0; $j = 0;
|
||||
|
||||
foreach($list as $entry)
|
||||
{
|
||||
$history=explode(" ", $entry);
|
||||
if($history[0] == "autoremove" || $history[0] == "upgrade")continue;
|
||||
$history[0] == "install" ? ($packages[$history[1]]=true):($packages[$history[1]]=false);
|
||||
}
|
||||
|
||||
foreach($packages as $package => $stat)
|
||||
{
|
||||
$stat ? ($ipackage[$i ++] = $package):($rpackage[$j ++] = $package);
|
||||
}
|
||||
|
||||
$i = sizeOf($ipackage);
|
||||
$j = sizeOf($rpackage);
|
||||
|
||||
$l = $i > $j ? $i:$j;
|
||||
|
||||
echo "Custom package activities(apt-get):\n";
|
||||
echo "+---------------------------------------------------------+\n";
|
||||
echo "| Package(s) installed | Package(s) removed |\n";
|
||||
echo "|----------------------------+----------------------------|\n";
|
||||
|
||||
$ll = .5*(strlen("+---------------------------------------------------------+") - 3);
|
||||
|
||||
for($k = 0; $k < $l; $k ++) {
|
||||
$il = str_pad($k < $i ? $ipackage[$k]:"", $ll, " ", STR_PAD_BOTH);
|
||||
$rl = str_pad($k < $j ? $rpackage[$k]:"", $ll, " ", STR_PAD_BOTH);
|
||||
|
||||
|
||||
echo "|$il|$rl|\n";
|
||||
}
|
||||
|
||||
echo "+---------------------------------------------------------+\n";
|
@ -117,8 +117,7 @@ class RegReplace:
|
||||
sys.stdout.write( "\033[K" ) # Clear line
|
||||
sys.stdout.write( "%s ... %s" % ( bb[ bb_i ], root ) )
|
||||
|
||||
actions = self._compile_actions( root, dirs )
|
||||
actions.extend( self._compile_actions( root, files ) )
|
||||
actions = self._compile_actions( root, files )
|
||||
|
||||
sys.stdout.write("\r") # Goto line start
|
||||
sys.stdout.write( "\033[F" ) # Move up
|
||||
|
Loading…
Reference in New Issue
Block a user