From a4ef3fcd47f43a8b08de9d1d72ad2e8793f0b434 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 12 Sep 2016 23:31:53 +0100 Subject: [PATCH] Bed --- etc/profile.d/functions | 47 ++++++++++++++++++++------- etc/profile.d/mac.sh | 14 ++++----- lib/php/db/shell.php | 70 ++++++++++++++++++++--------------------- 3 files changed, 77 insertions(+), 54 deletions(-) diff --git a/etc/profile.d/functions b/etc/profile.d/functions index d1bb2771..5ab9ec46 100644 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -200,16 +200,6 @@ ls_tree() { tree -tDphug } -find_sort_mtime() { - ( - if [ -n "$DARWIN" ]; then - find $@ -type f -exec stat -f '%m'$'\t''%N' {} \; - else - find $@ -type f -printf "%T@\t%p\n" | sed 's/^\([0-9]\+\)\.[0-9]\+/\1/' - fi - ) | sort -k1 -n | cut -f 2 -} - replace_tag_content() { declare tag; tag="$1"; shift declare content; content="$@" @@ -594,6 +584,41 @@ url2nc() { ' } + function ls_users() { - cat /etc/passwd + case "$OSTYPE" in + darwin*) + dscacheutil -q user \ + | perl -ne '/^\w+:\s+(.*)?$/; push @_,$1; print join(":",$_[0],"*",@_[2,3,6,4,5])."\n" and @_=() if /^\s*$/' \ + | sort -u \ + | sort -t : -k3,4 -n \ + ; + ;; + *) + grep '^[^#:]\+:' /etc/passwd | sort -u | sort -t : -k3,4 -n + ;; + esac +} + +function reverse() { perl -e 'print reverse <>'; } +function epoch2date() { perl -M'POSIX strftime' -e 'e2d($ARGV[0]) and exit if @ARGV; while(<>){e2d($_)}; sub e2d(){local $_=shift;s/^(\d+)/strftime("%Y-%m-%d %H:%M:%S",localtime($1))/e; print $_}' $@; } +#function epoch2date() { perl -M'POSIX strftime' -e 'e2d while<>; sub e2d(){local $_=shift;s/^(\d+)/strftime("%Y-%m-%d %H:%M:%S",localtime($1))/e; print $_}' $@; } + +find_sort_mtime() { + ( + local find_args="$@" + [ -z "$find_args" ] && args="." + + case "$OSTYPE" in + darwin*) + find $find_args -type f -exec stat -f '%m'$'\t''%N' {} \; + ;; + *) + find $@ -type f -printf "%T@\t%p\n" | sed 's/^\([0-9]\+\)\.[0-9]\+/\1/' + ;; + esac + + ) | sort -k1 -n $sort_args | epoch2date + # strftime "%a %b %e %H:%M:%S %Y" } + diff --git a/etc/profile.d/mac.sh b/etc/profile.d/mac.sh index cb4cf145..5b3913e1 100644 --- a/etc/profile.d/mac.sh +++ b/etc/profile.d/mac.sh @@ -10,7 +10,6 @@ mac_pbcopy() { # Darwin only ! # ############################################################################## -#[ -z "$DARWIN" ] && return 0 case "$OSTYPE" in darwin*) [ 1 ];; *) return ;; @@ -58,7 +57,7 @@ defaults write com.apple.finder AppleShowAllFiles FALSE echo "$run" | sh } -mac_user_top_proci() { +mac_user_top_proc() { echo "TOP PROCESSES:" ps -Aro'%cpu, ucomm, user' | grep `whoami` | grep -v ' 0.0 ' } @@ -72,17 +71,18 @@ mac_xmessage() { } mac_install_dmg() { - local MOUNTDIR=$(echo `hdiutil mount jdk-7u51-macos-x64.dmg | tail -1 | awk '{$1=$2=""; print $0}'` | xargs -0 echo) + local MOUNTDIR=$(echo `hdiutil mount "$1" | tail -1 | awk '{$1=$2=""; print $0}'` | xargs -0 echo) sudo installer --verbose -pkg "${MOUNTDIR}/"*.pkg -target / sudo hdiutil detach "${MOUNTDIR}" } +mac_pkg_list_files() { + #sudo pkgutil --only-dirs --files com.puppetlabs.puppet-agent|grep /puppet + sudo pkgutil --only-files --files $@ +} + mac_keychain_add() { local in="cat"; [ -n "$*" ] && in="echo $*"; eval $in | sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain } - -function ls_users() { - dscacheutil -q user|perl -ne '/^\w+:\s+(.*)?$/; push @_,$1; print join(":",$_[0],"*",@_[2,3,6,4,5])."\n" and @_=() if /^\s*$/'|sort -u|sort -t : -k3,4 -n |head|csv2human -nh -s : -} diff --git a/lib/php/db/shell.php b/lib/php/db/shell.php index 32339c93..b0959f7c 100755 --- a/lib/php/db/shell.php +++ b/lib/php/db/shell.php @@ -31,6 +31,7 @@ $no_reset_params = [ 'format', ]; #bye($Confs['ui']); + while($line = fgets(STDIN)){ $line = trim($line); @@ -42,59 +43,56 @@ while($line = fgets(STDIN)){ # Set params while ($line and (0 - #or preg_match('/^([\w\.]+)=("[^"]+"|\S+)/',$line,$args) or preg_match("/^([\w\.]+)='([^']+)'/",$line,$args) or preg_match('/^([\w\.]+)="([^"]+)"/',$line,$args) or preg_match('/^([\w\.]+)=(\S+)/',$line,$args) )) { - # (?:(?:[^()]++|"(?R)")*) $line = mb_substr($line,mb_strlen($args[0])+1); - #debug($args); - - array_shift($args); - list ($k,$v) = $args; + array_shift($args); list ($k,$v) = $args; + db_shell_action($k,$v); + } - Db::pset($k,$v); - Db::pinit(); +} - switch ($k) { +function db_shell_action($k,$v) { + global $Confs, $Db, $Table; + Db::pset($k,$v); + Db::pinit(); - case 'action': + switch ($k) { - if ($v == 'reset') { - $keep = []; - foreach (Db::p() as $k => $v) { if (in_array($k,$no_reset_params)) $keep[$k] = $v; } - $_REQUEST = []; - foreach ($keep as $k => $v) { Db::pset($k,$v); } - $keep = []; - break; - } + case 'action': - $Db->action($Db->p('action'),$Table); + if ($v == 'reset') { + $keep = []; + foreach (Db::p() as $k => $v) { if (in_array($k,$no_reset_params)) $keep[$k] = $v; } + $_REQUEST = []; + foreach ($keep as $k => $v) { Db::pset($k,$v); } + $keep = []; break; + } - case 'db': -#bye($Confs[$v]); - $Db = new Db($Confs[$v]+['conf'=>$Confs]); - $Db->connect(); - break; + $Db->action($Db->p('action'),$Table); + break; - case 'table': - $Table = new Table($v); - break; + case 'db': +#bye($Confs[$v]); + $Db = new Db($Confs[$v]+['conf'=>$Confs]); + $Db->connect(); + break; - case 'format': - break; + case 'table': + $Table = new Table($v); + break; - default: - echo "ERR: $k=$v\n"; - Db::pset($k,null); - break; + case 'format': + break; - } + default: + echo "ERR: $k=$v\n"; + Db::pset($k,null); + break; } - } - ?> -- 2.47.3