├── WGC ├── man ├── escapify ├── make.bach ├── make.dm365 ├── make.haydn ├── pipe.sh ├── vimgdb-bach ├── vimgdb-dm365 ├── vimgdb-haydn ├── make.mozart ├── make.vivaldi ├── vimgdb-mozart3 ├── vimgdb-vivaldi ├── .gitignore ├── di-flashfslog ├── fdhijack-dm365.sh ├── test.expect ├── subversion-scripts ├── svn-root ├── svn-url ├── svn-relocate2ip ├── svn-relocate2hostname ├── svn-missing ├── svn-deleted ├── svn-parent ├── svn-addremove ├── svn-conflict ├── svn-add-missing ├── svn-switched ├── svndiff_parse_args ├── svn-rm-missing ├── svn-diff-head ├── svn-ignore-missing ├── svn-rm-deleted ├── svn-horus-url ├── svn-blame ├── svn-rlog ├── svn-side-by-side-diff ├── svn-horus-log ├── svn-dircopy ├── svn-log ├── svn-di ├── svn-info ├── svn-filelist ├── svn-updates ├── svn-editlog ├── svn-switchver ├── svn-relocate2 ├── svn-tag ├── svn_clear ├── svn-st ├── svn-ignore ├── svn-tearoff ├── svn-diprev ├── svn-showchange ├── svndiff_helper ├── svn-tag2 └── svn-side-by-side-dirdiff ├── .github ├── CODEOWNERS └── pull_request_template.md ├── git-scripts ├── git-info ├── git-show ├── git-di ├── git_diff_wrapper ├── git-st └── git-github-url ├── jsl ├── dirdiff ├── checkpatch.pl ├── jscpucfg ├── Note.txt ├── bitbake-recipe-lookup.py ├── quotify ├── lighttpd.sh ├── lint ├── iw2 ├── AmazonEc2 ├── S98inadyn ├── inadyn.conf ├── exports ├── Amazon-Ec2-Deploy.sh └── Ubuntu-Deploy.sh ├── hiter ├── ipscan.sh ├── get_freemem ├── ls_color.sh ├── rm-release ├── tftpd.py ├── test2.expect ├── tunnel.expect ├── cc-flags ├── cc-config ├── autologin.expect ├── levis ├── ubnt-mk-recovery-sd ├── gdb-intercept.sh ├── ydict ├── colormake ├── portscan.sh ├── viman ├── BoaStatus ├── rusage.sh ├── scp.sh ├── telnet.sh ├── su-kent-source-me.sh ├── arm-linux-ldd ├── errno ├── pvs.sh ├── transfer_gdrive.sh ├── README.mkd ├── vwcgrep ├── get-swap.sh ├── colortable16.sh ├── git-time-machine ├── di-rootfslog ├── tmux-scripts └── tmux-tel.sh ├── upload_pkg ├── cc-defines ├── tel.sh ├── upload_rom ├── switch-trunk-branch.sh ├── preserve-debug ├── get_dll_version_xd.pl ├── rsync-backup.bash ├── html2wiki ├── ubnt-unifi-switch-poe-on-off.sh ├── vimgdb ├── pbcopy-nc ├── use_proxy ├── fixperm ├── fdswap.sh ├── ubnt-edge-switch-poe-on-off.sh ├── ssh.sh ├── transfer.sh ├── osx └── mount-tmp.sh ├── tag_rebuild ├── ubnt-discover-and-action.sh ├── upload_bin ├── color-spaces-3-byte.pl ├── threadsafe ├── 256colors2.pl ├── ubifs-mount-by-sudo.sh ├── wcfind_ ├── Vivotekbot.sh ├── wcfind ├── apropos ├── macos-pf-throttle.sh ├── ssh-and-action.sh ├── hwsysinfo ├── ydict-pl ├── fdhijack.sh ├── newest ├── imgcat ├── inpy ├── ubnt-devel-aircam ├── tmux_backup.sh ├── tunnel.sh ├── wcgrep ├── .bashrc_bb ├── wg ├── mkapp.sh ├── use_distcc_ccache ├── vvnt-devel-camera ├── vvtk └── cdfparse.py ├── vim2html.bash ├── vvnt_nightly_backup.sh ├── trans_add.py ├── ldd_arm ├── colormake-vvtk.pl ├── .bashrc_bb_u ├── tmux-bootstrap-myproject.sh ├── ydict_ ├── valgrind-run.sh ├── redmine_prj_gen.py └── get_version /WGC: -------------------------------------------------------------------------------- 1 | wg -------------------------------------------------------------------------------- /man: -------------------------------------------------------------------------------- 1 | viman -------------------------------------------------------------------------------- /escapify: -------------------------------------------------------------------------------- 1 | quotify -------------------------------------------------------------------------------- /make.bach: -------------------------------------------------------------------------------- 1 | mkapp.sh -------------------------------------------------------------------------------- /make.dm365: -------------------------------------------------------------------------------- 1 | mkapp.sh -------------------------------------------------------------------------------- /make.haydn: -------------------------------------------------------------------------------- 1 | mkapp.sh -------------------------------------------------------------------------------- /pipe.sh: -------------------------------------------------------------------------------- 1 | tunnel.sh -------------------------------------------------------------------------------- /vimgdb-bach: -------------------------------------------------------------------------------- 1 | vimgdb -------------------------------------------------------------------------------- /vimgdb-dm365: -------------------------------------------------------------------------------- 1 | vimgdb -------------------------------------------------------------------------------- /vimgdb-haydn: -------------------------------------------------------------------------------- 1 | vimgdb -------------------------------------------------------------------------------- /make.mozart: -------------------------------------------------------------------------------- 1 | mkapp.sh -------------------------------------------------------------------------------- /make.vivaldi: -------------------------------------------------------------------------------- 1 | mkapp.sh -------------------------------------------------------------------------------- /vimgdb-mozart3: -------------------------------------------------------------------------------- 1 | vimgdb -------------------------------------------------------------------------------- /vimgdb-vivaldi: -------------------------------------------------------------------------------- 1 | vimgdb -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tt 2 | .svn 3 | -------------------------------------------------------------------------------- /di-flashfslog: -------------------------------------------------------------------------------- 1 | di-rootfslog -------------------------------------------------------------------------------- /fdhijack-dm365.sh: -------------------------------------------------------------------------------- 1 | fdhijack.sh -------------------------------------------------------------------------------- /test.expect: -------------------------------------------------------------------------------- 1 | tunnel.expect -------------------------------------------------------------------------------- /subversion-scripts/svn-root: -------------------------------------------------------------------------------- 1 | svn-info -------------------------------------------------------------------------------- /subversion-scripts/svn-url: -------------------------------------------------------------------------------- 1 | svn-info -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @chenkaie @klaymenr 2 | -------------------------------------------------------------------------------- /subversion-scripts/svn-relocate2ip: -------------------------------------------------------------------------------- 1 | svn-relocate2 -------------------------------------------------------------------------------- /git-scripts/git-info: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | git config -l 3 | -------------------------------------------------------------------------------- /subversion-scripts/svn-relocate2hostname: -------------------------------------------------------------------------------- 1 | svn-relocate2 -------------------------------------------------------------------------------- /jsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenkaie/Tools/HEAD/jsl -------------------------------------------------------------------------------- /dirdiff: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | vim -c "set spell" -c "DirDiff $1 $2" 3 | -------------------------------------------------------------------------------- /checkpatch.pl: -------------------------------------------------------------------------------- 1 | /home/kent/project/linux-5.4.61/scripts/checkpatch.pl -------------------------------------------------------------------------------- /jscpucfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenkaie/Tools/HEAD/jscpucfg -------------------------------------------------------------------------------- /subversion-scripts/svn-missing: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | svn st | grep "^[ \t]*?" 4 | -------------------------------------------------------------------------------- /git-scripts/git-show: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git show --no-prefix $@ | levis 4 | 5 | -------------------------------------------------------------------------------- /subversion-scripts/svn-deleted: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | svn st | grep "^[ \t]*\!" 4 | -------------------------------------------------------------------------------- /subversion-scripts/svn-parent: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | svn-url | sed -e 's/\/[^\/]*$//' 4 | -------------------------------------------------------------------------------- /Note.txt: -------------------------------------------------------------------------------- 1 | before executing fixperm, "chmod -x foobar.xxx" first 2 | fixperm -s && svn ci 3 | -------------------------------------------------------------------------------- /subversion-scripts/svn-addremove: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | svn-rm-deleted 4 | svn-add-missing 5 | -------------------------------------------------------------------------------- /subversion-scripts/svn-conflict: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SVN=svn 4 | 5 | svn st $@ | grep ^C 6 | -------------------------------------------------------------------------------- /bitbake-recipe-lookup.py: -------------------------------------------------------------------------------- 1 | /home/kent/Project/Issues/RecipePacakgeLookup/bitbake-recipe-lookup.py -------------------------------------------------------------------------------- /subversion-scripts/svn-add-missing: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | svn add ` svn-missing | awk '{print $2}' $1` 4 | -------------------------------------------------------------------------------- /subversion-scripts/svn-switched: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | svn st | grep "^[ \t]*S" | sed -e 's/^\s*S\s*//' 4 | -------------------------------------------------------------------------------- /subversion-scripts/svndiff_parse_args: -------------------------------------------------------------------------------- 1 | i=0 2 | for a in "$@"; do i=$((i+1)); echo $i: "$a"; done 3 | -------------------------------------------------------------------------------- /subversion-scripts/svn-rm-missing: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | svn-missing | awk '{print $2}' $1 | xargs rm -rf 4 | -------------------------------------------------------------------------------- /subversion-scripts/svn-diff-head: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | svn diff -x -w -r BASE:HEAD $@ | sed -e 's/ //' | levis 4 | -------------------------------------------------------------------------------- /subversion-scripts/svn-ignore-missing: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | svn-missing | awk '{print $2}' $1 | xargs svn-ignore 4 | -------------------------------------------------------------------------------- /quotify: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -pl 2 | # Ref: https://stackoverflow.com/a/1315213/174993 3 | s/'/'\\''/g; 4 | $_ = qq['$_']; 5 | -------------------------------------------------------------------------------- /lighttpd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | lighttpd -f /home/kent/usr/etc/lighttpd.conf 4 | 5 | # Stop http server by: killall lighttpd 6 | -------------------------------------------------------------------------------- /lint: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | LINTDIR="$HOME/usr/share/pclint" 3 | wine $LINTDIR/LINT-NT.EXE +v -i$LINTDIR std.lnt $1 $2 $3 $4 $5 $6 $7 $8 $9 4 | 5 | -------------------------------------------------------------------------------- /subversion-scripts/svn-rm-deleted: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | IFS=" 4 | " 5 | for f in `svn-deleted | awk '{print $2}' $1`; do 6 | svn rm "$f" 7 | done 8 | -------------------------------------------------------------------------------- /git-scripts/git-di: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #git difftool --tool=vimdiff --no-prompt $@ 4 | git diff --ignore-space-change --no-prefix $@ | levis 5 | 6 | -------------------------------------------------------------------------------- /git-scripts/git_diff_wrapper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # hidden a/... & b/... 3 | #git diff --no-prefix 4 | #echo $0, $1, $2, $3, $4, $5, $6, $7 5 | vimdiff "$2" "$5" 6 | -------------------------------------------------------------------------------- /subversion-scripts/svn-horus-url: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "`svn-url \"$1\" | sed 's,\(Project/\).*\(app_cluster/\),\1Horus/trunk/\2,'`" 4 | 5 | exit 0 6 | -------------------------------------------------------------------------------- /git-scripts/git-st: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$1" = "-M" ] || [ "$1" = "-m" ] ; then 4 | git status | grep modified | awk '{print $2}' 5 | else 6 | git status $@ 7 | fi 8 | -------------------------------------------------------------------------------- /iw2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CAM_LIST="$HOME/tmp/camera_list.txt" 4 | [ -n "$1" ] && SEARCH_KEY="$1" || SEARCH_KEY="" 5 | [ -f "$CAM_LIST" ] && rm $CAM_LIST 6 | iw2_air -f $CAM_LIST -s "$SEARCH_KEY" 7 | -------------------------------------------------------------------------------- /AmazonEc2/S98inadyn: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | # /etc/rcS.d/S98inadyn 3 | 4 | echo 1 >> /tmp/log 5 | # Run DDNS service by Kent@20110610 6 | /usr/sbin/inadyn --input_file /etc/inadyn.conf 7 | echo 2 >> /tmp/log 8 | -------------------------------------------------------------------------------- /hiter: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | dos2unix | sed -e 's/^+\([^+]\)\(.*\)$/+ \1\2<\/span>/' | sed -e 's/^-\([^-]\)\(.*\)$/- \1\2<\/span>/' | sed -e 's/^/ /' 4 | -------------------------------------------------------------------------------- /ipscan.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | IP="$1" 4 | 5 | if [ -z "$IP" ] ; then 6 | echo "Usage: $0 [IP ADDR RANGE: 192.168.1.0/24 192.168.1.1-254]" 7 | exit 8 | fi 9 | 10 | nmap -v -sn $IP 11 | 12 | -------------------------------------------------------------------------------- /subversion-scripts/svn-blame: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | REVISION_LIST=`svn log --stop-on-copy $@ | grep ^r[0-9] | awk '{print $1}'` 4 | for i in $REVISION_LIST 5 | do 6 | svn blame -r $i:$i $@ | grep ${i:1} 7 | done 8 | 9 | -------------------------------------------------------------------------------- /get_freemem: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | free -m | grep - | awk '{print $4}' 3 | -------------------------------------------------------------------------------- /ls_color.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ( 4 | [ "$LS_COLORS" ] || eval $(dircolors) 5 | [ "$LS_COLORS" ] || eval $(TERM=xterm dircolors) 6 | printf "$LS_COLORS" 7 | ) | tr : '\n' | sed 's/\([^=]*\)=\(.*\)/\x1b[\2m\1\x1b[0m\t\2/' 8 | -------------------------------------------------------------------------------- /rm-release: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ -z "${PRJROOT}" ]; then 3 | echo "Please source environment file first!" 4 | exit 1 5 | fi 6 | 7 | cd ${PRODUCTDIR}/release 8 | rm -rf app_cluster_Build/ flashfs/ rootfs/ 9 | 10 | -------------------------------------------------------------------------------- /AmazonEc2/inadyn.conf: -------------------------------------------------------------------------------- 1 | # /etc/inadyn.conf 2 | --username chenkaie@gmail.com --password 2xxxxxxx 3 | --dyndns_system default@no-ip.com --alias amazon-ec2.no-ip.org --update_period 60000 --forced_update_period 864000 4 | --background 5 | -------------------------------------------------------------------------------- /subversion-scripts/svn-rlog: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Show log of remote repository rather than working copy to avoid 3 | # retrieving outdated log if user forget to `svn update` to HEAD 4 | 5 | svn log -v --stop-on-copy `svn-url $1` | less --tabs=4 -i 6 | -------------------------------------------------------------------------------- /subversion-scripts/svn-side-by-side-diff: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # old school, geek style.. 4 | #svn di --diff-cmd colordiff.pl -x "--side-by-side -N --ignore-all-space -W $(tput cols)" $@ | less -R 5 | 6 | svn di --diff-cmd svndiff_helper $@ 7 | -------------------------------------------------------------------------------- /subversion-scripts/svn-horus-log: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | path="" 4 | # if the 1st arg is not started with a "-" 5 | if [ "${1#-}" = "$1" ]; then 6 | path="$1" 7 | shift 8 | fi 9 | 10 | svn log `svn-horus-url "$path"` $@ 11 | 12 | exit 0 13 | -------------------------------------------------------------------------------- /subversion-scripts/svn-dircopy: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | IFS=$'\n' 4 | 5 | if [ -z "$1" ] ; then 6 | echo "Usage: $0 [src-wc] [dest-wc]" 7 | exit 8 | fi 9 | destDir=`readlink -f $2` 10 | cd $1 11 | cp -f --parents `svn ls -R .` ${destDir} 12 | cd - 13 | -------------------------------------------------------------------------------- /tftpd.py: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # sudo apt-get install python-tftpy 3 | 4 | echo ================================ 5 | echo "TFTP root path: $HOME/tmp" 6 | echo ================================ 7 | sudo /usr/share/doc/python-tftpy/examples/tftpy_server.py -p 69 -r $HOME/tmp/ 8 | -------------------------------------------------------------------------------- /subversion-scripts/svn-log: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | svn log -v --stop-on-copy $@ \ 4 | | sed -e 's/^\(.*\)|\(.*\)| \(.*\) \(.*\):[0-9]\{2\} \(.*\) (\(...\).*) |\(.*\)$/\o33\[1;32m\1\o33[0m|\o33\[1;34m\2\o33[0m| \o33\[1;35m\3 \4 (\6, \5)\o33[0m |\7/' \ 5 | | less --tabs=4 -i -R 6 | -------------------------------------------------------------------------------- /test2.expect: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect 2 | set count 1; 3 | while { $count > 0 } { 4 | puts "[exec date], Run at $count-th time\n"; 5 | spawn pipe.sh dd-wrt 6 | interact timeout 300 { send "\x00" } 7 | wait 8 | set count [expr $count+1]; 9 | sleep 5 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tunnel.expect: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect 2 | set count 1; 3 | while { $count > 0 } { 4 | puts "[exec date], Run at $count-th time\n"; 5 | spawn pipe.sh dd-wrt 6 | interact timeout 300 { send "\x00" } 7 | wait 8 | set count [expr $count+1]; 9 | sleep 5 10 | } 11 | 12 | -------------------------------------------------------------------------------- /cc-flags: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "$CC" = "" ]; then 4 | CC=gcc 5 | fi 6 | $CC -v --version 7 | 8 | # Learned this trick from: http://comments.gmane.org/gmane.comp.compilers.llvm.cvs/125877 9 | # Note that "gcc -dumpmachine" is easier if you only want the target triplet 10 | -------------------------------------------------------------------------------- /git-scripts/git-github-url: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | br=$(git branch --contains HEAD | sed -rn "s/^\* //p"); if ! git ls-remote . | grep -q -e "refs/remotes/.*/${br}"; then br="master"; fi; echo $(git config -l | sed -rn "s%remote.origin.url=git(@|://)(github.com)(:|/)(.+/.+).git%https://\2/\4/tree/${br}%p") 3 | -------------------------------------------------------------------------------- /cc-config: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "$CC" = "" ]; then 4 | CC=gcc 5 | fi 6 | $CC "$@" -v -E -x c /dev/null 2>&1 7 | 8 | # Learned this trick from: http://comments.gmane.org/gmane.comp.compilers.llvm.cvs/125877 9 | # Note that "gcc -dumpmachine" is easier if you only want the target triplet 10 | -------------------------------------------------------------------------------- /subversion-scripts/svn-di: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "$1" = "-v" ] || [ "$1" = "-vi" ] || [ "$1" = "-vim" ] ; then 4 | # Use `vim -p` to open each `'M' Modified stat` file on different tab 5 | IFS=$'\n' 6 | vim -X -p `svn st $2 | grep ^M | awk '{print $2}'` 7 | else 8 | svn di --diff-cmd diff -x "-ruN --ignore-all-space" $@ | levis 9 | fi 10 | -------------------------------------------------------------------------------- /subversion-scripts/svn-info: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | case "$0" in 4 | *-url*) 5 | svn info $1 | grep ^URL | sed -e 's/^.*http/http/' 6 | ;; 7 | *-root*) 8 | svn info $1 | grep "^Repository Root" | sed -e 's/^.*http/http/' 9 | ;; 10 | *) 11 | echo "Usage: svn-url | svn-root" 12 | exit 1 13 | ;; 14 | esac 15 | -------------------------------------------------------------------------------- /autologin.expect: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect 2 | 3 | spawn telnet "-8" "172.16.34.54" 4 | 5 | expect "login:" 6 | send "root\r\n" 7 | 8 | # if password is needed 9 | #expect "Password:" 10 | #send "1111\r\n" 11 | 12 | # Run shm_read command 13 | send "shm_read 0 0\r\n" 14 | 15 | interact timeout 60 { send -null } 16 | #interact timeout 300 { send "\x00" } 17 | 18 | -------------------------------------------------------------------------------- /levis: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Shell script to start Vim with less.vim. 3 | # Read stdin if no arguments were given. 4 | 5 | if test $# = 0; then 6 | vim -R --cmd 'let no_plugin_maps = 1' -c 'runtime! $VIMRUNTIME/macros/less.vim' -c 'set ft=diff' - 7 | else 8 | vim -R --cmd 'let no_plugin_maps = 1' -c 'runtime! $VIMRUNTIME/macros/less.vim' -c 'set ft=diff' "$@" 9 | fi 10 | -------------------------------------------------------------------------------- /subversion-scripts/svn-filelist: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$1" ] ; then 4 | echo "Usage: svn-filelist revision1 revision2 ..." 5 | exit 6 | fi 7 | 8 | IFS=$' ' 9 | 10 | FileList="" 11 | RevList="$@" 12 | 13 | for i in $RevList; do 14 | FileList=${FileList}$(echo -e "\r")$(svn log -v -r$i | grep "^ [A|M]" | awk '{print $2}') 15 | done 16 | 17 | echo ${FileList} | sort | uniq 18 | -------------------------------------------------------------------------------- /ubnt-mk-recovery-sd: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: https://ubiquiti.atlassian.net/wiki/display/AIRVISION/UVC+Micro+Recovery 3 | 4 | if [ $# -lt 1 ]; then 5 | echo "Usage: $0 " 6 | exit 0 7 | fi 8 | 9 | FW_BIN="$1" 10 | 11 | if [ "$FW_BIN" = "-" ]; then 12 | source ubnt-devel-aircam 13 | FW_BIN=$(ls $IMAGEDIR/*[^bootloader].bin) 14 | fi 15 | 16 | echo "Firmware name: `basename $FW_BIN`" 17 | 18 | sudo dd if=$FW_BIN of=/dev/sdd bs=8M 19 | sync 20 | -------------------------------------------------------------------------------- /gdb-intercept.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if test $# -ne 2; then 3 | echo "Usage: `basename $0 .sh` " 1>&2 4 | exit 1 5 | fi 6 | if test ! -r /proc/$1; then 7 | echo "Process $1 not found." 1>&2 8 | exit 1 9 | fi 10 | result="" 11 | GDB=${GDB:-/usr/bin/gdb} 12 | 13 | # Run GDB, strip out unwanted noise. 14 | result=`$GDB --quiet -nx /proc/$1/exe $1 <&1 15 | $2 16 | EOF` 17 | 18 | echo "$result" | egrep -A 1000 -e "^\(gdb\)" | egrep -B 1000 -e "^\(gdb\)" 19 | -------------------------------------------------------------------------------- /ydict: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exist () { type "$1" &> /dev/null; } 4 | 5 | CUR_PY_VER=$(python -V 2>&1 | cut -d ' ' -f 2) 6 | if [[ "$CUR_PY_VER" < "2.7.0" ]]; then 7 | if exist pythonbrew ; then 8 | VERSION=$(pythonbrew list | grep "2.7" | cut -d '-' -f 2 | cut -d ' ' -f 1) 9 | echo Please use Python 2.7.0 or greater. 10 | echo Exec \"pythonbrew switch $VERSION\" first. 11 | exit 1 12 | else 13 | echo Please use Python 2.7.0 or greater. 14 | fi 15 | fi 16 | 17 | ydict-py "$@" 18 | -------------------------------------------------------------------------------- /colormake: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Wrapper around make, to colorize it's output and pipe through less. 4 | # Jumps to the first gcc error that occurs during the build process. 5 | # 6 | 7 | #make $* 2>&1 | colormake.pl `stty size` 8 | # Uncomment below line for debug purpose 9 | #echo "$@" >> /tmp/makelog 10 | case "$@" in 11 | *menuconfig*|*firmware*|*sample*|doctor|release|*linux*|*oldconfig*|*preload*) 12 | make $@ 13 | ;; 14 | *) 15 | make $@ 2>&1 | colormake-vvtk.pl 16 | ;; 17 | esac 18 | 19 | -------------------------------------------------------------------------------- /portscan.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # http://www.cyberciti.biz/faq/linux-port-scanning/ 3 | # Introduction: 4 | # If nmap is not installed try nc / netcat command. 5 | # The -z flag can be used to tell nc to report open ports, rather than initiate a connection. 6 | # e.g. nc -z 172.16.2.54 1-65535 7 | 8 | IP="$1" 9 | PORT="1-65535" 10 | 11 | if [ -z "$1" ] ; then 12 | echo "Usage: $0 [IP ADDR] [PORT RANGE]" 13 | exit 14 | fi 15 | 16 | [ -n "$2" ] && PORT="$2" 17 | 18 | nc -z $IP $PORT 19 | 20 | -------------------------------------------------------------------------------- /subversion-scripts/svn-updates: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ -z "$1" ] ; then 3 | echo "Usage: svn-update . 4 | svn-update -l 5 | svn-update -d" 6 | exit 7 | fi 8 | 9 | if [ "$1" = "--log" ] || [ "$1" = "-l" ] ; then 10 | revision=`svn info | grep "^Revision: " | cut -d " " -f 2` 11 | svn-log -v -r `expr $revision + 1`:HEAD | less 12 | exit 13 | elif [ "$1" = "--diff" ] || [ "$1" = "-d" ] ; then 14 | svn-di -r BASE:HEAD 15 | exit 16 | fi 17 | 18 | svn st $@ -u | grep "*" | less 19 | -------------------------------------------------------------------------------- /viman: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ascii => 1 : 49 3 | # ascii => 9 : 57 4 | # man [section:1~9] [keyword] 5 | 6 | if [ "$#" == 2 ]; then 7 | sectionToASCII=`printf '%d' "'$1"` 8 | if [ "$sectionToASCII" -ge 49 -a $sectionToASCII -le 57 ]; then 9 | vim -X -c "Man $1 $2" -c 'silent only' -c 'set nolist' 10 | else 11 | echo "Wrong Params!" 12 | fi 13 | elif [ "$#" == 1 ]; then 14 | vim -X -c "Man $1" -c 'silent only' -c 'set nolist' 15 | else 16 | echo "Wrong Params!" 17 | fi 18 | -------------------------------------------------------------------------------- /BoaStatus: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | echo "Boa upup..." 3 | tmpFile=/tmp/test_boa.output 4 | if [ -z "$1" ]; then 5 | echo "Usage: BoaStatus ip_address" 6 | echo "Example: BoaStatus 172.16.7.29" 7 | exit 1; 8 | fi 9 | 10 | trap "exit 1" SIGINT 11 | nmap $1 -p 80 -P0 --scan-delay 1s -oN $tmpFile >/dev/null 12 | grep "open" $tmpFile 13 | 14 | while [ "$?" != "0" ] 15 | do 16 | echo -e "\e[0;34mBoa is Down\t\e[1;34m" 17 | nmap $1 -p 80 -P0 --scan-delay 1s -oN $tmpFile >/dev/null 18 | grep "open" $tmpFile 19 | done 20 | echo -e "\e[0;31mBoa is Up... GoGoGo\t\e[1;31m" 21 | -------------------------------------------------------------------------------- /rusage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Usage: Add below line to your first line of Makefile to collect Resource Usage information 4 | # SHELL = rusage.sh /bin/bash 5 | 6 | if [ $# -lt 1 ]; then 7 | echo "Usage: $0 COMMAND [ ARGS ]" 8 | exit 1 9 | fi 10 | 11 | # The shortest form used for Makefile debug (to printout each line been expanded) 12 | #exec time -f 'argv="%C"' "$@" 13 | 14 | # A full stack profiling argument :) 15 | exec time -f 'rc=%x elapsed=%e user=%U system=%S maxrss=%M avgrss=%t ins=%I outs=%O minflt=%R majflt=%F swaps=%W avgmem=%K avgdata=%D argv="%C"' "$@" 16 | -------------------------------------------------------------------------------- /subversion-scripts/svn-editlog: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | REV="$1" 4 | REPOS="$2" 5 | 6 | if [ "$1" = "-h" ] || [ "$1" = "--h" ] || [ "$1" = "--help" ] ; then 7 | echo "Usage: svn-editlog @REV [Target]" 8 | exit 9 | fi 10 | 11 | if [ -z "$REV" ] ; then 12 | revision=`svn info | grep "^Last\ Changed\ Rev: " | cut -d " " -f 4` 13 | echo "svn propedit -r $revision --revprop svn:log" 14 | svn propedit -r $revision --revprop svn:log 15 | else 16 | echo "svn propedit -r $REV --revprop svn:log $REPOS" 17 | svn propedit -r $REV --revprop svn:log $REPOS 18 | fi 19 | -------------------------------------------------------------------------------- /scp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #set -x 4 | 5 | if [ $# -lt 2 ]; then 6 | echo "Usage: $0 ..." 7 | exit 0 8 | fi 9 | 10 | # load credentials if exists 11 | [ -r ~/.creds ] && . ~/.creds 12 | 13 | DEVICE_IP="$1" 14 | 15 | SSH_OPTION_IGNORE_CHECK="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" 16 | 17 | for passwd in ${SSH_PASS:-ubnt}; do 18 | sshpass -p ${passwd} scp -O -P ${SSH_PORT:-22} $SSH_OPTION_IGNORE_CHECK -r "${@:2}" ${SSH_USER:-root}@$DEVICE_IP:/tmp/ 19 | [ $? -eq 0 ] && { echo "done"; exit 0; } || echo "try next..." 20 | done 21 | -------------------------------------------------------------------------------- /telnet.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ $# -lt 1 ]; then 4 | echo "Usage: $0 " 5 | exit 6 | fi 7 | 8 | SERVER="$1" 9 | [ -n "$2" ] && USERNAME="$2" || USERNAME="ubnt" 10 | PASSWORD="$3" 11 | 12 | 13 | expect -c " 14 | set timeout 3 15 | spawn telnet $SERVER 16 | expect \"User:*\" 17 | send \"$USERNAME\r\" 18 | 19 | if { \"$PASSWORD\" != \"\" } { 20 | expect \"?assword:*\" 21 | send \"$PASSWORD\r\" 22 | } 23 | 24 | interact timeout 60 { send -null } 25 | " 26 | 27 | # FIXME: It's weird/buggy to rewrite as below well-known form 28 | # expect << EOF 29 | # ... 30 | # ... 31 | # EOF 32 | 33 | -------------------------------------------------------------------------------- /su-kent-source-me.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | TMPDIR=/dev/shm 4 | 5 | # Read $ME from environment variable first. 6 | [ -z "$ME" ] && ME="kent.chen" 7 | 8 | # .bashrc 9 | \cp -rf `readlink -f /home/$ME/.bashrc` $TMPDIR/.bashrc_kent 10 | sed -i -e 's/$HOME/\/home\/$ME/g' $TMPDIR/.bashrc_kent 11 | #sed -i -e 's/PS1=\(.*\)/PS1=[\\u@\\h \\W]\\$/g' $TMPDIR/.bashrc_kent 12 | source $TMPDIR/.bashrc_kent 13 | 14 | # .vimrc 15 | \cp -rf `readlink -f /home/$ME/.vimrc` $TMPDIR/.vimrc_kent 16 | sed -i -e '/backup/d' $TMPDIR/.vimrc_kent 17 | alias vim="vim --cmd 'set rtp+=~$ME/.vim,~$ME/.vim/vundle/,~$ME/.vim/bundle/' -u '$TMPDIR'/.vimrc_kent" 18 | 19 | -------------------------------------------------------------------------------- /subversion-scripts/svn-switchver: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # svn 1.6/1.7/1.8 3 | # Usage: source svn-switchver [6|7|8] 4 | # Used on rd1-3 5 | 6 | if [ -n "$1" ] ; then 7 | case "$1" in 8 | *6*) svn_ver=6;; 9 | *7*) svn_ver=7;; 10 | *8*) svn_ver=8;; 11 | *) echo "Not available version '$1'"; exit 1; 12 | esac 13 | else 14 | echo "Usage: source svn-switchver [6|7|8]" 15 | exit 0 16 | fi 17 | 18 | # Make a temp .bin folder under $HOME directory. 19 | mkdir $HOME/.bin 20 | 21 | # Indicate your svn-1.[6|7|8] binary path 22 | SVN_BIN_PATH=/usr/local/bin/ 23 | 24 | ln -sf $SVN_BIN_PATH/svn-1.$svn_ver $HOME/.bin/svn 25 | export PATH=$HOME/.bin:$PATH 26 | 27 | -------------------------------------------------------------------------------- /arm-linux-ldd: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Method1: 3 | #/opt/toolchain/arm-elf-4.5.2/bin/arm-elf-readelf -d $1 |grep "Shared library" 4 | #~/ubnt_cache_dir/toolchains/14/linaro-aarch64-2017.02-gcc6.3/bin/aarch64-linux-gnu-readelf -d $1 |grep "Shared library" 5 | /usr/local/cortex-a53-2023.04-gcc12.2-linux5.15/bin/aarch64-linux-gnu-readelf -d $1 |grep "Shared library" 6 | 7 | # Method2: 8 | #/opt/toolchain/arm-elf-4.5.2/bin/arm-elf-objdump -x $1 | grep "NEEDED" 9 | #~/ubnt_cache_dir/toolchains/14/linaro-aarch64-2017.02-gcc6.3/bin/aarch64-linux-gnu-objdump -x $1 | grep "NEEDED" 10 | /usr/local/cortex-a53-2023.04-gcc12.2-linux5.15/bin/aarch64-linux-gnu-objdump -x $1 | grep "NEEDED" 11 | -------------------------------------------------------------------------------- /AmazonEc2/exports: -------------------------------------------------------------------------------- 1 | # /etc/exports: the access control list for filesystems which may be exported 2 | # to NFS clients. See exports(5). 3 | # 4 | # Example for NFSv2 and NFSv3: 5 | # /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check) 6 | # 7 | # Example for NFSv4: 8 | # /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check) 9 | # /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check) 10 | # 11 | 12 | # vbird: http://linux.vbird.org/linux_server/0330nfs.php 13 | 14 | /home localhost(rw,sync) *(ro,sync) 15 | /workspace localhost(rw,sync) *(rw,no_root_squash) 10.0.0.0/24(rw,sync) 16 | #/tmp localhost(rw,sync) *(rw,no_root_squash) 10.0.0.0/24(rw,sync) 17 | 18 | -------------------------------------------------------------------------------- /errno: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Reference: http://github.com/pixelb/scripts/commits/master/scripts/errno 3 | # 4 | # Display ENAME corresponding to number 5 | # or all ENAMEs if no number specified. 6 | # 7 | # [Kent] testing by the following to see those difference between cpp and arm-cpp 8 | # touch foo.h; cpp -dM foo.h 9 | # touch foo.h; arm_v5t_le-cpp -dM foo.h 10 | # 11 | # Usage: CPP=arm-linux-cpp errno 12 | 13 | 14 | [ $# -eq 1 ] && re="$1([^0-9]|$)" 15 | echo "#include " | 16 | ${CPP:-cpp} -dD -CC | #-CC available since GCC 3.3 (2003) 17 | grep -E "^#define E[^ ]+ $re" | 18 | sed ':s;s#/\*\([^ ]*\) #/*\1_#;t s;' | column -t | tr _ ' ' | #align 19 | cut -c1-$(tput cols) #truncate to screen width 20 | 21 | -------------------------------------------------------------------------------- /pvs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # PVS-Studio Static Code Analysis 4 | # https://www.viva64.com/en/m/0036/#ID0E6B 5 | 6 | if [ $# -lt 1 ]; then 7 | echo "Usage: $0 gen[2|3l|3m|3b|4l|3s]" 8 | exit 1 9 | fi 10 | 11 | rm -rf project.log pvs-studio-report-html project.tasks 12 | pvs-studio-analyzer analyze -j8 -l ~/.config/PVS-Studio/PVS-Studio.lic -o project.log -f ./builders/cmake/output/${1}/MinSizeRel/STATIC/work/compile_commands.json 13 | plog-converter -a GA:1,2 -t fullhtml -o pvs-studio-report-html project.log 14 | plog-converter -a GA:1,2 -t tasklist -o project.tasks project.log 15 | 16 | echo 17 | echo "Open http://10.2.2.15:8889" 18 | 19 | cd pvs-studio-report-html && python -m SimpleHTTPServer 8889 20 | 21 | -------------------------------------------------------------------------------- /transfer_gdrive.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # - Ref: https://github.com/prasmussen/gdrive 3 | # - TUTORIAL: How to get rid of 403 Errors #426 4 | # - https://github.com/gdrive-org/gdrive/issues/426 5 | # 6 | # https://drive.google.com/uc?id=149lMEhwwY4LYo6xS2jC11TEtXRwB8u0k&export=download 7 | 8 | SharedFolder=$(gdrive list --query "name = 'SharedFolderToAnyoneWithLink2022' and mimeType = 'application/vnd.google-apps.folder'" | sed -n 2p | awk '{print $1}') 9 | if [ "${SharedFolder}" = "" ]; then 10 | gdrive mkdir SharedFolderToAnyoneWithLink2022 11 | echo "Just created a 'SharedFolderToAnyoneWithLink2021' folder on your GDrive, please re-run again" 12 | else 13 | gdrive upload -p "$SharedFolder" --share "$1" 14 | fi 15 | -------------------------------------------------------------------------------- /subversion-scripts/svn-relocate2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SVN_REPO_IP="172.16.5.30" 4 | SVN_REPO_HOSTNAME="rd1-1" 5 | 6 | if [ "$1" = "-h" ] || [ "$1" = "--h" ] || [ "$1" = "--help" ] ; then 7 | echo "Usage: svn-relocate2ip [WC-Path] or svn-relocate2hostname [WC-Path]" 8 | exit 0 9 | fi 10 | 11 | case "$0" in 12 | *2ip*) 13 | svn switch --relocate `svn-url $1` `svn-url $1 | sed -e "s/${SVN_REPO_HOSTNAME}/${SVN_REPO_IP}/"` 14 | ;; 15 | *2hostname*) 16 | svn switch --relocate `svn-url $1` `svn-url $1 | sed -e "s/${SVN_REPO_IP}/${SVN_REPO_HOSTNAME}/"` 17 | ;; 18 | *) 19 | echo "Usage: svn-relocate2ip [WC-Path] or svn-relocate2hostname [WC-Path]" 20 | exit 1 21 | ;; 22 | esac 23 | -------------------------------------------------------------------------------- /README.mkd: -------------------------------------------------------------------------------- 1 | ABOUT 2 | ===== 3 | 4 | Useful tools to help improving efficiency on Linux 5 | 6 | Usage 7 | ===== 8 | 9 | 1. Check out from github 10 | 11 | git clone git://github.com/chenkaie/Tools.git ~/Tools 12 | 13 | 2. Add below to your .bashrc 14 | 15 | export PATH=$HOME/Tools:$HOME/Tools/subversion-scripts:$HOME/Tools/git-scripts:$PATH 16 | 17 | 3. source ~/.bashrc or Re-login for the change to take effect. 18 | 19 | AUTHOR 20 | ====== 21 | 22 | Kent Chen (chenkaie) 23 | 24 | * [@chenkaie](https://twitter.com/#!/chenkaie) on Twitter 25 | * [@chenkaie](http://www.plurk.com/chenkaie) on Plurk 26 | * 27 | 28 | Join the chat at https://gitter.im/chenkaie/Tools 29 | -------------------------------------------------------------------------------- /vwcgrep: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # below IFS is the keypoint 4 | IFS=$'\t ' 5 | 6 | result=`wcgrep "$1"` 7 | 8 | [ -z "$2" ] && INDEX=1 || INDEX=$2 9 | 10 | if [[ "$INDEX" == "a" ]]; then 11 | #FIXME: Why "tr" executed before "cut" in this statement FILENAME=`echo $result | cut -d ":" -f 1 | tr '\n' '@' | sed 's/@/ /g' 12 | FILENAME=`echo $result | awk '{print $2}' | cut -d ":" -f 1 | uniq` 13 | FILENAME1=`echo $FILENAME | tr '\n' '@' | sed 's/@/ /g'` 14 | echo Edit $INDEX, Filename: $FILENAME1 15 | $EDITOR -X -p $FILENAME1 16 | else 17 | str=`echo $result | sed -n "${INDEX}p" | awk '{print $2}'` 18 | FILENAME=`echo $str | cut -d ":" -f 1` 19 | LINENUMBER=`echo $str | cut -d ":" -f 2` 20 | $EDITOR $FILENAME +$LINENUMBER 21 | fi 22 | 23 | -------------------------------------------------------------------------------- /get-swap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Get current swap usage for all running processes in sorted results 3 | # Original Author: Erik Ljungstrom 27/05/2011 4 | 5 | RESULTS="/tmp/.getswap" 6 | rm -f $RESULTS 7 | 8 | SUM=0 9 | OVERALL=0 10 | for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"`; do 11 | PID=`echo $DIR | cut -d / -f 3` 12 | PROGNAME=`ps -p $PID -o comm --no-headers` 13 | for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'` 14 | do 15 | let SUM=$SUM+$SWAP 16 | done 17 | printf "Swap: %+7s\tPID:%+5s (%s)\n" $SUM $PID $PROGNAME >> $RESULTS 18 | let OVERALL=$OVERALL+$SUM 19 | SUM=0 20 | done 21 | 22 | cat $RESULTS | egrep -v "Swap: |Swap: 0|Swap: server" |sort -n -k 2 23 | 24 | echo "Overall swap used: $OVERALL" 25 | 26 | -------------------------------------------------------------------------------- /colortable16.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # prints a color table of 8bg * 8fg * 2 states (regular/bold) 4 | echo 5 | echo Table for 16-color terminal escape sequences. 6 | echo Replace ESC with \\033 in bash. 7 | echo 8 | echo "Background | Foreground colors" 9 | echo "---------------------------------------------------------------------" 10 | for((bg=40;bg<=47;bg++)); do 11 | for((bold=0;bold<=1;bold++)) do 12 | echo -en "\033[0m"" ESC[${bg}m | " 13 | for((fg=30;fg<=37;fg++)); do 14 | if [ $bold == "0" ]; then 15 | echo -en "\033[${bg}m\033[${fg}m [${fg}m " 16 | else 17 | echo -en "\033[${bg}m\033[1;${fg}m [1;${fg}m" 18 | fi 19 | done 20 | echo -e "\033[0m" 21 | done 22 | echo "--------------------------------------------------------------------- " 23 | done 24 | 25 | echo 26 | echo 27 | -------------------------------------------------------------------------------- /git-time-machine: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH=$PATH:$HOME/usr/bin 4 | source $HOME/.bashrc 5 | 6 | echo "GIT directories: $GIT_MANAGED_DIRECTORY" 7 | if [ "$GIT_MANAGED_DIRECTORY" = "" ]; then 8 | echo 'Please set $GIT_MANAGED_DIRECTORY first' 9 | fi 10 | 11 | for dir in $GIT_MANAGED_DIRECTORY ; do 12 | pushd $dir 2>&1 > /dev/null 13 | git add . 14 | echo "[Time Machine] Auto commit" | git commit -a -F - 15 | popd 2>&1 > /dev/null 16 | done 17 | 18 | exit 0; 19 | 20 | # do rsync in midnight ONLY! 21 | if [ `date -d now +%k` -le 1 ]; then 22 | echo "##################################################" 23 | echo "## Remote Replication on RD1-3 ##" 24 | echo "##################################################" 25 | 26 | rsync -avz --delete -e "ssh -l kent" $GIT_MANAGED_DIRECTORY rd1-3:TimeMachine 27 | fi 28 | -------------------------------------------------------------------------------- /subversion-scripts/svn-tag: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ $# -lt 2 ] ; then 4 | echo "This is svn auto tagger speaking. I will help you to tag your firmware." 5 | echo " svn-tag " 6 | exit 1 7 | fi 8 | 9 | if [ -z "${PRJROOT}" ] ; then 10 | echo "Please source environment file first!" 11 | exit 1 12 | fi 13 | 14 | source=$1 15 | target=$2 16 | version=$PRODUCTVER 17 | 18 | # check if target is a local directory 19 | if [ -d $target ]; then 20 | # we currently do not handle copy to local directory case 21 | echo "$0: target must be a svn remote repo" 22 | exit 1 23 | else 24 | echo "tagging $version" 25 | svn mkdir $target/$version -m "svn-tag: create tag directory" > /dev/null 26 | for dir in `ls $source`; do 27 | echo "..$dir" 28 | svn cp $source/$dir $target/$version/$dir -m "svn-tag: copying $dir" > /dev/null 29 | done 30 | fi 31 | -------------------------------------------------------------------------------- /subversion-scripts/svn_clear: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ################################################################################# 3 | # Filename: svn_clear 4 | # Author: Wu Yin(吴垠) 5 | # Email: lazy_fox@gmail.com 6 | # Created: 2007-10-26 7 | # Description: Clear a svn working copy, make it a nomal directory. 8 | # Usage: svn_clear [PATH] 9 | # "svn_clear" will remove all the ".svn" directory recursively 10 | # from the PATH you gived. The current directory by default. 11 | ################################################################################# 12 | IFS=' 13 | ' 14 | 15 | WORK_PATH=$1 16 | if [ -z "$WORK_PATH" ]; then 17 | WORK_PATH="." 18 | fi 19 | 20 | for files in `tree -difa $WORK_PATH | grep '.svn$'` 21 | do 22 | echo "Cleaning" $files " ... " 23 | rm -rf $files 24 | done 25 | -------------------------------------------------------------------------------- /di-rootfslog: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ -z "${PRJROOT}" ]; then 3 | echo "Please source environment file first!" 4 | exit 1 5 | fi 6 | 7 | cd ${PRODUCTDIR}/release/log 8 | 9 | PATTERN_DATE="" 10 | PATTERN_MD5="" 11 | 12 | case "$0" in 13 | *rootfs*) 14 | PATTERN_DATE="_rootfs_[^m]" 15 | PATTERN_MD5="_rootfs_md5_" 16 | ;; 17 | *flashfs*) 18 | PATTERN_DATE="_flashfs_[^m]" 19 | PATTERN_MD5="_flashfs_md5_" 20 | ;; 21 | *) 22 | exit 1 23 | ;; 24 | esac 25 | 26 | if [ "$1" = "-s" ] || [ "$1" = "-size" ] ; then 27 | new=`ls -t *${PATTERN_DATE}* |sed -n '1p'` 28 | last=`ls -t *${PATTERN_DATE}* |sed -n '2p'` 29 | elif [ "$1" = "-m" ] || [ "$1" = "-md5" ] || [ -z "$1"]; then 30 | new=`ls -t *${PATTERN_MD5}* |sed -n '1p'` 31 | last=`ls -t *${PATTERN_MD5}* |sed -n '2p'` 32 | fi 33 | 34 | vimdiff $new $last 35 | 36 | -------------------------------------------------------------------------------- /tmux-scripts/tmux-tel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ############## 4 | # function() # 5 | ############## 6 | 7 | Usage () 8 | { 9 | echo "Usage: `basename $0` [-n] " 10 | exit 1 11 | } 12 | 13 | ########## 14 | # main() # 15 | ########## 16 | 17 | [ $# -lt 2 ] && Usage 18 | 19 | if [ "$1" = "-n" ]; then 20 | readonly NEW_WINDOW=1; shift 21 | fi 22 | 23 | readonly IPADDR="$1" 24 | readonly TELNET_COUNT="$2" 25 | 26 | if [ "$NEW_WINDOW" = "1" ]; then 27 | # First new-window 28 | tmux new-window -k -n $IPADDR 29 | 30 | # Reset split-window except 1st one 31 | for (( i = 1; i < $TELNET_COUNT ; i++ )); do 32 | tmux split-window 33 | done 34 | 35 | # tiled layout 36 | tmux select-layout tiled 37 | fi 38 | 39 | # Not newly created, just send-keys to all target panes 40 | for (( i = 1; i <= $TELNET_COUNT ; i++ )); do 41 | tmux send-keys -t $i "tel.sh $IPADDR" c-m 42 | done 43 | 44 | -------------------------------------------------------------------------------- /upload_pkg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | use Net::FTP; 3 | use Env qw(PRODUCTDIR PRODUCTVER LANGUAGE); 4 | 5 | $target = shift(@ARGV); 6 | if (!$target) 7 | { 8 | print "Usage: update_pkg host-ip \n"; 9 | exit 1; 10 | } 11 | 12 | if (!$PRODUCTDIR) 13 | { 14 | print "Please source environment file first!\n"; 15 | exit 1; 16 | } 17 | 18 | print "Upload firmware to ", $target, "\n"; 19 | 20 | $ftp = Net::FTP->new($target, Debug => 1) 21 | or die "Cannot connect to $target: $@"; 22 | $ftp->login("root", "") 23 | or die "Cannot login ", $ftp->message; 24 | $ftp->binary(); 25 | 26 | print "Firmware: $PRODUCTDIR/release/package/$PRODUCTVER/$PRODUCTVER.flash.pkg\n"; 27 | 28 | $ftp->put("$PRODUCTDIR/release/package/$PRODUCTVER/$PRODUCTVER.flash.pkg", "flash.pkg") 29 | or die "put failed ", $ftp->message; 30 | 31 | $ftp->quit; 32 | 33 | print "Starting to test if Boa is up ", $target, "\n"; 34 | print `BoaStatus $target`; 35 | exit 0; 36 | 37 | -------------------------------------------------------------------------------- /cc-defines: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Show C/C++ macros pre-defined by the compiler: 4 | # 5 | # $ cc-defines | head 6 | # #define __amd64 1 7 | # #define __amd64__ 1 8 | # <...> 9 | # 10 | # $ CC=arm-none-eabi-gcc cc-defines | head 11 | # #define __ACCUM_EPSILON__ 0x1P-15K 12 | # <...> 13 | # #define __arm__ 1 14 | # <...> 15 | 16 | # See also: 17 | # GCC Manual: Common Predefined Macros: http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html 18 | # Pre-defined C/C++ Compiler Macros Wiki: http://sourceforge.net/p/predef/wiki/Home/ 19 | # C/C++ tip: How to list compiler predefined macros: http://nadeausoftware.com/articles/2011/12/c_c_tip_how_list_compiler_predefined_macros 20 | 21 | # See also: 22 | # http://www.commandlinefu.com/commands/view/3917/display-gcc-predefined-macros#comment 23 | # 1: gcc -dM -E - <<<'' 24 | # 2: echo | gcc -dM -E - 25 | # 3: cpp -dM /dev/null 26 | 27 | if [ "$CC" = "" ]; then 28 | CC=gcc 29 | fi 30 | $CC "$@" -dM -E -x c - < /dev/null | sort 31 | -------------------------------------------------------------------------------- /subversion-scripts/svn-st: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: svn-st [-M|-A|-R|-?] 3 | 4 | IFS=$'\n' 5 | 6 | if [ "$1" = "-M" ] || [ "$1" = "-m" ] ; then 7 | svn st $2 | grep ^M | awk '{print $2}' 8 | exit 9 | elif [ "$1" = "-A" ] || [ "$1" = "-a" ] ; then 10 | svn st $2 | grep ^A | awk '{print $2}' 11 | exit 12 | elif [ "$1" = "-R" ] || [ "$1" = "-r" ] ; then 13 | svn_wc=`find $2 -iname ".svn" -type d` 14 | st_list="/tmp/svn-st.$$" 15 | for i in $svn_wc; do 16 | svn st `dirname $i` >> $st_list 17 | done 18 | cat $st_list | sort | uniq 19 | rm -f $st_list 20 | exit 21 | elif [ "$1" = "-?" ] ; then 22 | svn st $2 | grep ^? | awk '{print $2}' 23 | exit 24 | fi 25 | 26 | svn status $@ | sed -e 's/^\(\([A-Z]\s\+\(+\s\+\)\?\)\?C .*\)$/\o33\[1;35m\1\o33[0m/' \ 27 | -e 's/^\(\s*M.*\)$/\o33\[1;34m\1\o33[0m/' \ 28 | -e 's/^\(A.*\)$/\o33\[1;32m\1\o33[0m/' \ 29 | -e 's/^\(\(D\|!\|~\).*\)$/\o33\[1;31m\1\o33[0m/' \ 30 | | less --tabs=4 -i -R 31 | -------------------------------------------------------------------------------- /tel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ $# -lt 1 ]; then 4 | echo "Usage: $0 " 5 | exit 6 | fi 7 | 8 | SERVER="$1" 9 | [ -n "$2" ] && USERNAME="$2" || USERNAME="root" 10 | PASSWORD="$3" 11 | 12 | # Enable telnet 13 | curl "http://$USERNAME:$PASSWORD@$SERVER:80/cgi-bin/admin/mod_inetd.cgi?telnet=on" 14 | 15 | 16 | # Put .bashrc for busybox file on remote server 17 | BASHRC_BB=".bashrc_bb" 18 | lftp -e "put `dirname $0`/$BASHRC_BB; bye" -u $USERNAME,$PASSWORD $SERVER 19 | 20 | # expect script, auto login to remote server and source $BASHRC_BB file 21 | 22 | expect -c " 23 | set timeout 3 24 | spawn telnet $SERVER 25 | expect \"?ogin:*\" 26 | send \"$USERNAME\r\" 27 | 28 | if { \"$PASSWORD\" != \"\" } { 29 | expect \"?assword:*\" 30 | send \"$PASSWORD\r\" 31 | } 32 | 33 | send \"FROM_ID='`whoami`'\r\" 34 | send \"source ~/$BASHRC_BB\r\" 35 | 36 | interact timeout 60 { send -null } 37 | " 38 | 39 | # FIXME: It's weird/buggy to rewrite as below well-known form 40 | # expect << EOF 41 | # ... 42 | # ... 43 | # EOF 44 | 45 | -------------------------------------------------------------------------------- /upload_rom: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | use Net::FTP; 3 | use Env qw(PRODUCTDIR PRODUCTVER LANGUAGE); 4 | 5 | $target = shift(@ARGV); 6 | if (!$target) 7 | { 8 | print "Usage: update_pkg host-ip \n"; 9 | exit 1; 10 | } 11 | 12 | if (!$PRODUCTDIR) 13 | { 14 | print "Please source environment file first!\n"; 15 | exit 1; 16 | } 17 | 18 | print "Upload firmware to ", $target, "\n"; 19 | 20 | $ftp = Net::FTP->new($target, Debug => 1) 21 | or die "Cannot connect to $target: $@"; 22 | $ftp->login("root", "") 23 | or die "Cannot login ", $ftp->message; 24 | $ftp->binary(); 25 | while (! $ftp->cwd("/mnt/ramdisk/")) 26 | { 27 | $ftp->mkdir("/mnt/ramdisk/", 1); 28 | } 29 | $ftp->put("$PRODUCTDIR/release/package/$PRODUCTVER-$LANGUAGE/$PRODUCTVER.flash.rom", "flashall.bin") 30 | or die "put failed ", $ftp->message; 31 | #$ftp->put("$PRODUCTDIR/images/$PRODUCTVER.flash.pkg") 32 | # or die "put failed ", $ftp->message; 33 | $ftp->quit; 34 | 35 | 36 | print "Starting to test if Boa is up on '", $target, "'\n"; 37 | print `BoaStatus $target`; 38 | 39 | exit 0; 40 | 41 | -------------------------------------------------------------------------------- /switch-trunk-branch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # simple script for switching directory between branches and trunk. 3 | # 4 | # svnb/svnt directory switch function works for current path like 5 | # /home/work/project/trunk 6 | # /home/work/project/branches 7 | # /home/work/project/branches/feature 8 | # 9 | # goto branch: 10 | # svnb [branch-name] 11 | # 12 | # branch list completion: 13 | # svnb 14 | # 15 | # goto trunk: 16 | # svnt 17 | # 18 | function _basedir() 19 | { 20 | local base_dir=` echo $(pwd) | perl -pe "s{(branches|trunk).*$}{}"` 21 | if [[ ! $base_dir =~ /$ ]] ; then 22 | local base_dir=$base_dir"/" 23 | fi 24 | echo $base_dir 25 | } 26 | 27 | function svnb() 28 | { 29 | cd $( _basedir )"branches/$1" 30 | } 31 | 32 | function svnt() 33 | { 34 | cd $( _basedir )"trunk/" 35 | } 36 | 37 | 38 | function _branches() 39 | { 40 | local branches=`ls $(_basedir)/branches` 41 | local cur=${COMP_WORDS[COMP_CWORD]} 42 | COMPREPLY=() 43 | COMPREPLY=( $( compgen -W '$branches' -- $cur ) ) 44 | } 45 | complete -F _branches svnb 46 | -------------------------------------------------------------------------------- /preserve-debug: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | scriptdir=`dirname ${0}` 4 | scriptdir=`(cd ${scriptdir}; pwd)` 5 | scriptname=`basename ${0}` 6 | 7 | set -e 8 | 9 | function errorexit() 10 | { 11 | errorcode=${1} 12 | shift 13 | echo $@ 14 | exit ${errorcode} 15 | } 16 | 17 | function usage() 18 | { 19 | echo "USAGE ${scriptname} " 20 | } 21 | 22 | tostripdir=`dirname "$1"` 23 | tostripfile=`basename "$1"` 24 | 25 | 26 | if [ -z ${tostripfile} ] ; then 27 | usage 28 | errorexit 0 "tostrip must be specified" 29 | fi 30 | 31 | cd "${tostripdir}" 32 | 33 | [ "$2" != "" ] && debugdir=$2 || debugdir=debug 34 | debugfile="${tostripfile}.debug" 35 | 36 | if [ ! -d "${debugdir}" ] ; then 37 | echo "creating dir ${tostripdir}/${debugdir}" 38 | mkdir -p "${debugdir}" 39 | fi 40 | echo "stripping ${tostripfile}, putting debug info into ${debugfile}" 41 | arm-linux-objcopy --only-keep-debug "${tostripfile}" "${debugdir}/${debugfile}" 42 | #arm-linux-strip --strip-debug --strip-unneeded "${tostripfile}" 43 | arm-linux-objcopy --add-gnu-debuglink="${debugdir}/${debugfile}" "${tostripfile}" 44 | chmod -x "${debugdir}/${debugfile}" 45 | -------------------------------------------------------------------------------- /get_dll_version_xd.pl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | NORMAL='\033[0m' 4 | GOOD='\033[32;01m' 5 | WARN='\033[33;01m' 6 | BAD='\033[31;01m' 7 | 8 | echo -e "" 9 | echo -e "+-------------------------------------------------------------+" 10 | echo -e "| ${BAD}[WARNING] get_dll_version_xd.pl is totally out of FASHION${NORMAL} |" 11 | echo -e "+-------------------------------------------------------------+" 12 | echo -e "| The charge for the patch is 0.99 USD |" 13 | echo -e "| Pay once for a lifetime membership ˊ_>ˋ |" 14 | echo -e "| Please Enter Your Credit Card Number: |" 15 | echo -e "| ${WARN}____ - ____ - ____ - ____ ${GOOD}CVC: ___ ${NORMAL} |" 16 | #read -p "| Press [Enter] key to continue... |" 17 | echo -e "+-------------------------------------------------------------+" 18 | cowsay -e "><" -W 100 "Just Sync It: svn log -v -r138970 http://rd1-1/subversion/" 19 | 20 | echo "`date`, `whoami`, $PRODUCTVER" >> /home/kent/tmp/CreditCardList 21 | mail -s "[VIVOTEK Store] CreditCardList" kent.chen@vivotek.com < /home/kent/tmp/CreditCardList 22 | 23 | exit 1 24 | -------------------------------------------------------------------------------- /rsync-backup.bash: -------------------------------------------------------------------------------- 1 | # --delete : delete files that don't exist on sender (system) 2 | # -v : Verbose (try -vv for more detailed information) 3 | # -e "ssh options" : specify the ssh as remote shell 4 | # -a : archive mode 5 | # -r : recurse into directories 6 | # -z : compress file data 7 | # -l : links, When symlinks are encountered, recreate the symlink on the destination. 8 | # -R : --relative, begin from /home/kent/... 9 | 10 | #To Mac 11 | echo "##################################################" 12 | echo "## sync RD1-2 To iMac ##" 13 | echo "##################################################" 14 | rsync -avHlr --delete --timeout=999 -e "ssh -l kent -p6622" ~/Tools ~/.vim ~/.bashrc ~/.vimrc ~/.screenrc ~/practice chenkaie.no-ip.org:RD1-2 15 | rsync -avHlr --delete --timeout=999 -e "ssh -l kent -p6622" ~/.vim chenkaie.no-ip.org: 16 | 17 | #To RD1-3 18 | echo "##################################################" 19 | echo "## sync RD1-2 To RD1-3 ##" 20 | echo "##################################################" 21 | #rsync -avHlr --delete --timeout=999 -e "ssh -l kent" ~/Tools ~/.vim ~/.bashrc ~/.vimrc ~/practice rd1-3:/ 22 | -------------------------------------------------------------------------------- /html2wiki: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: 3 | # 1st step: vim sample.sh => :TOhtml => save as sample.sh.html 4 | # 2nd step: html2wiki sample.sh.html 5 | # 6 | # Description about the following 5 sed command lines. 7 | # 1st: replace with
8 | # 2nd: remove 9 | # 3nd: replace with
10 | # 4rd: because [[:xxx:]] is a wiki-style command, replace it! 11 | # 5th: for fancy layout 12 | # 6th: remove useless html lines, eg: , , , , <meta> ... 13 | # 14 | # 15 | 16 | ARGUMENT="$1" 17 | if [ -z "$ARGUMENT" ] ; then 18 | echo "Usage: $0 filename" 19 | exit 1 20 | fi 21 | 22 | sed -e 's/<body bgcolor="\(.*\)" text="\(.*\)" \(.*\)>/<div style="font-size:13px; font-family: Consolas, Monaco, Courier New; background:\1; color:\2;">/; 23 | s/<font face="\(.*\)">//; 24 | s/<\/font>$/<\/div>/; 25 | s/<\/html>$//; 26 | s/<\/body>$//; 27 | s/\[\[/<nowiki>\[\[<\/nowiki>/g; 28 | s/ <\/span><br>/\ <\/span><br>/g; 29 | 1,40d; $d' $1 30 | 31 | -------------------------------------------------------------------------------- /ubnt-unifi-switch-poe-on-off.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Usage: 4 | # $ ubnt-unifi-switch-poe-on-off.sh 192.168.1.20 1 5 | 6 | SSH_OPTION_IGNORE_CHECK="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" 7 | 8 | CMD=".cmd.txt" 9 | USR=ubnt 10 | PWD=ubnt 11 | 12 | IP="$1" 13 | LANPORT="$2" 14 | DELAY="${3:-3}" # Default 3s 15 | 16 | echo "===== Disable PoE port: ${LANPORT} at ${IP} =====" 17 | 18 | cat > $CMD << EOF 19 | (echo "enable" ; echo "configure" ; echo "interface 0/$LANPORT" ; echo "poe opmode shutdown"; echo exit; echo exit; echo exit) | telnet localhost 23 20 | EOF 21 | 22 | # poe off 23 | sshpass -p $PWD ssh $SSH_OPTION_IGNORE_CHECK -q $USR@$IP $(cat $CMD) 24 | 25 | sleep $DELAY 26 | 27 | echo "===== Enable PoE port: ${LANPORT} at ${IP} =====" 28 | 29 | cat > $CMD << EOF 30 | (echo "enable" ; echo "configure" ; echo "interface 0/$LANPORT" ; echo "poe opmode auto"; echo exit; echo exit; echo exit) | telnet localhost 23 31 | EOF 32 | 33 | # poe auto 34 | sshpass -p $PWD ssh $SSH_OPTION_IGNORE_CHECK -q $USR@$IP $(cat $CMD) 35 | 36 | # link up 37 | sshpass -p $PWD ssh $SSH_OPTION_IGNORE_CHECK -q $USR@$IP "swctrl port set up id $LANPORT" 38 | 39 | rm $CMD 40 | 41 | -------------------------------------------------------------------------------- /vimgdb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | GDBPRG="" 3 | 4 | case "$0" in 5 | *vivaldi*) 6 | GDBPRG="/home/kent/ArmTools/arm-linux-gdb_vivaldi" 7 | ;; 8 | *bach*) 9 | GDBPRG="/home/kent/ArmTools/arm-linux-gdb_bach" 10 | ;; 11 | *haydn*) 12 | GDBPRG="/home/kent/ArmTools/arm-linux-gdb_haydn" 13 | ;; 14 | *mozart3*) 15 | #GDBPRG="/home/kent/ArmTools/arm-linux-gdb_mozart3-v6.7" 16 | 17 | # My own build : GNU gdb (GDB) 7.1 18 | GDBPRG="/home/kent/ArmTools/arm-linux-gdb_mozart3-v7.1" 19 | ;; 20 | *dm365*) 21 | # montavista arm-linux-gdb : GNU gdb 6.6.50_20070925 (MontaVista 6.6.50-9.0.20.0801914 2008-08-30) 22 | #vim -X -c "set gdbprg=/home/vivotek/mv_pro_5.0/montavista/pro/devkit/arm/v5t_le/bin/arm_v5t_le-gdb" -c "call ToggleGDB(\"$1\")" 23 | 24 | # My own build : GNU gdb (GDB) 7.0 25 | GDBPRG="/home/kent/ArmTools/arm-linux-gdb_dm365-v7" 26 | ;; 27 | *) 28 | # My own build : GNU gdb (GDB) 7.0 29 | GDBPRG="/home/kent/usr/bin/gdb" 30 | ;; 31 | esac 32 | 33 | /home/kent/usr/bin/vim -X -c "run macros/gdb_mappings.vim" -c "set gdbprg=${GDBPRG}" -c "call ToggleGDB(\"$1\")" 34 | -------------------------------------------------------------------------------- /subversion-scripts/svn-ignore: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Script to make it easier to add svn-ignore rules. 5 | """ 6 | 7 | import sys 8 | import os 9 | import subprocess 10 | 11 | def svn_propget_svnignore(path): 12 | '''fetch the svn:ignore property of given path''' 13 | p = subprocess.Popen(['svn', 'propget', 'svn:ignore', path], stdout=subprocess.PIPE) 14 | p.wait() 15 | data = p.stdout.read().strip() 16 | return data 17 | 18 | def svn_propset_svnignore(path, value): 19 | '''set the svn:ignore property of the given path''' 20 | p = subprocess.Popen(['svn', 'propset', 'svn:ignore', value, path]) 21 | p.wait() 22 | 23 | 24 | def main(): 25 | 26 | if len(sys.argv) < 2: 27 | print 'Usage: %s filenames' % sys.argv[0] 28 | sys.exit() 29 | 30 | for path in sys.argv[1:]: 31 | print path 32 | 33 | dirpath, filename = os.path.split(path) 34 | svnignore_data = svn_propget_svnignore(dirpath) 35 | 36 | if filename not in svnignore_data: 37 | svnignore_data += '\n' + filename 38 | svn_propset_svnignore(dirpath, svnignore_data) 39 | 40 | if __name__ == '__main__': 41 | main() 42 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | Clearly and concisely describe the feature or problem. A picture/video tells a thousand words. 4 | 5 | Any test report, link, UX design which helps reviewers understand better 6 | 7 | Closes JIRA-XXX 8 | 9 | ## Type of change 10 | 11 | Please delete options that are not relevant. 12 | 13 | - [X] Bug fix (non-breaking change which fixes an issue) 14 | - [X] New feature (non-breaking change which adds functionality) 15 | - [X] New API/IPC command added (this implies semver MINOR version bump) 16 | - [X] Breaking change (fix or feature that would cause existing functionality to not work as expected) 17 | - [X] Require backend integration to make it work or solve this issue. 18 | - [X] Refactor (nothing changed essentially and make sure not to break anything) 19 | - [X] Improvement (existing functionality improvement) 20 | 21 | ## Before this PR 22 | 23 | Basically, for bug fix case and sharing some logs which indicate where the issue occurs. 24 | 25 | ## After this PR 26 | 27 | Any logs that are worthy of mentioning or new API/IPC command usage. 28 | 29 | ## How Has This Been Tested? 30 | 31 | Please describe the tests that you ran to verify your changes. 32 | 33 | - [ ] Test Case A 34 | - [ ] Test Case B 35 | 36 | ## Related PR 37 | 38 | TBD 39 | 40 | -------------------------------------------------------------------------------- /pbcopy-nc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Mac OS X `pbcopy` clone of network manner by nc (netcat) 4 | # [New] Clipboard access for local and remote tmux sessions 5 | # https://github.com/wincent/clipper 6 | # -- 7 | # [Obsolete] Recommended using together with "Clipboard Listener (Java)" 8 | # Ref: http://www.hanhuy.com/pfn/integrating_screen_and_clipboard 9 | 10 | # Automatically determine Mackbook IP addresses 11 | IP_ADDRESSES=("192.168.10.187" "192.168.1.202" "192.168.1.158") 12 | 13 | # Read content from STDIN, a super cool and ELEGANT way 14 | # $(cat) is a shorthand for $(cat /dev/stdin) 15 | # So you can use this to read from STDERR by $(cat /dev/stderr) 16 | STDINVAL=$(cat) 17 | 18 | # Loop through IPs 19 | for IP in "${IP_ADDRESSES[@]}"; do 20 | if ping -c 1 -W 0.1 "$IP" > /dev/null 2>&1; then 21 | REMOTE="$IP" 22 | #echo "IP: $REMOTE" 23 | 24 | if [ -z "$1" ]; then 25 | # If under tmux, also set content into paste buffer 26 | [ -n "$TMUX" ] && tmux set-buffer "$STDINVAL" 27 | 28 | # Send to remote clipboard listener 29 | echo "$STDINVAL" | nc -N ${REMOTE} 8377 30 | else 31 | # Read content from $1: file path 32 | nc ${REMOTE} 8377 < $1 33 | 34 | # If under tmux, also load content into paste buffer 35 | [ -n "$TMUX" ] && tmux load-buffer $1 36 | fi 37 | fi 38 | done 39 | 40 | -------------------------------------------------------------------------------- /use_proxy: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # NOTE: source this file to enable AV thing over HTTP proxy feature 3 | # 4 | # Don't steal my poor Proxy, you could build yourown proxy server on Win32 by FreeProxy 5 | 6 | export PROXY_IP="172.16.2.54" 7 | export PROXY_PORT="8888" 8 | 9 | # For most applications, e.g. wget, curl, lynx 10 | export http_proxy=http://$PROXY_IP:$PROXY_PORT/ 11 | 12 | # For Git operation 13 | # 1. through http: git config --global http.proxy proxy_addr:proxy_port 14 | # 2. through ssh: (see the following) 15 | gitp () 16 | ( 17 | GIT_PROXY_COMMAND_FILE=~/tmp/.git-proxy-wrapper 18 | 19 | cat >| $GIT_PROXY_COMMAND_FILE <<EOF 20 | #!/bin/sh 21 | socat - PROXY:$PROXY_IP:\$1:\$2,proxyport=$PROXY_PORT 22 | EOF 23 | 24 | chmod +x $GIT_PROXY_COMMAND_FILE; 25 | 26 | GIT_PROXY_COMMAND=$GIT_PROXY_COMMAND_FILE git "$@" 27 | ) 28 | 29 | # For svn operation 30 | # Modify this file ~/.subversion/servers by using 31 | # http-proxy-exceptions 32 | # http-proxy-host 33 | # http-proxy-port 34 | 35 | # For ssh operation 36 | # Modify this file ~/.ssh/config by using 37 | # ProxyCommand + "corkscrew" or "socat" 38 | 39 | echo "+----------------------------------------------------+" 40 | echo "| Just enjoy AV thing over HTTP Proxy +" 41 | echo "+----------------------------------------------------+" 42 | 43 | -------------------------------------------------------------------------------- /fixperm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | friendly_remind () 4 | { 5 | if [ -d $1 ] ; then 6 | pushd $1 > /dev/null 7 | list=`wcfind . -type f -perm \( ! -perm /u+x -o ! -perm /g+x -o ! -perm /o+x \)` 8 | if [ "$list" != "" ] ; then 9 | echo "following files should have exec permission $1" 10 | echo $list 11 | fi 12 | popd > /dev/null 13 | fi 14 | } 15 | if [ -n $1 ]; then 16 | if [ "$1" = "-v" ]; then 17 | verbose="-t" 18 | elif [ "$1" = "-s" ]; then 19 | svn_exec="0"; 20 | fi 21 | fi 22 | 23 | 24 | list=`wcfind . -type f \( ! -perm /u+x -o ! -perm /g+x -o ! -perm /o+x \) -exec file {} \; | grep executable | sed 's/:.*//'` 25 | if [ "$list" != "" ] ;then 26 | echo "$list" | sed 's/ /\\ /g' | xargs $verbose chmod 755 27 | if [ "$svn_exec" = "0" ]; then 28 | echo "$list" | sed 's/ /\\ /g' | xargs svn ps svn:executable true 29 | fi 30 | fi 31 | 32 | list=`wcfind . -type f -perm +0111 -exec file {} \; | grep -v executable | sed 's/:.*//'` 33 | if [ "$list" != "" ] ; then 34 | echo "$list" | sed 's/ /\\ /g' | xargs $verbose chmod 644 35 | fi 36 | 37 | ALWAYS_EXEC_DIR="rootfs/usr/bin" 38 | friendly_remind $ALWAYS_EXEC_DIR 39 | ALWAYS_EXEC_DIR="rootfs/usr/sbin" 40 | friendly_remind $ALWAYS_EXEC_DIR 41 | ALWAYS_EXEC_DIR="rootfs/usr/share/www/cgi-bin/" 42 | friendly_remind $ALWAYS_EXEC_DIR 43 | 44 | 45 | echo "permission fixing completed." 46 | -------------------------------------------------------------------------------- /fdswap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Swap/Roll a logfile 4 | # 5 | # Usage: <old logfile> <new logfile> [ optional pids ] 6 | # ./swap.sh /var/log/logfile /tmp/logfile [pids] 7 | # 8 | # Author: Robert McKay <rob...@mckay.com> 9 | # Date: Tue Aug 14 13:36:35 BST 2007 10 | # 11 | # Update: Added usage message when needed, a fuser format fix, 12 | # some whitespace cleanup, and a localization fix. 13 | # Ingvar Hagelund <ingvar@redpill-linpro.com> 14 | # Date: Sat Jul 10 02:11:49 CEST 2010 15 | 16 | if [ "$2" = "" ]; then 17 | echo "Usage: $0 /path/to/oldfile /path/to/newfile [pids] 18 | Example: $0 /var/log/somedaemon.log /var/log/newvolume/somedaemon.log 1234 19 | Example: $0 /dev/pts/53 /dev/null 1234 20 | " 21 | exit 0 22 | fi 23 | 24 | if gdb --version > /dev/null 2>&1; then 25 | true 26 | else 27 | echo "Unable to find gdb." 28 | exit 1 29 | fi 30 | 31 | src=$1 32 | dst=$2 33 | shift; shift 34 | pids=$* 35 | 36 | for pid in ${pids:=$( /sbin/fuser $src | cut -d ':' -f 2 )}; 37 | do 38 | echo "src=$src, dst=$dst" 39 | echo "$src has $pid using it" 40 | ( 41 | echo "attach $pid" 42 | echo 'call open("'$dst'", 66, 0666)' 43 | for ufd in $(LANG=C ls -l /proc/$pid/fd | grep $src\$ | awk ' { print $9; } '); 44 | do 45 | echo 'call dup2($1,'"$ufd"')' 46 | done 47 | echo 'call close($1)' 48 | echo 'detach' 49 | echo 'quit' 50 | sleep 5 51 | ) | gdb -q -x - 52 | done 53 | 54 | -------------------------------------------------------------------------------- /subversion-scripts/svn-tearoff: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "${PRODUCTDIR}" ]; then 4 | echo "Please source environment file first!" 5 | exit 1 6 | fi 7 | 8 | if [ "$1" = "-h" ] || [ "$1" = "--h" ] || [ "$1" = "--help" ] ; then 9 | echo "Usage: cd ${PRODUCTDIR}; $0 [TEAROFF_FOLDERS]" 10 | exit 0 11 | fi 12 | 13 | cd ${PRODUCTDIR} 14 | BACKUP_FOLDER="${PRODUCTDIR}/_TearoffFromHorus" 15 | 16 | TEAROFF_FOLDERS=$@ 17 | if [ -z "$TEAROFF_FOLDERS" ]; then 18 | TEAROFF_FOLDERS=`hr ls | awk '{print $1}'` 19 | fi 20 | 21 | echo -e "It's gonna to tear off these folders from Horus: \n[$TEAROFF_FOLDERS]" 22 | echo -e "All the above folders will be move into $BACKUP_FOLDER temporally!\n" 23 | 24 | # A kindly reminding 25 | WARNING='\033[31;01m' 26 | NORMAL='\033[0m' 27 | echo -e "${WARNING}Press y to Continue${NORMAL}" 28 | read yn 29 | if [ "$yn" = "y" ] || [ "$yn" = "Y" ] ; then 30 | echo "God Bless You..." 31 | else 32 | exit 0 33 | fi 34 | 35 | # Create a backup folder 36 | [ -d $BACKUP_FOLDER ] || mkdir $BACKUP_FOLDER 37 | 38 | for folder in ${TEAROFF_FOLDERS} 39 | do 40 | WC_HOST=`svn-url ./ | cut -d '/' -f 3` 41 | FOLDER_HOST=`svn-url $folder | cut -d '/' -f 3` 42 | if [ "$WC_HOST" != "$FOLDER_HOST" ]; then 43 | echo "Repository Root is different, can't do svn cp..." 44 | else 45 | echo "Tear off" $folder" from Horus ... " 46 | mv $folder $BACKUP_FOLDER 47 | svn cp $BACKUP_FOLDER/$folder ./ 48 | hr rm $folder 49 | fi 50 | done 51 | 52 | -------------------------------------------------------------------------------- /ubnt-edge-switch-poe-on-off.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Usage: 4 | # $ ubnt-edge-switch-poe-on-off.sh 192.168.1.20 1 5 | 6 | USR=ubnt 7 | PWD=2rjudoru 8 | 9 | IP="$1" 10 | LANPORT="$2" 11 | 12 | echo "===== Disable PoE port: ${LANPORT} at ${IP} =====" 13 | 14 | # PoE Port Status 15 | nc ${IP} 23 >&1 2>&1 << EOF 16 | ${USR} 17 | ${PWD} 18 | enable 19 | ${PWD} 20 | configure 21 | show poe status 0/${LANPORT} 22 | EOF 23 | 24 | # Method 1 25 | #(echo "${USR}"; echo "${PWD}"; echo "enable"; echo "${PWD}"; echo "configure" ; echo "interface 0/${LANPORT}" ; echo "poe opmode shutdown") | nc ${IP} 23 26 | 27 | # Method 2 28 | #echo -e ${USR}"\n"${PWD}"\n"en"\n"${PWD}"\n"config"\n"interface 0/${LANPORT}"\n"poe opmode shutdown | nc ${IP} 23 29 | #echo -e "${USR}""\n""${PWD}""\n""enable""\n""${PWD}""\n""config""\n""interface 0/${LANPORT}""\n""poe opmode shutdown" | nc ${IP} 23 > /dev/null 2>&1 30 | 31 | # Method 3 32 | nc ${IP} 23 > /dev/null 2>&1 << EOF 33 | ${USR} 34 | ${PWD} 35 | enable 36 | ${PWD} 37 | configure 38 | interface 0/${LANPORT} 39 | poe opmode shutdown 40 | EOF 41 | 42 | # Sleep for 500ms 43 | sleep 0.5 44 | 45 | echo "===== Enable PoE port: ${LANPORT} at ${IP} =====" 46 | # Method 1 47 | # (echo "${USR}"; echo "${PWD}"; echo "enable"; echo "${PWD}"; echo "configure" ; echo "interface 0/${LANPORT}" ; echo "poe opmode auto") | nc ${IP} 23 48 | 49 | # Method 2 50 | echo -e "${USR}""\n""${PWD}""\n""enable""\n""${PWD}""\n""config""\n""interface 0/${LANPORT}""\n""poe opmode auto" | nc ${IP} 23 > /dev/null 2>&1 51 | 52 | -------------------------------------------------------------------------------- /subversion-scripts/svn-diprev: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | Usage () { 4 | echo "Usage: `basename $0` [PATH...]" 5 | exit 1 6 | } 7 | 8 | case "$1" in 9 | *-h*) 10 | Usage 11 | ;; 12 | esac 13 | 14 | svn log -r PREV $1 > /dev/null 2>&1 15 | 16 | if [ $? -eq 0 ]; then 17 | svn di --diff-cmd diff -x "-ruN --ignore-all-space" -r PREV:COMMITTED $1 | levis 18 | 19 | # Have the same result if BASE == COMMITTED, we could manually svn up -r[older version] foo.c to make produce this situation! 20 | # svn di -r PREV:BASE $1 | levis 21 | else 22 | # PATH check 23 | [ -n $1 ] && [ -e $1 ] || Usage || Usage 24 | svnUrl=`svn-url $1` 25 | repoRoot=`svn info $1 2> /dev/null | grep "^Repository Root:" | sed -e "s/^Repository Root: //"` 26 | 27 | IFS=$'\t ' 28 | svnParentLog=$(svn log -v --stop-on-copy $1 | grep " (from .*)") 29 | 30 | parentURL=${svnUrl/$repoRoot/} 31 | 32 | while [ 1 ]; do 33 | fromResult=$(echo $svnParentLog | grep "${parentURL/$tmpBasename/} ") 34 | [ $? -eq 0 ] && break || parentURL=${parentURL/$tmpBasename/} 35 | parentURLBasename=$(basename $parentURL) 36 | tmpBasename="/${parentURLBasename}" 37 | targetBasename="$tmpBasename$targetBasename" 38 | done 39 | 40 | fromURL=$(echo $fromResult | sed 's/\(.*\)from \(.*\):\(.*\))/\2/') 41 | fromRev=$(echo $fromResult | sed 's/\(.*\)from \(.*\):\(.*\))/\3/') 42 | 43 | #echo svn diff ${repoRoot}${fromURL}${targetBasename}@${fromRev} $svnUrl 44 | svn di --diff-cmd diff -x "-ruN --ignore-all-space" ${repoRoot}${fromURL}${targetBasename}@${fromRev} $svnUrl | levis 45 | fi 46 | 47 | -------------------------------------------------------------------------------- /ssh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | # If you fully UNDERSTAND what you are doing, it won't be annoying anymore 6 | # 7 | # $HOME/.ssh/config 8 | # Host 10.*.*.* 9 | # StrictHostKeyChecking no 10 | # UserKnownHostsFile /dev/null 11 | 12 | if [ $# -lt 1 ]; then 13 | echo "Usage: $0 <device ip> <args>" 14 | exit 15 | fi 16 | 17 | # load credentials if exists 18 | [ -r ~/.creds ] && . ~/.creds 19 | 20 | DEVICE_IP="$1" 21 | [ -n "$2" ] && ARGS="$2" 22 | 23 | echo "Waiting for device to go online" 24 | until nc -vzw 2 $DEVICE_IP 22 2>/dev/null; do sleep 0.3; done 25 | 26 | # Put .bashrc for busybox file on remote server 27 | BASHRC_BB=".bashrc_bb_v" 28 | SSH_OPTION_IGNORE_CHECK="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" 29 | for passwd in ${SSH_PASS:-root}; do 30 | sshpass -p ${passwd} scp -O $SSH_OPTION_IGNORE_CHECK `dirname $0`/$BASHRC_BB `dirname $0`/.tmux_uart.conf ${SSH_USER:-root}@[$DEVICE_IP]:/tmp/ 31 | [ $? -eq 0 ] && break || echo "try next..." 32 | done 33 | 34 | expect -c " 35 | set timeout 3 36 | spawn sshpass -p $passwd ssh $SSH_OPTION_IGNORE_CHECK ${SSH_USER:-root}@$DEVICE_IP 37 | 38 | send \"FROM_ID='`whoami`'\r\" 39 | send \"source /tmp/$BASHRC_BB\r\" 40 | 41 | send \"export PATH=\\\$PATH:/mnt/media/usr/bin:/usr/libexec\r\" 42 | send \"cat /mnt/persistent/calib/vivint.ini\r\" 43 | send \"cat /etc/version\r\" 44 | send \"tmux ls #HINT: tmux attach-session\r\" 45 | send \"$ARGS\r\" 46 | 47 | interact timeout 60 { } 48 | " 49 | 50 | # FIXME: It's weird/buggy to rewrite as below well-known form 51 | # expect << EOF 52 | # ... 53 | # ... 54 | # EOF 55 | 56 | -------------------------------------------------------------------------------- /subversion-scripts/svn-showchange: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use strict; 4 | 5 | # ==================================================================== 6 | # Show the log message and diff for a revision. 7 | # 8 | # $ showchange.pl REVISION [WC_PATH|URL] 9 | 10 | 11 | if ((scalar(@ARGV) == 0) 12 | or ($ARGV[0] eq '-?') 13 | or ($ARGV[0] eq '-h') 14 | or ($ARGV[0] eq '--help')) { 15 | print <<EOF; 16 | Show the log message and diff for a revision. 17 | usage: $0 REVISION [WC_PATH|URL] 18 | EOF 19 | exit 0; 20 | } 21 | 22 | my $revision = shift || die ("Revision argument required.\n"); 23 | if ($revision =~ /r([0-9]+)/) { 24 | $revision = $1; 25 | } 26 | 27 | my $url = shift || ""; 28 | 29 | my $svn = "svn"; 30 | 31 | my $prev_revision = $revision - 1; 32 | 33 | if (not $url) { 34 | # If no URL was provided, use the repository root from the current 35 | # directory's working copy. We want the root, rather than the URL 36 | # of the current dir, because when someone's asking for a change 37 | # by name (that is, by revision number), they generally don't want 38 | # to have to cd to a particular working copy directory to get it. 39 | my @info_lines = `${svn} info`; 40 | foreach my $info_line (@info_lines) { 41 | if ($info_line =~ s/^Repository Root: (.*)$/$1/e) { 42 | # Kent@20101123, apply chomp to remove line ending character. 43 | chomp($url = $info_line); 44 | } 45 | } 46 | } 47 | 48 | system ("${svn} log -v --incremental -r${revision} $url"); 49 | system ("${svn} diff -r${prev_revision}:${revision} ${url} | vim -c 'set ft=diff' -"); 50 | -------------------------------------------------------------------------------- /transfer.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Ref: https://gist.github.com/nl5887/a511f172d3fb3cd0e42d 3 | # Defines transfer alias and provides easy command line file and folder sharing. 4 | # 5 | # Authors: 6 | # Remco Verhoef <remco@dutchcoders.io> 7 | # 8 | 9 | curl --version 2>&1 > /dev/null 10 | if [ $? -ne 0 ]; then 11 | echo "Could not find curl." 12 | return 1 13 | fi 14 | 15 | # check arguments 16 | if [ $# -eq 0 ]; 17 | then 18 | echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" 19 | exit 1 20 | fi 21 | 22 | # get temporarily filename, output is written to this file show progress can be showed 23 | tmpfile=$( mktemp -t transferXXX ) 24 | 25 | # upload stdin or file 26 | file=$1 27 | 28 | if tty -s; 29 | then 30 | basefile=$(basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g') 31 | 32 | if [ ! -e $file ]; 33 | then 34 | echo "File $file doesn't exists." 35 | return 1 36 | fi 37 | 38 | if [ -d $file ]; 39 | then 40 | # zip directory and transfer 41 | zipfile=$( mktemp -t transferXXX.zip ) 42 | cd $(dirname $file) && zip -r -q - $(basename $file) >> $zipfile 43 | curl --progress-bar --upload-file "$zipfile" "https://transfer.sh/$basefile.zip" >> $tmpfile 44 | rm -f $zipfile 45 | else 46 | # transfer file 47 | curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> $tmpfile 48 | fi 49 | else 50 | # transfer pipe 51 | curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> $tmpfile 52 | fi 53 | 54 | # cat output link 55 | cat $tmpfile 56 | 57 | # cleanup 58 | rm -f $tmpfile 59 | echo 60 | -------------------------------------------------------------------------------- /osx/mount-tmp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | size=1024 # MB 4 | mount_point=$HOME/tmp 5 | name=$(basename "$mount_point") 6 | 7 | usage() { 8 | echo "usage: $(basename "$0") [mount | umount | remount | check | orphan]" \ 9 | "(default: mount)" >&2 10 | } 11 | 12 | process_argv() { 13 | [ $# -ge 0 -a $# -le 1 ] || { usage; exit 1; } 14 | case "$1" in 15 | "") cmd_mount ;; 16 | "mount") cmd_mount ;; 17 | "umount") cmd_umount ;; 18 | "remount") cmd_remount ;; 19 | "check") cmd_check ;; 20 | "orphan") cmd_orphan ;; 21 | *) usage ;; 22 | esac 23 | } 24 | 25 | cmd_check() { 26 | is_mounted 27 | } 28 | 29 | cmd_mount() { 30 | if is_mounted; then 31 | echo "Already mounted at $mount_point" >&2 32 | return 1 33 | fi 34 | 35 | sectors=$(( $size * 1024 * 1024 / 512 )) 36 | dev=$(hdiutil attach -nomount ram://$sectors) \ 37 | && newfs_hfs -v "$name" $dev \ 38 | && mount -t hfs -o nobrowse $dev "$mount_point" \ 39 | && echo "Hello, world!" > "$mount_point"/hello_world \ 40 | && echo "Mounted $name ($size MB) at $mount_point" 41 | } 42 | 43 | cmd_umount() { 44 | dev=$(df "$mount_point" | tail -1 | awk '{ print $1 }') 45 | [ $dev ] || return 1 46 | umount "$mount_point" && hdiutil detach "$dev" 47 | } 48 | 49 | cmd_remount() { 50 | if is_mounted; then cmd_umount else true; fi \ 51 | && cmd_mount 52 | } 53 | 54 | cmd_orphan() { 55 | hdiutil info | egrep 'image-path\s+: ram://' -A14 | egrep '^/dev/disk\d+\s*$' 56 | return 0 57 | } 58 | 59 | is_mounted() { 60 | mount | grep -q " on $mount_point " 61 | } 62 | 63 | process_argv "$@" 64 | -------------------------------------------------------------------------------- /tag_rebuild: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ################################################################################# 3 | # By Kent 4 | # -R: Recurse directories for files 5 | # -b: Build the cross-reference only 6 | # -k: Kernel Mode - don't use /usr/include for #include files 7 | # -q: Build an inverted index for quick symbol searching 8 | # #cscope just scan *.c & *.h by default, if u want to scan other extension type, do it by below 9 | # find . -name "*.h" -o -name "*.c" -o -name "*.cc" > cscope.files 10 | # cscope -bkq -i cscope.files 11 | ################################################################################ 12 | 13 | WORK_PATH=$1 14 | CSCOPE_TAG_PATH=$2 15 | CTAGS_PRG=ctags 16 | 17 | [ -z "$WORK_PATH" ] && WORK_PATH="" || cd $WORK_PATH 18 | 19 | echo "cscope ... " $WORK_PATH 20 | find . -type f \ 21 | \( -name "*.c" \ 22 | -o -name "*.cc" \ 23 | -o -name "*.cpp" \ 24 | -o -name "*.cxx" \ 25 | -o -name "*.h" \ 26 | -o -name "*.hh" \ 27 | -o -name "*.hpp" \ 28 | -o -name "*.hxx" \ 29 | -o -name "*.inc" \ 30 | -o -name "*.java" \ 31 | \) \ 32 | > cscope.files 33 | 34 | cscope -bkqR -i cscope.files 35 | 36 | echo "ctags ... " $WORK_PATH 37 | #ctags -R --fields=+lS 38 | ctags -R --c-kinds=+p --fields=+ialS --extras=+q --exclude=*jquery* -L cscope.files 39 | #ctags -R --c++-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+v --fields=+liaS --extra=+q --language-force=c++ --exclude=*jquery* 40 | 41 | [ -n "$CSCOPE_TAG_PATH" ] && cp cscope.* tags $CSCOPE_TAG_PATH || echo "Done!" 42 | 43 | # GNU GLOBAL (gtags) treats *.h files as a C source file, treat them as a C++ source file also by set GTAGSFORCECPP 44 | GTAGSLABEL='ctags' GTAGSFORCECPP=0 gtags -f cscope.files 45 | -------------------------------------------------------------------------------- /ubnt-discover-and-action.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # A simple way to batch upload camera fw: 4 | # $ discover | grep UVC | cut -d ' ' -f 2` > uvc_list.txt 5 | # $ for i in $(cat uvc_list.txt); do upload_bin $i UVC.bin; done 6 | 7 | # A fancy way to get managed & connected UVC 8 | # wget --no-check-certificate -qO- 'https://10.0.0.1:7443/api/2.0/camera?apiKey=ooxx&managed=true&state=CONNECTED' | jq '.data[].host' 9 | 10 | 11 | if [ $# -lt 1 ]; then 12 | echo "Usage: $0 <command>" 13 | exit 0 14 | fi 15 | 16 | SSHCMD="$1" 17 | 18 | # get ssh command from STDIN 19 | [ "$SSHCMD" == "-" ] && SSHCMD="$(cat)" 20 | 21 | SSH_OPTION_IGNORE_CHECK="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" 22 | 23 | tmpdir=$(mktemp -d) 24 | deviceresults="${tmpdir}/ubnt_device_results.json" 25 | devicelist="${tmpdir}/ubnt_device_list.json" 26 | 27 | # filter out results other than UVC 28 | echo '{ "devices": [' >> $deviceresults 29 | discover -j | grep "UVC." >> $deviceresults 30 | echo ']}' >> $deviceresults 31 | 32 | jq . $deviceresults > $devicelist 33 | 34 | cat $devicelist | jq '.devices[].fwversion' | nl -v 0 > "${tmpdir}/uvc_list.json" 35 | 36 | for i in $(cat "${tmpdir}/uvc_list.json" | awk '{print $1}'); do 37 | camip=$(cat $devicelist | jq ".devices[${i}].ipv4" | tr -d '"') 38 | fwversion=$(cat $devicelist | jq ".devices[${i}].fwversion" | tr -d '"') 39 | 40 | echo IP: $camip 41 | echo FW: $fwversion 42 | 43 | #sshpass -p ${SSH_PASS:-ubnt} ssh $SSH_OPTION_IGNORE_CHECK ${SSH_USER:-ubnt}@$camip "${SSHCMD}" 44 | ssh.sh $camip "${SSHCMD}" 45 | echo ======================================================================== 46 | done 47 | 48 | rm -rf $tmpdir 49 | -------------------------------------------------------------------------------- /upload_bin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ $# -lt 2 ]; then 4 | echo "Usage: $0 <DEVICE_IP> <FW_BIN>" 5 | exit 0 6 | fi 7 | 8 | # load credentials if exists 9 | [ -r ~/.creds ] && . ~/.creds 10 | 11 | DEVICE_IP="$1" 12 | FW_BIN="$2" 13 | 14 | if [ "$FW_BIN" = "-" ]; then 15 | . ubnt-devel-aircam 16 | FW_BIN=$PRODUCTDIR/rel-firmware.bin 17 | fi 18 | 19 | echo Firmware name: "$(basename "$FW_BIN")" 20 | 21 | SSH_OPTION_IGNORE_CHECK="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" 22 | 23 | # Methond 1: Simpler way but not preseting scp uploading progress 24 | # Methond 2: Use ssh key for auth instead of sshpass 25 | METHOD=2 26 | 27 | case $METHOD in 28 | 1) 29 | sshpass -p ${SSH_PASS:-ubnt} scp -O $SSH_OPTION_IGNORE_CHECK "$FW_BIN" ${SSH_USER:-ubnt}@"$DEVICE_IP":/tmp/fwupdate.bin 30 | sshpass -p ${SSH_PASS:-ubnt} ssh $SSH_OPTION_IGNORE_CHECK ${SSH_USER:-ubnt}@"$DEVICE_IP" /usr/bin/fwupdate -m || echo "FW upload fail!" 31 | ;; 32 | 2) 33 | KEY="$HOME/.ssh/id_rsa_ubnt" 34 | if [ ! -e "$KEY" ]; then 35 | ssh-keygen -t rsa -N "" -f "$KEY" 36 | fi 37 | 38 | for passwd in ${SSH_PASS:-ubnt}; do 39 | #sshpass -p ${passwd} ssh-copy-id $SSH_OPTION_IGNORE_CHECK -i "$KEY".pub ${SSH_USER:-ubnt}@"$DEVICE_IP" >/dev/null 2>&1 40 | sshpass -p ${passwd} ssh ${SSH_USER:-ubnt}@"$DEVICE_IP" "tee -a /etc/dropbear/authorized_keys" < "$KEY".pub >/dev/null 2>&1 41 | 42 | [ $? -eq 0 ] || { echo "try next..."; continue; } 43 | scp -O $SSH_OPTION_IGNORE_CHECK -i "$KEY" "$FW_BIN" ${SSH_USER:-ubnt}@"$DEVICE_IP":/tmp/fwupdate.bin 44 | [ $? -eq 0 ] && { ssh -i "$KEY" ${SSH_USER:-ubnt}@"$DEVICE_IP" /usr/bin/fwupdate -m; exit $?; } || echo "FW upload fail!" 45 | done 46 | ;; 47 | esac 48 | 49 | -------------------------------------------------------------------------------- /subversion-scripts/svndiff_helper: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Author: http://carlo-notes.blogspot.com/ 4 | # Github: https://github.com/c4rlo/Subversion-scripts 5 | # 6 | # This is a simple wrapper intended for use with the --diff-cmd argument of 7 | # 'svn diff' (or indeed 'svndiff') and uses gvimiff as the diffing tool. 8 | # It makes Vim name the buffers according to what Subversion passes in 9 | # as the names for the files. This may look like 10 | # file.c (.../trunk/file.c) (revision 72) 11 | # Note the tabs and slashes. Both confuse Vim, so we replace whitespace by 12 | # regular spaces and slashes by backslashes. 13 | # Also, we ensure that we get nice syntax highlighting in Vim by creating 14 | # symlinks with appropriate extensions to the temp files we are given. 15 | # The easiest way to use this script is by setting 16 | # diff-cmd = svndiff_helper 17 | # in section [helpers] in your ~/.subversion/config. 18 | 19 | import sys, re, subprocess, os, os.path 20 | 21 | n1, n2 = sys.argv[3], sys.argv[5] 22 | f1, f2 = sys.argv[6], sys.argv[7] 23 | 24 | def lntemp(f, n): 25 | fn = n.split('\t')[0] 26 | ext = os.path.splitext(fn)[1] 27 | if ext not in ("", os.path.splitext(f)[1]): 28 | tmpfn = f + ext 29 | os.symlink(os.path.basename(f), tmpfn) 30 | return tmpfn 31 | else: return f 32 | 33 | lf1 = lntemp(f1, n1) 34 | lf2 = lntemp(f2, n2) 35 | 36 | def sanitise(n): 37 | n = re.sub(r'\s+', r'\ ', n) 38 | n = re.sub(r'/', r'\\\\', n) 39 | return n 40 | 41 | vim_rc = subprocess.call(['vim', '-dR', 42 | '--cmd', "au BufReadPost " + lf1 + " silent f " + sanitise(n1), 43 | '--cmd', "au BufReadPost " + lf2 + " silent f " + sanitise(n2), 44 | lf1, lf2]) 45 | 46 | if lf1 != f1: os.remove(lf1) 47 | if lf2 != f2: os.remove(lf2) 48 | 49 | sys.exit(vim_rc) 50 | 51 | -------------------------------------------------------------------------------- /color-spaces-3-byte.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Author: Todd Larason <jtl@molehill.org> 3 | # $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.1 1999/07/11 08:49:54 dawes Exp $ 4 | 5 | print "256 color mode\n\n"; 6 | 7 | # display back ground colors 8 | 9 | for ($fgbg = 38; $fgbg <= 48; $fgbg +=10) { 10 | 11 | # first the system ones: 12 | print "System colors:\n"; 13 | for ($color = 0; $color < 8; $color++) { 14 | print "\x1b[${fgbg};5;${color}m::"; 15 | } 16 | print "\x1b[0m\n"; 17 | for ($color = 8; $color < 16; $color++) { 18 | print "\x1b[${fgbg};5;${color}m::"; 19 | } 20 | print "\x1b[0m\n\n"; 21 | 22 | # now the color cube 23 | print "Color cube, 6x6x6:\n"; 24 | for ($green = 0; $green < 6; $green++) { 25 | for ($red = 0; $red < 6; $red++) { 26 | for ($blue = 0; $blue < 6; $blue++) { 27 | $color = 16 + ($red * 36) + ($green * 6) + $blue; 28 | print "\x1b[${fgbg};5;${color}m::"; 29 | } 30 | print "\x1b[0m "; 31 | } 32 | print "\n"; 33 | } 34 | 35 | # now the grayscale ramp 36 | print "Grayscale ramp:\n"; 37 | for ($color = 232; $color < 256; $color++) { 38 | print "\x1b[${fgbg};5;${color}m::"; 39 | } 40 | print "\x1b[0m\n\n"; 41 | 42 | } 43 | 44 | print "Examples for the 3-byte color mode\n\n"; 45 | 46 | for ($fgbg = 38; $fgbg <= 48; $fgbg +=10) { 47 | 48 | # now the color cube 49 | print "Color cube\n"; 50 | for ($green = 0; $green < 256; $green+=51) { 51 | for ($red = 0; $red < 256; $red+=51) { 52 | for ($blue = 0; $blue < 256; $blue+=51) { 53 | print "\x1b[${fgbg};2;${red};${green};${blue}m::"; 54 | } 55 | print "\x1b[0m "; 56 | } 57 | print "\n"; 58 | } 59 | 60 | # now the grayscale ramp 61 | print "Grayscale ramp:\n"; 62 | for ($gray = 8; $gray < 256; $gray+=10) { 63 | print "\x1b[${fgbg};2;${gray};${gray};${gray}m::"; 64 | } 65 | print "\x1b[0m\n\n"; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /threadsafe: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # print functions in C/C++ files that are not threadsafe 4 | # Example usage: 5 | # $ threadsafe 6 | # If no files passed then the total list of functions 7 | # that are not threadsafe is printed. 8 | # 9 | # Obviously your man pages need to be accurate for this to work. 10 | # Redhat 9 has woefully incomplete man pages, 11 | # Fedora Core 3 (man-pages-1.67) has at least 12 12 | # missing entries from apropos (gethostbyname_r for e.g.). 13 | # ubuntu 5.10 (manpages-2.02-2) does seem to be up to date though. 14 | # 15 | # TODO: remove false positives like .ctime ->rand ... 16 | 17 | THREAD_UNSAFE_LIST=" 18 | asctime 19 | ctime 20 | drand48 21 | ecvt 22 | encrypt 23 | erand48 24 | ether_aton 25 | ether_ntoa 26 | fcvt 27 | fgetgrent 28 | fgetpwent 29 | getaliasbyname 30 | getaliasent 31 | getdate 32 | getgrent 33 | getgrgid 34 | getgrnam 35 | getlogin 36 | gethostbyaddr 37 | gethostbyname 38 | gethostbyname2 39 | getmntent 40 | getnetgrent 41 | getpwent 42 | getpwnam 43 | getpwuid 44 | getutent 45 | getutid 46 | getutline 47 | gmtime 48 | hcreate 49 | hdestroy 50 | hsearch 51 | initstate 52 | jrand48 53 | lcong48 54 | lgamma 55 | lgammaf 56 | lgammal 57 | localtime 58 | lrand48 59 | mrand48 60 | nrand48 61 | ptsname 62 | qecvt 63 | qfcvt 64 | rand 65 | random 66 | readdir 67 | readdir64 68 | seed48 69 | setkey 70 | setstate 71 | srand48 72 | srandom 73 | #strerror 74 | strtok 75 | tmpnam 76 | ttyname 77 | " 78 | 79 | for i in $THREAD_UNSAFE_LIST; do 80 | #statements 81 | LANG=C grep $i -F -w -n --color="auto" `find -name '*.c' -o -name '*.h' -o -name '*.cpp'` 82 | done 83 | exit 0 84 | 85 | # Original method 86 | apropos "_r" | 87 | sed -n 's#\(.*\)_r .*#\1#p' | 88 | uniq | #remove duplicates (from posix section for example) 89 | LANG=C grep -F -f- -w -n --color="auto" `find -name '*.c' -o -name '*.h' -o -name '*.cpp'` 90 | 91 | -------------------------------------------------------------------------------- /256colors2.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Author: Todd Larason <jtl@molehill.org> 3 | # $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.2 2002/03/26 01:46:43 dickey Exp $ 4 | 5 | # use the resources for colors 0-15 - usually more-or-less a 6 | # reproduction of the standard ANSI colors, but possibly more 7 | # pleasing shades 8 | 9 | # colors 16-231 are a 6x6x6 color cube 10 | for ($red = 0; $red < 6; $red++) { 11 | for ($green = 0; $green < 6; $green++) { 12 | for ($blue = 0; $blue < 6; $blue++) { 13 | printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\", 14 | 16 + ($red * 36) + ($green * 6) + $blue, 15 | ($red ? ($red * 40 + 55) : 0), 16 | ($green ? ($green * 40 + 55) : 0), 17 | ($blue ? ($blue * 40 + 55) : 0)); 18 | } 19 | } 20 | } 21 | 22 | # colors 232-255 are a grayscale ramp, intentionally leaving out 23 | # black and white 24 | for ($gray = 0; $gray < 24; $gray++) { 25 | $level = ($gray * 10) + 8; 26 | printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\", 27 | 232 + $gray, $level, $level, $level); 28 | } 29 | 30 | 31 | # display the colors 32 | 33 | # first the system ones: 34 | print "System colors:\n"; 35 | for ($color = 0; $color < 8; $color++) { 36 | print "\x1b[48;5;${color}m "; 37 | } 38 | print "\x1b[0m\n"; 39 | for ($color = 8; $color < 16; $color++) { 40 | print "\x1b[48;5;${color}m "; 41 | } 42 | print "\x1b[0m\n\n"; 43 | 44 | # now the color cube 45 | print "Color cube, 6x6x6:\n"; 46 | for ($green = 0; $green < 6; $green++) { 47 | for ($red = 0; $red < 6; $red++) { 48 | for ($blue = 0; $blue < 6; $blue++) { 49 | $color = 16 + ($red * 36) + ($green * 6) + $blue; 50 | print "\x1b[48;5;${color}m "; 51 | } 52 | print "\x1b[0m "; 53 | } 54 | print "\n"; 55 | } 56 | 57 | 58 | # now the grayscale ramp 59 | print "Grayscale ramp:\n"; 60 | for ($color = 232; $color < 256; $color++) { 61 | print "\x1b[48;5;${color}m "; 62 | } 63 | print "\x1b[0m\n"; 64 | -------------------------------------------------------------------------------- /ubifs-mount-by-sudo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # sudo rmmod ubifs ubi nandsim nand mtdblock mtd_blkdevs cmdlinepart mtd 4 | 5 | usage() 6 | { 7 | echo "usage: $(basename "$0") <mount | umount> <path-to-ubi-image> <gen> <mount-point>" 8 | } 9 | 10 | mount_ubi() 11 | { 12 | lsmod |grep nandsim > /dev/null 13 | if [ $? -ne 0 ]; then 14 | sudo modprobe mtdblock 15 | sudo modprobe ubi 16 | sudo modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 fourth_id_byte=0x15 17 | sudo chmod 660 /dev/mtd* 18 | sudo mkdir $MOUNT_POINT > /dev/null 2>&1 19 | fi 20 | 21 | sudo dd if=$UBI_IMAGE of=/dev/mtdblock0 22 | 23 | # Why does ubiattach on a freshly formatted device fail with "Invalid argument"? 24 | # http://www.linux-mtd.infradead.org/faq/ubi.html#L_vid_offset_mismatch 25 | case "$GEN" in 26 | *gen2*) 27 | sudo ubiattach /dev/ubi_ctrl -m 0 28 | ;; 29 | *gen3*) 30 | sudo ubiattach /dev/ubi_ctrl -m 0 -O 2048 31 | ;; 32 | esac 33 | 34 | sudo mount -t ubifs ubi0 $MOUNT_POINT 35 | [ $? -eq 0 ] && echo "Mount successfully on: $MOUNT_POINT" 36 | } 37 | 38 | umount_ubi() 39 | { 40 | sudo umount $MOUNT_POINT 41 | sudo ubidetach -m 0 42 | 43 | # Due to some speical case, kernel moduels have to be rmmod/insmod to make 44 | # it work properly under certern condition, e.g., 45 | # When you try to ubiattach between two different "VID header offset" image 46 | # GEN3 => UBI: VID header offset: 2048 (aligned 2048), data offset: 4096 47 | # GEN2 => UBI: VID header offset: 512 (aligned 512), data offset: 2048 48 | 49 | lsmod |grep nandsim > /dev/null 50 | if [ $? -eq 0 ]; then 51 | sudo rmmod ubifs ubi nandsim nand mtdblock mtd_blkdevs cmdlinepart mtd 52 | fi 53 | } 54 | 55 | [ $# -lt 1 ] && { usage; exit 1; } 56 | 57 | UBI_IMAGE="$2" 58 | GEN="$3" 59 | MOUNT_POINT="${4:-/mnt/ubi}" 60 | 61 | case "$1" in 62 | "mount") mount_ubi ;; 63 | "umount") umount_ubi ;; 64 | *) usage ;; 65 | esac 66 | -------------------------------------------------------------------------------- /wcfind_: -------------------------------------------------------------------------------- 1 | #!/bin/sh -f 2 | # ---------------------------------------------------------------------------- 3 | # Amarganth Development Environment 4 | # Copyright (C) 2004, Jeff Hung 5 | # All rights reserved. 6 | # ---------------------------------------------------------------------------- 7 | # $Date$ 8 | # $Rev$ 9 | # $Author$ 10 | # ---------------------------------------------------------------------------- 11 | # revid: "@(#) $Id$" 12 | # ---------------------------------------------------------------------------- 13 | 14 | __revision=`echo '$Rev$' | cut -d' ' -f2`; 15 | __rev_date=`echo '$Date$' | cut -d' ' -f2`; 16 | __pname=`basename $0`; 17 | 18 | __usage() 19 | { 20 | local ex=0; 21 | if [ $# -gt 0 ]; then 22 | ex=$1; shift; 23 | fi; 24 | echo >&2 "\ 25 | Usage: $__pname [ <grep-option> ... ] <pattern> [ <path> ... ] 26 | 27 | Examples: 28 | 29 | SHELL> $__pname . -type f -name '*.h' -or -name '*.cpp' 30 | 31 | SHELL> $__pname . -type f \\ 32 | \`file-type-patterns.sh lang-cpp \\ 33 | | xargs -n 1 -I \& echo '-or -name &' \\ 34 | | xargs echo \\ 35 | | sed -e s/^-or//\` \\ 36 | ; 37 | 38 | Revision: r${__revision} (${__rev_date}) 39 | "; 40 | if [ $# -gt 0 ]; then 41 | echo >&2 ""; 42 | echo >&2 "Error: $@"; 43 | fi; 44 | exit $ex; 45 | } 46 | 47 | __path=''; 48 | __find_args=''; 49 | while [ $# -gt 0 ]; do 50 | __arg="$1"; shift; 51 | if [ -z "$__path" ]; then 52 | __path="$__arg"; 53 | else 54 | __find_args="$__find_args $__arg"; 55 | fi; 56 | done; 57 | if [ -z "${__path}" ]; then 58 | __usage; 59 | fi; 60 | if [ -z "$__find_args" ]; then 61 | # jeffhung.20060124: 62 | # - Useful to follow after -or to maintain find(1) command-line syntax, but 63 | # is redundant actually. 64 | __find_args="-mindepth 0"; 65 | fi; 66 | 67 | find "$__path" -type d -regex '.*/\.svn' -prune -or $__find_args \ 68 | | grep -v '.*/\.svn$' \ 69 | ; 70 | 71 | -------------------------------------------------------------------------------- /Vivotekbot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #This is a Vivotekbot (similar to Googlebot), to automatically request something from camera! 3 | 4 | echo -n "Network-Camera login:" 5 | read username 6 | echo -n "Password:" 7 | read password 8 | echo -n "Camera IP Address:" 9 | read ipaddr 10 | 11 | #$RANDOM -> /dev/random (0~32767) 12 | declare -i randomNumber 13 | 14 | cgi_array=(system network ipfilter ddns videoin image motion security privacymask event server media recording ircutctrl capability layout) 15 | wagpage_array=(system security https network ddns accesslist video motin tampering homelayout application recording syslog parafile maintain) 16 | 17 | # get length of an array 18 | #echo "${#cgi_array[@]}" 19 | #echo "${#wagpage_array[@]}" 20 | 21 | RandomSleep() 22 | { 23 | #let randomNumber belong to 0~60 24 | randomNumber=$RANDOM*60/32767 25 | echo "sleep $randomNumber" 26 | randomNumber=1 27 | sleep $randomNumber 28 | } 29 | 30 | while [ 1 ] 31 | do 32 | #Get a video.jpg 33 | echo "GET: /cgi-bin/viewer/video.jpg" 34 | curl -u $username:$password http://$ipaddr/cgi-bin/viewer/video.jpg -o /dev/null > /dev/null 2>&1 & 35 | RandomSleep 36 | 37 | #Get a cgi command 38 | ranNumCgi=$RANDOM*${#cgi_array[@]}/32767 39 | echo "CGI: /cgi-bin/admin/getparam.cgi?${cgi_array[$ranNumCgi]}" 40 | curl -u $username:$password http://$ipaddr/cgi-bin/admin/getparam.cgi?${cgi_array[$ranNumCgi]} -o /dev/null > /dev/null 2>&1 & 41 | #echo "curl -u $username:$password http://$ipaddr/cgi-bin/admin/getparam.cgi?${cgi_array[$ranNumCgi]} -o /dev/null > /dev/null 2>&1 &" 42 | RandomSleep 43 | 44 | #Get a webpage.html 45 | ranNumWebpage=$RANDOM*${#wagpage_array[@]}/32767 46 | echo "GET: /setup/${wagpage_array[$ranNumWebpage]}.html" 47 | curl -u $username:$password http://$ipaddr/setup/$wagpage_array[$ranNumWebpage].html -o /dev/null > /dev/null 2>&1 & 48 | #echo "curl -u $username:$password http://$ipaddr/setup/${wagpage_array[$ranNumWebpage]}.html -o /dev/null > /dev/null 2>&1 &" 49 | RandomSleep 50 | done 51 | -------------------------------------------------------------------------------- /wcfind: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright 2007 Max Bowsher 4 | # Licensed under the terms Subversion ships under 5 | 6 | # Runs the 'find' program, with arguments munged such that '.svn' or 'CVS' 7 | # working copy administrative directories and their contents are ignored. 8 | 9 | optspaths= 10 | expropts= 11 | exproptarg= 12 | exprmain= 13 | depth= 14 | somethingseen= 15 | phase=optspaths 16 | print=-print 17 | for option in "$@"; do 18 | if [ "$phase" = "optspaths" ]; then 19 | case $option in 20 | -H|-L|-P) ;; 21 | -*|"("*|")"*|,*|!*) phase=exprmain ;; 22 | *) ;; 23 | esac 24 | fi 25 | if [ "$exproptarg" = "yes" ]; then 26 | exproptarg= 27 | phase=expropts 28 | fi 29 | if [ "$phase" = "exprmain" ]; then 30 | case $option in 31 | -depth|-d) depth=yes ;; 32 | -delete|-exec|-exec|-execdir|-execdir|-fls|-fprint|-fprint0 \ 33 | |-fprintf|-ok|-print|-okdir|-print0|-printf|-quit|-ls) print= ;; 34 | esac 35 | case $option in 36 | -depth|-d|-noleaf|-mount|-xdev|-warn|-nowarn \ 37 | |-ignore_readdir_race|-noignore_readdir_race) phase=expropts ;; 38 | -maxdepth|-mindepth|-regextype) phase=expropts; exproptarg=yes ;; 39 | -follow|-daystart) ;; 40 | *) somethingseen=yes 41 | esac 42 | fi 43 | eval "$phase=\"\$$phase \\\"$option\\\"\"" 44 | if [ "$phase" = "expropts" ]; then 45 | phase=exprmain 46 | fi 47 | done 48 | 49 | if [ -z "$somethingseen" ]; then 50 | exprmain="$exprmain -print" 51 | print= 52 | fi 53 | 54 | if [ "$depth" = "yes" ]; then 55 | eval find $optspaths $expropts \ 56 | -regex \''.*/\.svn'\' -or -regex \''.*/\.svn/.*'\' \ 57 | -or -regex \''.*/CVS'\' -or -regex \''.*/CVS/.*'\' \ 58 | -or -regex \''.*/\.git'\' -or -regex \''.*/\.git/.*'\' \ 59 | -or '\(' $exprmain '\)' $print 60 | else 61 | eval find $optspaths $expropts '\(' -name .svn -or -name CVS -or -name .git '\)' -prune \ 62 | -or '\(' $exprmain '\)' $print 63 | fi 64 | -------------------------------------------------------------------------------- /apropos: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # apropos -- search the whatis database for keywords. 4 | # whatis -- idem, but match only commands (as whole words). 5 | # 6 | # Copyright (c) 1990, 1991, John W. Eaton. 7 | # Copyright (c) 1994-1999, Andries E. Brouwer. 8 | # 9 | # You may distribute under the terms of the GNU General Public 10 | # License as specified in the README file that comes with the man 11 | # distribution. 12 | # 13 | # apropos/whatis-1.5m aeb 2003-08-01 (from man-1.6d) 14 | # 15 | # keep old PATH - 000323 - Bryan Henderson 16 | # also look in /var/cache/man - 030801 - aeb 17 | 18 | program=`basename $0` 19 | 20 | # When man pages in your favorite locale look to grep like binary files 21 | # (and you use GNU grep) you may want to add the 'a' option to *grepopt1. 22 | aproposgrepopt1='ai' 23 | aproposgrepopt2='' 24 | whatisgrepopt1='aiw' 25 | whatisgrepopt2='^' 26 | grepopt1=$aproposgrepopt1 27 | grepopt2=$aproposgrepopt2 28 | 29 | if [ $# = 0 ] 30 | then 31 | echo "usage: $program keyword ..." 32 | exit 1 33 | fi 34 | 35 | manpath=`/usr/bin/man --path | tr : '\040'` 36 | 37 | if [ "$manpath" = "" ] 38 | then 39 | echo "$program: manpath is null" 40 | exit 1 41 | fi 42 | 43 | args= 44 | for arg in $*; do 45 | case $arg in 46 | --version|-V|-v) 47 | echo "$program from man-1.6d" 48 | exit 0 49 | ;; 50 | --help|-h) 51 | echo "usage: $program keyword ..." 52 | exit 0 53 | ;; 54 | -*) 55 | echo "$program: $arg: unknown option" 56 | exit 1 57 | ;; 58 | *) 59 | args="$args $arg" 60 | esac 61 | done 62 | 63 | while [ "$1" != "" ] 64 | do 65 | found=0 66 | for d in /var/cache/man $manpath /usr/lib 67 | do 68 | if [ -f $d/whatis ] 69 | then 70 | if grep -"$grepopt1" "$grepopt2""$1" $d/whatis 71 | then 72 | found=1 73 | # Some people are satisfied with a single occurrence 74 | # But it is better to give all 75 | # break 76 | fi 77 | fi 78 | done 79 | 80 | if [ $found = 0 ] 81 | then 82 | echo "$1: nothing appropriate" 83 | fi 84 | 85 | shift 86 | done 87 | 88 | exit 89 | -------------------------------------------------------------------------------- /macos-pf-throttle.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Sets up outgoing dummynet in pf firewall suitable for use to throttle outgoing network 4 | # connections. gtihub.com/tylertreat/comcast is a much nicer tool but I couldn't get it to work due 5 | # to shell issues and more - it seemed to only setup inbound rules in pf which don't affect outbound 6 | # TCP connections in my tests. 7 | 8 | TARGET=$1 9 | PIPECFG=${2:-"plr 1"} 10 | 11 | if [ -z "$1" ]; then 12 | echo "Usage: $0 <target> <pipe config - leave blank to drop all>" 13 | echo '' 14 | echo "EXAMPLES:" 15 | echo '' 16 | echo "$0 'port 12345'" 17 | echo " - drops all outgoing packets to port 12345 silently" 18 | echo '' 19 | echo "$0 'example.com' 'plr 0.1'" 20 | echo " - simulates packet loss of 10% for traffic to example.com (IP looked up)" 21 | echo '' 22 | echo "$0 '192.168.2.3 port 443' 'bw 300Kbit/s delay 100'" 23 | echo " - simulates 300Kb/s bandwidth and round trip time of 100ms for traffic to 192.168.2.3:443" 24 | echo '' 25 | echo 'For more details on target syntax refer to `man pf.conf` under PACKET FILTERING.' 26 | echo 'For more details on traffic throttling syntax refer to `man dnutil`.' 27 | echo '' 28 | echo 'You can inspect the rules added using `sudo pfctl -sa` and `sudo dnctl list`.' 29 | exit 1 30 | fi 31 | 32 | # Enable firewall if necessary 33 | sudo pfctl -e 2>/dev/null 34 | 35 | # Setup dummy net 36 | { 37 | cat /etc/pf.conf 38 | echo "dummynet-anchor \"mop\"" 39 | echo "anchor \"mop\"" 40 | #echo "dummynet out from any to $TARGET pipe 1" 41 | echo "dummynet in quick from $TARGET to any pipe 1" 42 | # Supress noisy ALTQ nonsense but keep stderr messages from bad filter syntax 43 | } | sudo pfctl -f - 2> >(grep -v 'ALTQ\|pf.conf\|flushing of rules\|present in the main ruleset\|^$') 44 | 45 | # Create pipe 46 | sudo dnctl pipe 1 config $PIPECFG 47 | 48 | # Wait for input 49 | read -p "Press any key to stop throttling traffic" 50 | 51 | # Teardown Pipe 52 | sudo dnctl -q flush 53 | 54 | # Reset pf 55 | sudo pfctl -f /etc/pf.conf 2> >(grep -v 'ALTQ\|pf.conf\|flushing of rules\|present in the main ruleset\|^$') 56 | 57 | echo "Finished shaping traffic" 58 | 59 | -------------------------------------------------------------------------------- /subversion-scripts/svn-tag2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 0.99 cent 4 | 5 | function detect_tag_repo 6 | { 7 | echo "Tag repository is not specified, autodetecting..." 8 | 9 | tag_repo=`echo $trunk_repo | sed -e "s:\(.*\)/trunk[/]\?$:\1/tag/$brand:"` 10 | # search tag repo path 11 | echo " Searching $tag_repo" 12 | svn ls $tag_repo > /dev/null 2>&1 13 | if [ "$?" -ne "0" ]; then 14 | # tag_repo might not exist, find tags 15 | tag_repo=`echo $trunk_repo | sed -e "s:\(.*\)/trunk[/]\?$:\1/tags/$brand:"` 16 | echo " Searching $tag_repo" 17 | svn ls $tag_repo > /dev/null 2>&1 18 | if [ "$?" -ne "0" ] ; then 19 | # unable to guess tag repo path, give up 20 | tag_repo="" 21 | fi 22 | fi 23 | } 24 | 25 | if [ -z "${PRJROOT}" ] ; then 26 | echo "Please source environment file first!" 27 | exit 1 28 | fi 29 | 30 | tag_repo=$1 31 | source=`readlink $PRODUCTDIR` 32 | trunk_repo=`svn-url $source` 33 | target=$1 34 | version=$PRODUCTVER 35 | brand=`echo $PRODUCTVER | awk -F- '{print $2}'` 36 | 37 | if [ "$tag_repo" == "" ] ; then 38 | detect_tag_repo 39 | 40 | if [ "$tag_repo" == "" ] ; then 41 | echo "Unable to detect tag repository path. Please specify manually" 42 | exit 1 43 | fi 44 | fi 45 | 46 | target=$tag_repo 47 | 48 | # - debug code 49 | echo "\$source: $source" 50 | echo "\$trunk_repo: $trunk_repo" 51 | echo "\$tag_repo: $tag_repo" 52 | echo "\$target: $target" 53 | echo "\$version: $version" 54 | echo "\$brand: $brand" 55 | 56 | exit; 57 | 58 | # check if target is a local directory 59 | if [ -d $target ]; then 60 | # we currently do not handle copy to local directory case 61 | echo "$0: target must be a svn remote repo" 62 | exit 1 63 | else 64 | echo "tagging $version" 65 | # svn mkdir $target/$version -m "svn-tag: create tag directory" > /dev/null 66 | echo "svn mkdir $target/$version -m \"svn-tag: create tag directory\" > /dev/null" 67 | if [ "$?" -ne "0" ] ; then 68 | echo "tag directory exists, give up" 69 | exit 1 70 | fi 71 | 72 | for dir in `ls $source`; do 73 | echo "..$dir" 74 | # svn cp $source/$dir $target/$version/$dir -m "svn-tag: copying $dir" > /dev/null 75 | echo "svn cp $source/$dir $target/$version/$dir -m \"svn-tag: copying $dir\" > /dev/null" 76 | done 77 | fi 78 | -------------------------------------------------------------------------------- /AmazonEc2/Amazon-Ec2-Deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Login by pem: ssh -i natty.pem ubuntu@ec2-50-18-83-73.us-west-1.compute.amazonaws.com 3 | # 4 | # ========================================================================== 5 | # Samba: \\amazon-ec2.no-ip.org\ubuntu 6 | # NFS : mount -t nfs -o tcp,nolock amazon-ec2.no-ip.org:/home /home 7 | # 8 | # Samba: 9 | # Path: \\amazon-ec2.no-ip.org\ubuntu 10 | # config file: /etc/samba/smb.conf + sudo smbpasswd -a username 11 | # 12 | # ========================================================================== 13 | # 14 | # NFS : 15 | # Path: mount -t nfs -o tcp,nolock amazon-ec2.no-ip.org:/home /home 16 | # config file: /etc/exports 17 | # 18 | # ========================================================================== 19 | # 20 | # Change default Ubuntu AMI password 21 | # 22 | # -- 23 | # ubuntu@ip-10-146-13-248:~$ sudo passwd 24 | # Enter new UNIX password: 25 | # -- 26 | # 27 | # ========================================================================== 28 | # Amazon Web Services™ are available in several regions. 29 | # Estimate the latency from your browser to each AWS™ region. 30 | # 31 | # http://www.cloudping.info/ 32 | # 33 | # ========================================================================== 34 | 35 | 36 | # 0. Use passowrd authentication 37 | sudo sed -i "s/^PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config 38 | sudo /etc/init.d/ssh restart 39 | 40 | sudo dpkg-reconfigure bash 41 | # sudo ln -s -n -i /bin/bash /bin/sh 42 | 43 | # 1. 44 | sudo passwd ubuntu 45 | 46 | # 2. 47 | sudo adduser vivotek 48 | sudo adduser kent 49 | sudo adduser kent admin 50 | sudo adduser kent adm 51 | sudo adduser kent sudo 52 | 53 | # 3. 54 | mkdir $HOME/Repos 55 | cd $HOME/Repos 56 | 57 | git clone git://github.com/chenkaie/DotFiles.git 58 | git clone git://github.com/chenkaie/Tools.git 59 | git clone git://github.com/chenkaie/rcfiles.git 60 | 61 | ln -s $HOME/Repos/Tools $HOME/Tools 62 | mv $HOME/.bashrc $HOME/.bashrc_ori 63 | 64 | ln -s $HOME/Repos/rcfiles/ $HOME/Repos/DotFiles/ 65 | cd $HOME/Repos/DotFiles; git submodule update --init; ./deploy-links; cd $HOME 66 | 67 | # packages 68 | sudo aptitude install exuberant-ctags cscope lsb-release cowsay inadyn 69 | 70 | -------------------------------------------------------------------------------- /ssh-and-action.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # - Description: A simple fork-join model ssh utility 3 | # - Author: Kent Chen <chenkaie at gmail.com> 4 | # - GitHub: http://github.com/chenkaie/ 5 | # - version: 0.3 6 | 7 | if [ $# -lt 1 ]; then 8 | echo "Usage: $0 <thread#> <timeout>" 9 | exit 0 10 | fi 11 | 12 | # Please modify below 2 files 13 | 14 | CMD="cmd.txt" 15 | ################## 16 | # cmd.txt sample # 17 | ################## 18 | # $ cat cmd.txt 19 | # env | grep SSH; touch /tmp/iamhere; ls /tmp/iamhere; uname -a 20 | 21 | LIST="server.txt" 22 | ############################ 23 | # server.txt syntax format # 24 | ############################ 25 | # $ cat server.txt 26 | # root:pass:192.168.1.1:22 27 | # $USER:$PASS:$IP:$PORT 28 | ############################ 29 | 30 | # CLI arguments 31 | ARG_THREAD_NO=${1:-1} 32 | ARG_TIMEOUT=${2:-60} 33 | 34 | # Default not verifying host and hostkey 35 | SSH_OPTION_IGNORE_CHECK="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" 36 | 37 | SSH_OPTIONS="-o ConnectTimeout=$ARG_TIMEOUT $SSH_OPTION_IGNORE_CHECK" 38 | 39 | pidlist= 40 | tmpdir=$(mktemp -d) 41 | tmplog='$tmpdir/$camip.txt' 42 | 43 | echo ">>> Start: $(date)" 44 | 45 | while IFS=':' read -r user pass ip port; do 46 | echo ======================================================================== 47 | echo IP: $ip 48 | 49 | ( 50 | sshpass -p $pass ssh -p ${port:-22} ${SSH_OPTIONS} $user@$ip $(cat $CMD) > $tmpdir/.$ip.ssh.log 2>&1 51 | if [ $? -eq 0 ]; then 52 | echo --------------------------------- >> $tmpdir/$ip.txt 53 | echo Date: $(date) >> $tmpdir/$ip.txt 54 | echo Server: $user:$pass:$ip:$port >> $tmpdir/$ip.txt 55 | cat $tmpdir/.$ip.ssh.log >> $tmpdir/$ip.txt 56 | echo --------------------------------- >> $tmpdir/$ip.txt 57 | flock .good.lock cat $tmpdir/$ip.txt >> good.txt 58 | else 59 | echo --------------------------------- >> $tmpdir/$ip.txt 60 | echo Date: $(date) >> $tmpdir/$ip.txt 61 | echo Server: $user:$pass:$ip:$port >> $tmpdir/$ip.txt 62 | echo --------------------------------- >> $tmpdir/$ip.txt 63 | flock .bad.lock cat $tmpdir/$ip.txt >> bad.txt 64 | fi 65 | ) & 66 | pidlist="$pidlist $!" 67 | echo ======================================================================== 68 | done < $LIST 69 | 70 | wait $pidlist 71 | rm -rf $tmpdir .*.lock 72 | 73 | echo "<<< DONE: $(date)" 74 | 75 | -------------------------------------------------------------------------------- /hwsysinfo: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | # simple script to give a summary of system information 4 | 5 | # Author: 6 | # http://www.pixelbeat.org/ 7 | # Notes: 8 | # Unless you run as root, disk info can't be shown 9 | # Changes: 10 | # V0.1, 16 Nov 2005, Initial release 11 | # V0.s, 22 Oct 2007, Tweak to ensure cdrom info shown. 12 | # Comment out partition info as a bit noisy. 13 | 14 | 15 | find_sbin_cmd() { 16 | for base in / /usr/ /usr/local; do 17 | if [ -e $base/sbin/$1 ]; then 18 | echo $base/sbin/$1 19 | exit 20 | fi 21 | done 22 | } 23 | FDISK=`which fdisk 2>/dev/null` 24 | LSUSB=`which lsusb 2>/dev/null` 25 | LSPCI=`which lspci 2>/dev/null` 26 | [ -z "$FDISK" ] && FDISK=`find_sbin_cmd fdisk` 27 | [ -z "$LSUSB" ] && LSUSB=`find_sbin_cmd lsusb` 28 | [ -z "$LSPCI" ] && LSPCI=`find_sbin_cmd lspci` 29 | 30 | echo "============= Drives =============" 31 | ( 32 | sed -n 's/.* \([hs]d[a-f]$\)/\1/p' < /proc/partitions 33 | [ -e /dev/cdrom ] && readlink -f /dev/cdrom | cut -d/ -f3 34 | ) | 35 | sort | uniq | 36 | while read disk; do 37 | echo -n "/dev/$disk: " 38 | if [ ! -r /dev/$disk ]; then 39 | echo "permission denied" #could parse /proc for all but 40 | else 41 | size=`$FDISK -l /dev/$disk | grep Disk | cut -d' ' -f3-4 | tr -d ,` 42 | rest=`/sbin/hdparm -i /dev/$disk 2>/dev/null | grep Model` 43 | rest=`echo $rest` #strip spaces 44 | echo -n "$rest" 45 | if [ ! -z "$size" ]; then 46 | echo ", Size=$size" 47 | else 48 | echo 49 | fi 50 | fi 51 | done 52 | 53 | #if [ `id -u` == "0" ]; then 54 | #echo "========== Partitions ==========" 55 | #$FDISK -l 2>/dev/null 56 | #fi 57 | 58 | echo "============= CPUs =============" 59 | grep "model name" /proc/cpuinfo #show CPU(s) info 60 | 61 | echo "============= MEM =============" 62 | KiB=`grep MemTotal /proc/meminfo | tr -s ' ' | cut -d' ' -f2` 63 | MiB=`expr $KiB / 1024` 64 | #note various mem not accounted for, so round to appropriate size 65 | #on my 384MiB system over 8MiB was unaccounted for 66 | #on my 1024MiB system over 20MiB was unaccounted for so round to next highest power of 2 67 | round=32 68 | echo "`expr \( \( $MiB / $round \) + 1 \) \* $round` MiB" 69 | 70 | echo "============= PCI =============" 71 | $LSPCI -tv 72 | 73 | echo "============= USB =============" 74 | $LSUSB 75 | -------------------------------------------------------------------------------- /ydict-pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # Yen-Ming Lee <leeym@leeym.com> 3 | # 2010/06/01 4 | # 5 | # ---------------------------------------------------------------------------- 6 | # "THE PEARL-TEA-WARE LICENSE", based on "THE BEER-WARE LICENSE": 7 | # <leeym@leeym.com> wrote this file. As long as you retain this notice you 8 | # can do whatever you want with this stuff. If we meet some day, and you think 9 | # this stuff is worth it, you can buy me a pearl tea in return. Yen-Ming Lee 10 | # ---------------------------------------------------------------------------- 11 | 12 | use FindBin qw($Script); 13 | use Term::ANSIColor qw(:constants); 14 | use LWP::Simple; 15 | use URI::Escape; 16 | use strict; 17 | 18 | use utf8; 19 | binmode(STDOUT, ':encoding(utf8)'); 20 | 21 | my $word = shift; 22 | die "usage: $Script word\n" if !$word; 23 | 24 | my $red = RED; 25 | my $bold = BOLD; 26 | my $cyan = CYAN; 27 | my $reset = RESET; 28 | my $green = GREEN; 29 | 30 | ydict("http://tw.dictionary.yahoo.com/search?p=" . uri_escape($word)); 31 | 32 | sub ydict 33 | { 34 | my $url = shift; 35 | 36 | #warn "GET $url\n"; 37 | my $html = get($url); 38 | my $i = 0; 39 | $html =~ s{\r}{}g; 40 | $html =~ s{\n}{ }g; 41 | my @URL = grep { !m{tab} } ($html =~ m{(http[^<]+docid=\d+)}sg); 42 | exit if !scalar(@URL); 43 | 44 | print BOLD YELLOW "\nCorrection: $1\n" if $html =~ m{以下為(\w+)在字典}; 45 | my $pronunciation = $1 if $html =~ m{<div class="pronunciation">(.*?)</div>}; 46 | $pronunciation =~ s{</?[^>]+>}{}g; 47 | 48 | #print BOLD YELLOW "\nPronunciation: $pronunciation\n" if $pronunciation; 49 | 50 | my $indent = " "; 51 | $html =~ s{.*?(<div class="def clr nobr">)}{\1}; # behead 52 | $html =~ s{<div class="ft">.*}{}; # curtail 53 | $html =~ s{<p class="example">}{$indent $cyan}g; 54 | $html =~ s{<p class="interpret">}{ $green}g; 55 | $html =~ s{<b>}{$bold}g; 56 | $html =~ s{</b>}{$reset$cyan}g; 57 | $html =~ s{</p>}{$reset\n}g; 58 | $html =~ s{<div class="def clr nobr">}{$reset\n$bold$red}g; 59 | $html =~ s{<div class="list">}{$reset\t}g; 60 | $html =~ s{<ol>}{$reset\n}g; 61 | $html =~ s{<li>}{$indent\*}g; 62 | $html =~ s{\\}{}g; # bug? 63 | $html =~ s{</?\w+[^>]*>}{}g; # all tags 64 | 65 | print "$html"; 66 | shift @URL; 67 | map { ydict($_) } (@URL); 68 | } 69 | -------------------------------------------------------------------------------- /fdhijack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Redirect stdin, stdout, stderr of a daemon to /dev/pts/# 4 | # 5 | ################################################################################################################# 6 | # Ref: stdio buffering: http://www.pixelbeat.org/programming/stdio_buffering/ 7 | # Default Buffering modes: 8 | # stdin -> is always buffered 9 | # stderr -> is always unbuffered 10 | # if stdout is a terminal then buffering is automatically set to line buffered, else it is set to buffered 11 | ################################################################################################################# 12 | # Therefore if we set stdout, stderr unbuffered by setvbuf(), we don't need flush (-f) feature. 13 | # However buffered mode stdio is more efficient. 14 | ################################################################################################################# 15 | 16 | if [ "$2" = "" ]; then 17 | echo "Usage: $0 PID /path/to/pts" 18 | echo "Example: $0 \`pidof Daemon\` /dev/pts/1" 19 | echo " $0 \`pidof Daemon\` \`tty\`" 20 | exit 0 21 | fi 22 | 23 | SLEEP_DURATION=5 24 | 25 | case "$0" in 26 | *dm365*) 27 | # Finetune SLEEP_DURATION to avoid gdb output "Hangup detected on fd 0, error detected on stdin" 28 | SLEEP_DURATION=3 29 | GDB="/home/kent/ArmTools/gdb-dm365-v6-montavista" 30 | 31 | #SLEEP_DURATION=8 32 | #GDB="/home/kent/ArmTools/gdb-dm365-v7" 33 | ;; 34 | esac 35 | 36 | GDB=${GDB:-gdb} 37 | 38 | if ${GDB} --version > /dev/null 2>&1; then 39 | true 40 | else 41 | echo "Unable to find gdb." 42 | exit 1 43 | fi 44 | 45 | pid=$1 46 | dst=$2 47 | 48 | # -f : flushes all open output streams to avoid buffered IO 49 | if [ "${2}" = "-f" ]; then 50 | ( 51 | echo "attach $pid" 52 | echo 'call fflush(0)' 53 | echo 'detach' 54 | echo 'quit' 55 | sleep 5 56 | ) | ${GDB} -q -x - 57 | else 58 | ( 59 | echo "attach $pid" 60 | echo 'call open("'$dst'", 66, 0666)' 61 | #echo 'call dup2($1,0)' # stdin 62 | echo 'call dup2($1,1)' # stdout, $1 derived from previous open() by gdb 63 | echo 'call dup2($1,2)' # stderr 64 | # NOTE: setvbuf cause SIGSEGV in some situation, 65 | # uncomment them if you needed. 66 | #echo 'p setvbuf(stdout, 0, 2, 0)' #set _IONBF unbuffered 67 | #echo 'p setvbuf(stderr, 0, 2, 0)' #set _IONBF unbuffered 68 | echo 'call close($1)' 69 | echo 'detach' 70 | echo 'quit' 71 | sleep $SLEEP_DURATION 72 | ) | ${GDB} -q -x - 73 | fi 74 | 75 | -------------------------------------------------------------------------------- /newest: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # List the newest files in the specified paths and by default any subdirectories 4 | # If no paths are specified, the current directory is listed. 5 | 6 | # Author: 7 | # http://www.pixelbeat.org/ 8 | # Notes: 9 | # This script explicitly ignores repository metadata. 10 | # This script (well find actually) fails for user specified paths 11 | # that begin with '-', '(' or '!', so prepend './' for paths like that. 12 | # Changes: 13 | # V1.0, 26 May 2005, Initial release 14 | # V1.1, 20 Jul 2007, Ignore git metadata in addition to svn and cvs 15 | # Fix options syntax (breaks backwards compatibility) 16 | # Add -nr option to not recurse 17 | # Add -na option to ignore dotfiles 18 | # Add -r option to show oldest rather than newest 19 | # Allow specifiying multiple files & directories 20 | # Don't output extra file info if output is not a tty 21 | 22 | num="20" 23 | 24 | usage() { 25 | echo "Usage: `basename $0` [-nr] [-na] [-n#] [-s] [-r] [path...]" >&2 26 | echo >&2 27 | echo " -nr do not recurse" >&2 28 | echo " -na ignore files starting with ." >&2 29 | echo " -n# list the newest # files ($num by default)" >&2 30 | echo " -r reverse to show oldest files" >&2 31 | exit 1 32 | } 33 | 34 | num="-n$num" 35 | dotfiles="yes" 36 | recurse="yes" 37 | reverse="" 38 | while : 39 | do 40 | case "$1" in 41 | --) shift; break ;; 42 | -na) dotfiles="no" ;; 43 | -nr) recurse="no" ;; 44 | -n[0-9]*) num=$1 ;; 45 | -r) reverse="r" ;; 46 | --help) usage ;; 47 | --version) echo "1.1" && exit ;; 48 | *) break ;; 49 | esac 50 | shift 51 | done 52 | [ "$dotfiles" = "no" ] && ignore_hidden="-name '.*' -o" 53 | [ "$recurse" = "no" ] && dont_recurse="-maxdepth 1" 54 | if [ $# -gt 0 ]; then 55 | path_format="%p" 56 | else 57 | path_format="%P" 58 | set -- "./" 59 | fi 60 | 61 | ignore_metadata="\( -type d -a \( -name '.git' -o -name '.svn' -o -name 'CVS' \) \) -prune -o" 62 | print_format="\( -type f -printf '%T@\t$path_format\n' \)" 63 | eval find '"$@"' $dont_recurse $ignore_metadata $ignore_hidden $print_format | 64 | sort -k1,1${reverse}n | 65 | tail $num | 66 | cut -f2- | 67 | if [ ! -p /proc/self/fd/1 ]; then 68 | tr '\n' '\0' | 69 | xargs -r0 ls -lUd --color=auto -- 70 | else 71 | cat 72 | fi 73 | -------------------------------------------------------------------------------- /imgcat: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # tmux requires unrecognized OSC sequences to be wrapped with DCS tmux; 4 | # <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It 5 | # only accepts ESC backslash for ST. 6 | function print_osc() { 7 | if [[ $TERM == screen* ]] ; then 8 | printf "\033Ptmux;\033\033]" 9 | else 10 | printf "\033]" 11 | fi 12 | } 13 | 14 | # More of the tmux workaround described above. 15 | function print_st() { 16 | if [[ $TERM == screen* ]] ; then 17 | printf "\a\033\\" 18 | else 19 | printf "\a" 20 | fi 21 | } 22 | 23 | # print_image filename inline base64contents 24 | # filename: Filename to convey to client 25 | # inline: 0 or 1 26 | # base64contents: Base64-encoded contents 27 | function print_image() { 28 | print_osc 29 | printf '1337;File=' 30 | if [[ -n "$1" ]]; then 31 | printf 'name='`echo -n "$1" | base64`";" 32 | fi 33 | if $(base64 --version 2>&1 | grep GNU > /dev/null) 34 | then 35 | BASE64ARG=-d 36 | else 37 | BASE64ARG=-D 38 | fi 39 | echo -n "$3" | base64 $BASE64ARG | wc -c | awk '{printf "size=%d",$1}' 40 | printf ";inline=$2" 41 | printf ":" 42 | echo -n "$3" 43 | print_st 44 | printf '\n' 45 | } 46 | 47 | function error() { 48 | echo "ERROR: $*" 1>&2 49 | } 50 | 51 | function show_help() { 52 | echo "Usage: imgcat filename ..." 1>& 2 53 | echo " or: cat filename | imgcat" 1>& 2 54 | } 55 | 56 | ## Main 57 | 58 | if [ -t 0 ]; then 59 | has_stdin=f 60 | else 61 | has_stdin=t 62 | fi 63 | 64 | # Show help if no arguments and no stdin. 65 | if [ $has_stdin = f -a $# -eq 0 ]; then 66 | show_help 67 | exit 68 | fi 69 | 70 | # Look for command line flags. 71 | while [ $# -gt 0 ]; do 72 | case "$1" in 73 | -h|--h|--help) 74 | show_help 75 | exit 76 | ;; 77 | -*) 78 | error "Unknown option flag: $1" 79 | show_help 80 | exit 1 81 | ;; 82 | *) 83 | if [ -r "$1" ] ; then 84 | print_image "$1" 1 "$(base64 < "$1")" 85 | else 86 | error "imgcat: $1: No such file or directory" 87 | exit 2 88 | fi 89 | ;; 90 | esac 91 | shift 92 | done 93 | 94 | # Read and print stdin 95 | if [ $has_stdin = t ]; then 96 | print_image "" 1 "$(cat | base64)" 97 | fi 98 | 99 | exit 0 100 | -------------------------------------------------------------------------------- /inpy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -i 2 | 3 | # Enhance introspection at the python interactive prompt. 4 | # This is a very simple alternative to ipython 5 | # whose default settings I don't like. 6 | 7 | # Notes: 8 | # You can run it directly, or call it like: 9 | # PYTHONSTARTUP=~/path/to/inpy python 10 | # Changes: 11 | # V0.1 09 Sep 2008 Initial release 12 | # V0.2 30 Nov 2010 13 | # http://github.com/pixelb/scripts/commits/master/scripts/inpy 14 | 15 | 16 | import os, errno 17 | class _readline: 18 | history=os.path.join(os.environ['HOME'],'.inpy_history') 19 | import readline 20 | # turn on tab completion 21 | readline.parse_and_bind("tab: complete") 22 | import rlcompleter 23 | def __init__(self): 24 | try: 25 | self.readline.read_history_file(self.history) 26 | except (IOError, OSError), value: 27 | if value.errno == errno.ENOENT: 28 | pass 29 | else: 30 | raise 31 | def __del__(self): 32 | self.readline.write_history_file(self.history) 33 | _rl=_readline() 34 | 35 | import sys 36 | # The following exits on Ctrl-C 37 | def _std_exceptions(etype, value, tb): 38 | sys.excepthook=sys.__excepthook__ 39 | if issubclass(etype, KeyboardInterrupt): 40 | sys.exit(0) 41 | else: 42 | sys.__excepthook__(etype, value, tb) 43 | sys.excepthook=_std_exceptions 44 | 45 | #try to import dire() and ls() 46 | #See http://www.pixelbeat.org/libs/dir_patt.py 47 | # Note if $PYTHONPATH is not set then you can 48 | # import from arbitrary locations like: 49 | # import sys,os 50 | # sys.path.append(os.environ['HOME']+'/libs/') 51 | try: 52 | from dir_patt import * 53 | except: 54 | pass 55 | 56 | #pprint.pprint() doesn't put an item on each line 57 | #even if width is small? See also: 58 | #http://code.activestate.com/recipes/327142/ 59 | #also from reddit: 60 | # ppdict = lambda d:"\n".join(map("%s: %s".__mod__, d.items())) 61 | def ppdict(d): 62 | """Pretty Print for Dicts""" 63 | print '{' 64 | keys=d.keys() 65 | keys.sort() 66 | for k in keys: 67 | spacing=" " * (16-(len(repr(k))+1)) 68 | print "%s:%s%s," % (repr(k),spacing,repr(d[k])) 69 | print '}' 70 | 71 | if 1: # Show info on startup 72 | sys.stderr.write("Python %s\n" % sys.version.split('\n')[0]) 73 | sys.stderr.write("Tab completion on. Available items: %s\n" % 74 | sorted(filter(lambda n: not n.startswith('_'), locals()))) 75 | -------------------------------------------------------------------------------- /ubnt-devel-aircam: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: execute `source ubnt-devel-aircam` under top level folder of unifi-video-firmware 3 | 4 | git rev-parse --show-toplevel > /dev/null 2>&1 5 | if [ $? -eq 0 ]; then 6 | REPODIR=$(git rev-parse --show-toplevel) 7 | pushd "$REPODIR" > /dev/null 8 | else 9 | echo "Please run under a git repo!" 10 | exit 1 11 | fi 12 | 13 | export PRODUCTDIR="$REPODIR" 14 | 15 | # For Openwrt build system (refer to Openwrt/Makefile) 16 | # Export below variable, you can make any package w/o typing annyoing long string 17 | # make package/xxx/compile => make compile (or just make) 18 | # make package/xxx/install => make install 19 | # make package/xxx/clean => make clean 20 | 21 | # unset $TOPDIR when you hit some clean build issue 22 | export TOPDIR=${PRODUCTDIR}/.openwrt 23 | export INCLUDE_DIR=${TOPDIR}/include 24 | 25 | # For packages which supports parallel build (PKG_BUILD_PARALLEL:=1) 26 | #export PKG_JOBS="-j$(grep processor /proc/cpuinfo | wc -l)" 27 | 28 | # Fetch $GEN=[genXF] and $CONF=[rel|dbg], read from last built 29 | #MAKE_TARGET=$(ls -t .marker-*_prepare | head -n1) 30 | MAKE_TARGET=$(ls -td openwrt-gen* | head -n1) 31 | export GEN=$(echo "$MAKE_TARGET" | cut -d '_' -f 1 | cut -d '-' -f 2) 32 | export CONF=$(echo "$MAKE_TARGET" | cut -d '_' -f 1 | cut -d '-' -f 3) 33 | echo Last build: GEN="$GEN" CONF="$CONF" 34 | 35 | # export some useful env var 36 | export IMAGEDIR=${PRODUCTDIR}/.openwrt/artifacts 37 | export STAGINGDIR=${PRODUCTDIR}/.openwrt/staging_dir 38 | export STAGINGBINDIR=${PRODUCTDIR}/.openwrt/staging_dir/host/bin 39 | export MWDIR=${PRODUCTDIR}/packages/packages-ubnt/ubnt-middleware/unifi-video-fw-middleware/ 40 | 41 | #export PATH=$STAGINGBINDIR:$PATH 42 | alias om='PATH=$STAGINGBINDIR:$PATH make -j$(nproc)' 43 | alias omc='PATH=$STAGINGBINDIR:$PATH m clean' 44 | alias omi='PATH=$STAGINGBINDIR:$PATH m install' 45 | 46 | # Make symlink # symlink name 47 | ln -sf openwrt-"${GEN}"-"${CONF}" .openwrt 48 | ln -sf .openwrt/artifacts rel-artifacts 49 | ln -sf .openwrt/staging_dir/target-*/root-*/ rootfs-owrt 50 | ln -sf .openwrt/build_dir/target-*/root-*/ rootfs-ubnt 51 | ln -sf .openwrt/build_dir/target-*/linux-*/linux-* linux 52 | ln -sf .openwrt/build_dir/target-* target 53 | ln -sf .openwrt/staging_dir/target-*/usr* installDev 54 | 55 | ln -sf .openwrt/artifacts/*bootloader.bin rel-preload_image.bin 56 | ln -sf $(ls .openwrt/artifacts/*[^bootloader].bin | tail -n1) rel-firmware.bin 57 | 58 | #godir PATTERN 59 | 60 | popd > /dev/null 61 | -------------------------------------------------------------------------------- /AmazonEc2/Ubuntu-Deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Login by pem: ssh -i natty.pem ubuntu@ec2-50-18-83-73.us-west-1.compute.amazonaws.com 3 | # 4 | # ========================================================================== 5 | # Samba: \\amazon-ec2.no-ip.org\ubuntu 6 | # NFS : mount -t nfs -o tcp,nolock amazon-ec2.no-ip.org:/home /home 7 | # 8 | # Samba: 9 | # Path: \\amazon-ec2.no-ip.org\ubuntu 10 | # config file: /etc/samba/smb.conf + sudo smbpasswd -a username 11 | # 12 | # ========================================================================== 13 | # 14 | # NFS : 15 | # Path: mount -t nfs -o tcp,nolock amazon-ec2.no-ip.org:/home /home 16 | # config file: /etc/exports 17 | # 18 | # ========================================================================== 19 | # 20 | # Change default Ubuntu AMI password 21 | # 22 | # -- 23 | # ubuntu@ip-10-146-13-248:~$ sudo passwd 24 | # Enter new UNIX password: 25 | # -- 26 | # 27 | # ========================================================================== 28 | # Amazon Web Services™ are available in several regions. 29 | # Estimate the latency from your browser to each AWS™ region. 30 | # 31 | # http://www.cloudping.info/ 32 | # 33 | # ========================================================================== 34 | 35 | sudo apt-get install openssh-server vim curl git 36 | 37 | # Run a 32-bit program on a 64-bit version of Ubuntu 38 | sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6 39 | sudo dpkg --add-architecture i386 40 | sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 41 | sudo apt-get install multiarch-support 42 | 43 | # 0. Use passowrd authentication 44 | sudo sed -i "s/^PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config 45 | sudo /etc/init.d/ssh restart 46 | 47 | sudo dpkg-reconfigure dash 48 | # sudo ln -s -n -i /bin/bash /bin/sh 49 | 50 | # 1. 51 | sudo passwd ubuntu 52 | 53 | # 2. 54 | sudo adduser vivotek 55 | sudo adduser kent 56 | sudo adduser kent admin 57 | sudo adduser kent adm 58 | sudo adduser kent sudo 59 | 60 | mkdir -p $HOME/usr/bin 61 | REPO_BIN=$HOME/usr/bin/repo 62 | curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > $REPO_BIN 63 | chmod +x $REPO_BIN 64 | 65 | UNIX_ENV_DEPLY="$HOME/Repos/unix-env-deploy" 66 | 67 | # 3. 68 | mkdir -p ${UNIX_ENV_DEPLY} 69 | cd ${UNIX_ENV_DEPLY} 70 | 71 | $REPO_BIN init -u https://github.com/chenkaie/manifest-unix-env-deploy.git 72 | $REPO_BIN sync 73 | 74 | ln -s ${UNIX_ENV_DEPLY}/Tools $HOME/Tools 75 | mv $HOME/.bashrc $HOME/.bashrc_ori 76 | 77 | cd ${UNIX_ENV_DEPLY}/DotFiles; git submodule update --init; ./deploy-links; cd $HOME 78 | 79 | # packages 80 | sudo apt-get install exuberant-ctags cscope lsb-release cowsay silversearcher-ag id-utils 81 | 82 | -------------------------------------------------------------------------------- /tmux_backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # By Victor Orlikowski. Public domain. 4 | # 5 | # This script maintains snapshots of each pane's 6 | # history buffer, for each tmux session you are running. 7 | # 8 | # It is intended to be run by cron, on whatever interval works 9 | # for you. 10 | 11 | # Maximum number of snapshots to keep. 12 | max_backups=12 13 | # Names of sessions you may wish to exclude from snapshotting, 14 | # space separated. 15 | ignore_sessions="" 16 | # The directory into which you want your snapshots placed. 17 | # The default is probably "good enough." 18 | backup_dir=~/.tmux_backup/snapshot 19 | 20 | ######################################################################## 21 | 22 | # Rotate previous backups. 23 | i=${max_backups} 24 | while [[ ${i} != 0 ]] ; do 25 | if [ -d ${backup_dir}.${i} ] ; then 26 | if [[ ${i} = ${max_backups} ]] ; then 27 | rm -r ${backup_dir}.${i} 28 | else 29 | mv ${backup_dir}.${i} ${backup_dir}.$((${i}+1)) 30 | fi 31 | fi 32 | i=$((${i}-1)) 33 | done 34 | 35 | if [ -d ${backup_dir} ] ; then 36 | mv ${backup_dir} ${backup_dir}.1 37 | fi 38 | 39 | ## Dump hardcopy from all windows in all available tmux sessions. 40 | unset TMUX 41 | for session in $(tmux list-sessions | cut -d' ' -f1 | sed -e 's/:$//') ; do 42 | for ignore_session in ${ignore_sessions} ; do 43 | if [ ${session} = ${ignore_session} ] ; then 44 | continue 2 45 | fi 46 | done 47 | 48 | # Session name can contain the colon character (":"). 49 | # This can screw up addressing of windows within tmux, since 50 | # target windows are specified as target-session:target-window. 51 | # 52 | # We use uuidgen to create a "safe" temporary session name, 53 | # which we then use to create a "detached" session that "links" 54 | # to the "real" session that we want to back up. 55 | tmpsession=$(uuidgen) 56 | tmux new-session -d -s "$tmpsession" -t "$session" 57 | HISTSIZE=$(tmux show-options -g -t "$tmpsession" | grep "history-limit" | awk '{print $2}') 58 | for win in $(tmux list-windows -t "$tmpsession" | grep -v "^\s" | cut -d' ' -f1 | sed -e 's/:$//'); do 59 | session_dir=$(echo "$session" | sed -e 's/ /_/g' | sed -e 's%/%|%g') 60 | win_spec="$tmpsession":"$win" 61 | 62 | if [ ! -d ${backup_dir}/${session_dir}/${win} ] ; then 63 | mkdir -p ${backup_dir}/${session_dir}/${win} 64 | fi 65 | 66 | for pane in $(tmux list-panes -t "$win_spec" | cut -d' ' -f1 | sed -e 's/:$//'); do 67 | pane_path=${backup_dir}/${session_dir}/${win}/${pane} 68 | pane_spec="$win_spec"."$pane" 69 | 70 | tmux capture-pane -t "$pane_spec" -S -${HISTSIZE} 71 | tmux save-buffer ${pane_path} 72 | 73 | if [ ! -s ${pane_path} ] ; then 74 | sleep 1 75 | rm ${pane_path} 76 | fi 77 | done 78 | done 79 | tmux kill-session -t "$tmpsession" 80 | 81 | done 82 | -------------------------------------------------------------------------------- /tunnel.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | # This is a really cool ssh login style 4 | # Catch me if you can :) 5 | 6 | VIMSSH="vim" 7 | VIMSSH_PATH="$HOME/tmp/" 8 | cd $VIMSSH_PATH 9 | export PATH=.:$PATH 10 | 11 | case "$1" in 12 | *dd-wrt-proxy*) 13 | # -D [bind_address:]port 14 | # Specifies a local "dynamic" application-level port forwarding. This works by allocating a socket to listen to port on the local side, optionally bound 15 | # to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the secure channel, and the application 16 | # protocol is then used to determine where to connect to from the remote machine. Currently the SOCKS4 and SOCKS5 protocols are supported, and ssh will 17 | # act as a SOCKS server. Only root can forward privileged ports. Dynamic port forwardings can also be specified in the configuration file. 18 | # 19 | # The bind_address of "localhost" indicates that the listening port be bound for local use only, 20 | # while an empty address or '*' indicates that the port should be available from all interfaces. 21 | # 22 | # Note: -D mode only do a port fowarding on local side, i.e. works only on telnet localhost port, rather than telnet PUBLIC_IP port 23 | # Therefore we have to do a public port fowarding e.g. 24 | # step 1. kent@hostname $ ssh -R 7321:rd1-2:22 ubuntu@amazon-ec2.no-ip.org -o TCPKeepAlive=no -o ServerAliveInterval=60 25 | # step 2. ubuntu@hostname $ ssh -D 8888 localhost -p7321 -lkent -vvv -N 26 | # step 3. ubuntu@hostname $ socat TCP-LISTEN:12345,fork TCP:localhost:8888 27 | # step 4. Setup browser proxy settings as "SOCK v5" + "amazon-ec2.no-ip.org:12345" 28 | # 29 | # 30 | # Update: When '*' is used as bind_address, everything makes easy. Make sure <interface:port> not blocked by iptables :) 31 | # kent@mbpr $ ssh -D 8080 amazon-ec2.no-ip.org -p7321 -lkent 32 | 33 | autossh -M 0 -D 172.16.5.31:52525 -R 7322:rd1-2:22 root@chenkaie.no-ip.org -p2222 -o TCPKeepAlive=no -o ServerAliveInterval=60 34 | ;; 35 | *dd-wrt*) 36 | #autossh -M 0 -R 7322:rd1-2:22 root@chenkaie.no-ip.org -p2222 -o TCPKeepAlive=no -o ServerAliveInterval=60 37 | $VIMSSH config_videoin.xml 38 | ;; 39 | *totoro*) 40 | autossh -M 0 -R 7321:rd1-2:22 kent@140.118.155.113 -p3063 -o TCPKeepAlive=no -o ServerAliveInterval=60 41 | ;; 42 | *funp*) 43 | autossh -M 0 -R 7322:rd1-2:22 arnold@tcdevweb.funp.com -p22 -o TCPKeepAlive=no -o ServerAliveInterval=60 44 | ;; 45 | *amazon*) 46 | autossh -M 0 -R 7322:rd1-2:22 ubuntu@amazon-ec2.no-ip.org -p22 -o TCPKeepAlive=no -o ServerAliveInterval=60 47 | ;; 48 | *ptt*) 49 | $VIMSSH config_system.xml 50 | ;; 51 | *rdp*) 52 | $VIMSSH config_ptzctrl.xml 53 | ;; 54 | *diskstation*) 55 | $VIMSSH config_ddns.xml 56 | ;; 57 | *) 58 | echo "Usage : $0 [dd-wrt|totoro|funp|ptt|rdp]" 59 | exit 1 60 | ;; 61 | esac 62 | -------------------------------------------------------------------------------- /wcgrep: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2004 Ben Reser <ben@reser.org> 4 | # Licensed under the terms subversion ships under or GPLv2. 5 | 6 | # Useful for greping in a subversion working copy. 7 | # Essentially it behaves the same way your grep command does (in fact it 8 | # ultimately calls the grep command on your path) with a few exceptions. 9 | # Ignores the subversion admin directories (.svn) and vi(m) backup files. 10 | # Recursive is always on with or without -r. 11 | # Always print filename and line numbers. 12 | # Ignores binary files. 13 | # If no path is given the current working directory is searched not stdin. 14 | # Other than that it will take any parameter or pattern your standard grep 15 | # does. 16 | # 17 | # This script requires GNU findutils and by default GNU grep (though that 18 | # can be changed with environment variables). 19 | # 20 | # There are three environment variables you can set that modify the default 21 | # behavior: 22 | # 23 | # WCGREP_GREP Controls what command is used for the grep command. 24 | # If unset or null wcgrep will use the command named grep. 25 | # WCGREP_GREPARGS Controls what arguments are always passed to the grep 26 | # command before the arguments given on the command line. 27 | # If unset or null it defaults to -HnI (always print file 28 | # names, line numbers and ignore binary files). If you wish 29 | # to set no default args set the variable to a space (" "). 30 | # WCGREP_IGNORE Controls what files are ignored by the grep command. 31 | # This is a regex that is passed to the find command with 32 | # -regex so see find's man page for details. If unset or 33 | # null defaults to '.*~$\|.*/\.svn\(/\|$\)', which will 34 | # ignore vim backup files and subversion admin dirs. 35 | 36 | #define by Kent(2008/12/05), add 37 | #-i: ignore-case 38 | #--colour=auto: Surround the matching string with the marker find in GREP_COLOR environment variable (RECMOMMENDED) 39 | WCGREP_GREPARGS="-HnIi --colour=auto --mmap" 40 | WCGREP_GREP="grep" 41 | WCGREP_IGNORE=".*/\.git\(/\|$\)\|.*/tags\|.*/cscope.out\|.*~$\|.*/\.svn.*\(/\|$\)" 42 | 43 | if [ $# -eq 0 ]; then 44 | echo "Usage: wcgrep PATTERN" 45 | exit 0 46 | fi 47 | 48 | arg_count=$# 49 | for (( i=1; i <= $arg_count; i++ )); do 50 | arg="$1" 51 | shift 1 52 | if [ -z "$pattern" ]; then 53 | if [ "$arg" == "--" ]; then 54 | grepargs="$grepargs $arg" 55 | pattern="$1" 56 | shift 1 57 | ((i++)) 58 | elif [ "${arg:0:1}" != "-" ]; then 59 | pattern="$arg" 60 | else 61 | grepargs="$grepargs $arg" 62 | fi 63 | else 64 | pathargs="$pathargs $arg" 65 | fi 66 | done 67 | 68 | find $pathargs -regex ${WCGREP_IGNORE:-'.*/\.git\(/\|$\)\|.*~$\|.*/\.svn\(/\|$\)'} -prune -o \ 69 | -type f -print0 | xargs -r0 ${WCGREP_GREP:-grep} ${WCGREP_GREPARGS:--HnI} \ 70 | $grepargs "$pattern" | nl -n ln | grep -Ii --colour=auto $grepargs "$pattern" 71 | -------------------------------------------------------------------------------- /.bashrc_bb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This .bashrc_bb is useful for busybox environment 3 | 4 | ####################### 5 | # Alias # 6 | ####################### 7 | 8 | alias ll='ls -al' # long list format 9 | alias lk='ls -lk' # --block-size=1K 10 | alias lt='ls -ltr' # sort by date (mtime) 11 | alias lc='ls -ltcr' # sort by and show change time 12 | alias la='ls -ltur' # sort by and show access time 13 | alias lx='ls -lX' # sort by extension 14 | alias lz='ls -lSr' # sort by size 15 | alias ld='ls -d */' # es only Dirs 16 | alias l.='ls -dAFh .[^.]*' # ls only Dotfiles 17 | alias lst='ls -hFtal | grep $(date +%Y-%m-%d)' #ls Today 18 | 19 | alias ..='cd ..' 20 | alias ...='cd ../..' 21 | alias ....='cd ../../..' 22 | alias .....='cd ../../../..' 23 | alias ......='cd ../../../../..' 24 | 25 | alias b='cd -' 26 | alias cd..='cd ..' 27 | alias path='echo -e ${PATH//:/\\n}' 28 | 29 | # netstat -npl 30 | alias netstat='netstat -np' 31 | 32 | ####################### 33 | # Env var # 34 | ####################### 35 | 36 | IP_HERE=$(ifconfig eth0 | awk -F':' '/inet addr/&&!/127.0.0.1/{split($2,_," ");print _[1]}') 37 | 38 | ####################### 39 | # Functions # 40 | ####################### 41 | 42 | # ls when cd, it's useful 43 | cd () 44 | { 45 | if [ -n "$1" ]; then 46 | chdir "$@"&& ls 47 | else 48 | chdir ~&& ls 49 | fi 50 | } 51 | 52 | fnd () 53 | { 54 | find -iname "*$1*" 55 | } 56 | 57 | wg () 58 | { 59 | grep -ri "$1" * 60 | } 61 | 62 | mt () 63 | { 64 | if [ $# -ne 1 ]; then 65 | echo "Usage: mt /path/to/folder" 66 | return 0 67 | fi 68 | 69 | RWDIR=$1 70 | TMPDIR=`mktemp -d -p /mnt/ramdisk/` 71 | cp -a $RWDIR/* $TMPDIR 72 | mount -t tmpfs -o size=100M tmpfs $RWDIR 73 | cp -a $TMPDIR/* $RWDIR/ 74 | rm -rf $TMPDIR 75 | } 76 | 77 | ####################### 78 | # Sysinfo # 79 | ####################### 80 | 81 | echo "==================================" 82 | uname -mnrs 83 | echo "==================================" 84 | uptime 85 | echo "==================================" 86 | who 87 | echo "==================================" 88 | echo "Welcome to $IP_HERE, $FROM_ID " 89 | echo "==================================" 90 | 91 | ####################### 92 | # IP Camera # 93 | ####################### 94 | 95 | # Readable PS1 96 | TXTGRN="\[\033[0;32m\]" 97 | TXTPUR="\[\033[0;35m\]" 98 | TXTRST="\[\033[0m\]" 99 | 100 | IP_HERE_SHORT=${IP_HERE#172.16.} 101 | FW_VER=`cat /etc/firmware-version` 102 | FW_VER_SHORT=${FW_VER:0:6} 103 | PS1=${TXTGRN}"[${FW_VER_SHORT}]"${TXTRST}'@'${TXTPUR}${IP_HERE_SHORT}${TXTRST}':\w \$ ' 104 | 105 | DEV_SERVER="172.16.5.32" 106 | alias mount-home="mount -t nfs -o tcp,nolock $DEV_SERVER:/home /home" 107 | alias mount-rw="umount /etc; mount -o rw,remount /" 108 | alias mount-debugfs="mount -t debugfs debugfs /sys/kernel/debug" 109 | 110 | echo "----------------------------------" 111 | cat /var/run/sessioninfo 112 | echo "----------------------------------" 113 | 114 | -------------------------------------------------------------------------------- /subversion-scripts/svn-side-by-side-dirdiff: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # TortoiseSVN killer... 3 | # Use "svn cat" to retreve related files, then employ dirdiff as diff utility. 4 | 5 | get_svn_log() 6 | { 7 | SVN_LOG=`svn log -q 2> /dev/null| grep "^r" | cut -d ' ' -f 1 | head -n $1` 8 | } 9 | 10 | get_caret_range() 11 | { 12 | CARET=`echo -n ${1#HEAD} | wc -m` 13 | 14 | get_svn_log $((CARET + 1)) 15 | 16 | IFS='' 17 | cur_revision=`echo $SVN_LOG | head -1` 18 | pre_revision=`echo $SVN_LOG | tail -1` 19 | unset IFS 20 | } 21 | 22 | get_num_range() 23 | { 24 | RANGE=${1#HEAD\~} 25 | 26 | get_svn_log $(($RANGE + 1)) 27 | 28 | IFS='' 29 | cur_revision=`echo $SVN_LOG | head -1` 30 | pre_revision=`echo $SVN_LOG | tail -1` 31 | unset IFS 32 | } 33 | 34 | help() 35 | { 36 | echo "Usage: $PROGNAME <revision|HEAD^^^...|HEAD~number|revision1..revision2]" 37 | } 38 | 39 | PROGNAME=`basename $0` 40 | 41 | if [ $# -lt 1 ]; then 42 | help 43 | exit 1 44 | fi 45 | 46 | if echo $1 | grep -q "\.\."; then 47 | cur_revision=`echo $1 | cut -d '.' -f 1` 48 | pre_revision=`echo $1 | cut -d '.' -f 3` 49 | elif echo $1 | grep -q "\-r"; then 50 | r_dashr="-r" 51 | cur_revision="r"${1/${r_dashr}/} 52 | pre_revision="r"$((${1/${r_dashr}/}-1)) 53 | elif echo $1 | grep -q "r"; then 54 | r_dashr="r" 55 | cur_revision="r"${1/${r_dashr}/} 56 | pre_revision="r"$((${1/${r_dashr}/}-1)) 57 | elif echo $1 | grep -q "^HEAD\^\+"; then 58 | get_caret_range $1 59 | elif echo $1 | grep -q "^HEAD~"; then 60 | get_num_range $1 61 | else 62 | help 63 | exit 1 64 | fi 65 | 66 | echo "cur: $cur_revision pre: $pre_revision" 67 | 68 | # Using tmpfs for high performance I/O 69 | [ -d "/dev/shm" ] && tmpdir="/dev/shm" || tmpdir="/tmp" 70 | 71 | cur_tmpdir="${tmpdir}/${cur_revision}" 72 | pre_tmpdir="${tmpdir}/${pre_revision}" 73 | 74 | export LC_ALL=POSIX 75 | repo_root=`svn info 2> /dev/null | grep "^Repository Root:" | sed -e "s/^Repository Root: //"` 76 | [ -z "${repo_root}" ] && repo_root="http://rd1-1/subversion" 77 | 78 | if [ -n "$r_dashr" ]; then 79 | filelist=`svn log -v -r${cur_revision} ${repo_root} | grep "^ [A|M]" | awk '{print $2}' | sort | uniq` 80 | else 81 | repo_url=`svn info 2> /dev/null | grep "^URL:" | sed -e "s/^URL: //"` 82 | filelist=`svn log -v -r${pre_revision}:${cur_revision} ${repo_url} | grep "^ [A|M]" | awk '{print $2}' | sort | uniq` 83 | fi 84 | 85 | mkdir ${cur_tmpdir} ${pre_tmpdir} 86 | for filepath in ${filelist}; do 87 | #echo $repo_root/$filepath 88 | svn cat -r ${cur_revision} ${repo_root}/${filepath} > ${cur_tmpdir}/`basename $filepath` 2> /dev/null 89 | svn cat -r ${pre_revision} ${repo_root}/${filepath} > ${pre_tmpdir}/`basename $filepath` 2> /dev/null 90 | done 91 | 92 | # Remove empty file generated by "svn cat" a non-exist file[@REV] or a directory, e.g. 93 | # A /foo --> Directory 94 | # A /foo/bar.h --> New file 95 | find ${cur_tmpdir} ${pre_tmpdir} -type f -size 0 -exec rm -rf '{}' \; 96 | 97 | vim -c "let g:DirDiffAddArgs=''" -c "DirDiff ${cur_tmpdir} ${pre_tmpdir}" 98 | 99 | trap "rm -rf ${cur_tmpdir} ${pre_tmpdir}" 0 1 2 15 100 | 101 | rm -rf ${cur_tmpdir} ${pre_tmpdir} 102 | -------------------------------------------------------------------------------- /wg: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | #-i: ignore-case 4 | #--colour=auto: Surround the matching string with the marker find in GREP_COLOR environment variable (RECMOMMENDED) 5 | WCGREP_GREPARGS="-HnI --colour=auto" 6 | WCGREP_GREP="grep" 7 | WCGREP_IGNORE=".*/\.git\(/\|$\)\|.*/tags\|.*/cscope.out\|.*~$\|.*/\.svn.*\(/\|$\)" 8 | 9 | # below IFS is the keypoint 10 | IFS=$'\t ' 11 | EDITOR=vim 12 | 13 | if [ "$#" -eq 0 ]; then 14 | echo "Usage: wg PATTERN [INDEX]" 15 | echo " Open [INDEX]-th file by editor: $EDITOR" 16 | exit 0 17 | fi 18 | 19 | pattern="$1" 20 | INDEX=$2 21 | 22 | case `uname` in 23 | Darwin|*BSD) 24 | _strings='strings' 25 | ;; 26 | *) 27 | _strings='strings -e S' 28 | ;; 29 | esac 30 | 31 | function exist () { type "$1" &> /dev/null; } 32 | 33 | function _ag() 34 | { 35 | ag --smart-case --nocolor --nogroup --skip-vcs-ignores --hidden "$pattern" | $_strings | sort | nl -n ln | grep -P -Ii --colour=auto "$pattern" 36 | return 0; 37 | } 38 | 39 | function _rg() 40 | { 41 | rg --line-number --smart-case --no-heading --hidden --no-ignore-vcs -g '!.git/' "$pattern" | $_strings | sort | nl -n ln | grep -P -Ii --colour=auto "$pattern" 42 | return 0; 43 | } 44 | 45 | function _wcgrep() 46 | { 47 | case "$0" in 48 | *WGC*) 49 | # [NOTE] Don't ignore case => Lightning fast 50 | bGrepExcDir=`$WCGREP_GREP --help | grep "exclude-dir"` 51 | if [ -n "$bGrepExcDir" ]; then 52 | export GREP_OPTIONS="--exclude-dir=\*/.svn/\* --exclude-dir=\*/.git/\* --exclude=\*~ --exclude=\*.swp --exclude=cscope.* --exclude=tags" 53 | else 54 | export GREP_OPTIONS="--exclude=\*~ --exclude=\*.swp --exclude=cscope.* --exclude=tags" 55 | fi 56 | ${WCGREP_GREP} "$pattern" . -R ${WCGREP_GREPARGS} | nl -n ln | grep -I --colour=auto "$pattern" 57 | ;; 58 | 59 | *wg*) 60 | # [NOTE] ignore case => slower 61 | WCGREP_GREPARGS=${WCGREP_GREPARGS}" -i" 62 | find $pathargs -regex ${WCGREP_IGNORE:-'.*/\.git\(/\|$\)\|.*~$\|.*/\.svn\(/\|$\)'} -prune -o \ 63 | -type f -print0 | xargs -r0 ${WCGREP_GREP:-grep} ${WCGREP_GREPARGS:--HnI} "$pattern" \ 64 | | nl -n ln | grep -Ii --colour=auto "$pattern" 65 | ;; 66 | esac 67 | } 68 | 69 | if [ -n "$INDEX" ]; then 70 | if exist rg; then 71 | result=$(_rg) 72 | elif exist ag; then 73 | result=$(_ag) 74 | else 75 | result=$(_wcgrep); 76 | fi 77 | 78 | if [ "$INDEX" == "a" ]; then 79 | #FIXME: Why "tr" executed before "cut" in this statement FILENAME=`echo $result | cut -d ":" -f 1 | tr '\n' '@' | sed 's/@/ /g' 80 | FILENAME=`echo $result | awk '{print $2}' | cut -d ":" -f 1 | sort | uniq` 81 | FILENAME1=`echo $FILENAME | tr '\n' '@' | sed 's/@/ /g'` 82 | LINENUMBER=`echo $result | sed -n "1p" | awk '{print $2}' | cut -d ":" -f 2` 83 | $EDITOR -X -p $FILENAME1 -c "silent! /$pattern" +$LINENUMBER 84 | else 85 | str=`echo $result | sed -n "${INDEX}p" | awk '{print $2}'` 86 | FILENAME=`echo $str | cut -d ":" -f 1` 87 | LINENUMBER=`echo $str | cut -d ":" -f 2` 88 | echo Edit $INDEX-th, Filename: $FILENAME, LN: $LINENUMBER 89 | $EDITOR $FILENAME -c "silent! /$pattern" +$LINENUMBER 90 | fi 91 | else 92 | if exist rg; then 93 | _rg 94 | elif exist ag; then 95 | _ag 96 | else 97 | _wcgrep 98 | fi 99 | fi 100 | 101 | -------------------------------------------------------------------------------- /mkapp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Script for project make file 3 | case "$0" in 4 | *vivaldi*) 5 | export soc_platform=vivaldi 6 | export BUILDROOTDIR=/opt/Vivotek/lsp/buildroot-2.0.0.0 7 | export VIVALDIDIR=/opt/Vivotek/lsp/vivaldi-2.0.0.0 8 | export TOOLSDIR=${BUILDROOTDIR}/build_arm_nofpu/staging_dir/bin 9 | export PRJROOT=${VIVALDIDIR} 10 | export TARGET=arm-linux 11 | export PREFIX=${PRJROOT}/tools 12 | export TARGET_PREFIX=${PREFIX}/${TARGET} 13 | export PATH=${TOOLSDIR}:${PREFIX}/bin:${PATH} 14 | export MODULEINC=${PRJROOT}/kernel/modules/include 15 | export KERNELINC=${PRJROOT}/kernel/linux-2.4/include 16 | ;; 17 | *bach*) 18 | export soc_platform=bach 19 | export LSPDIR=/opt/Vivotek/lsp/bach 20 | export BUILDROOTDIR=${LSPDIR}/buildroot 21 | export PROJECT=kernel_platform_sq 22 | export PRJROOT=${LSPDIR}/${PROJECT} 23 | export PATH="$PATH:${BUILDROOTDIR}/build_arm_nofpu/staging_dir/bin" 24 | export KERNELINC=${PRJROOT}/kernel/linux-2.6/include 25 | export KERNELSRC=${PRJROOT}/kernel/linux-2.6 26 | ;; 27 | *haydn*) 28 | export soc_platform=haydn 29 | #export LSPDIR=/opt/Vivotek/lsp/haydn 30 | export LSPDIR=/opt/Vivotek/lsp/haydnEABI 31 | export BUILDROOTDIR=${LSPDIR}/buildroot 32 | export PATH="$PATH:${BUILDROOTDIR}/build_arm_nofpu/staging_dir/bin" 33 | ;; 34 | *mozart*) 35 | export soc_platform=mozart3 36 | export LSPDIR=/opt/Vivotek/lsp/mozart3 37 | export BUILDROOTDIR=${LSPDIR}/buildroot 38 | export PROJECT=kernel_platform 39 | export PRJROOT=${LSPDIR}/${PROJECT} 40 | export TOOLSDIR=${BUILDROOTDIR}/build_arm_nofpu/staging_dir/bin 41 | export PATH="$PATH:${BUILDROOTDIR}/build_arm_nofpu/staging_dir/bin" 42 | ;; 43 | *dm355*) 44 | export soc_platform=dm355 45 | export LSPDIR=/opt/Vivotek/lsp/DM355 46 | export PROJECT=kernel_platform 47 | export PRJROOT=${LSPDIR}/${PROJECT} 48 | export TOOLSDIR="/opt/montavista/pro5.0/devkit/arm/v5t_le/bin" 49 | #export TOOLSDIR="/opt/montavista/pro/devkit/arm/v5t_le/bin" 50 | export TARGET=arm-linux 51 | export PREFIX=${PRJROOT}/tools 52 | export TARGET_PREFIX=${PREFIX}/${TARGET} 53 | export PATH="${TOOLSDIR}:${PREFIX}/bin:/opt/montavista/pro5.0/bin:/opt/montavista/common/bin:${PATH}" 54 | ;; 55 | *dm365*) 56 | export soc_platform=dm365 57 | export LSPDIR=/opt/Vivotek/lsp/DM365 58 | export PROJECT=kernel_platform 59 | export PRJROOT=${LSPDIR}/${PROJECT} 60 | export TOOLSDIR="/opt/montavista/pro5.0/devkit/arm/v5t_le/bin" 61 | #export TARGET=arm-linux 62 | export PREFIX=${PRJROOT}/tools 63 | export TARGET_PREFIX=${PREFIX}/${TARGET} 64 | export PRODUCTNAME=DM365 65 | export PATH="${TOOLSDIR}:${PREFIX}/bin:/opt/montavista/pro5.0/bin:/opt/montavista/common/bin:${PATH}" 66 | #export DVSDK="/home/yenchun/project/DM365/dvsdk_2_10_01_18" 67 | #export DVSDK="/home/yenchun/project/DM365/dvsdk_2_10_01_19" 68 | #export DVSDK="/home/yenchun/project/DM365/dvsdk_3_10_00_12" 69 | ;; 70 | *) 71 | exit 1 72 | ;; 73 | esac 74 | 75 | echo soc_platform=$soc_platform 76 | 77 | export PROJ_ROOT=~/Project/Horus/apps/app_cluster 78 | #export BUILD_ROOT=~/project/${soc_platform}/build 79 | export BUILD_ROOT=~/tmp/Horus/${soc_platform}/build 80 | export ROOTFSDIR=~/tmp/Horus/${soc_platform}/rootfs 81 | 82 | make soc_platform=$soc_platform BUILD_ROOT=$BUILD_ROOT $@ 83 | 84 | exit 0 85 | -------------------------------------------------------------------------------- /use_distcc_ccache: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # NOTE: source this file to enable ccache & distcc feature 3 | # 4 | # kent@ubuntu:scripts (1) >>> ll /usr/local/bin/arm-linux-gcc 5 | # lrwxrwxrwx 1 root root 15 2011-02-10 15:01 /usr/local/bin/arm-linux-gcc -> /usr/bin/ccache* 6 | # 7 | # (1) ccache tips: 8 | # Set CCACHE_DIR to tmpfs/ramdisk to speed up and reduce journaling filesystem i/o times 9 | # 10 | # (2) how to tell a directory is tmpfs by dd tool? (speed difference) 11 | # Write: 12 | # +--------------------------------------------------------------------------------+ 13 | # | $ dd if=/dev/zero of=/dev/shm/testfile bs=1M count=1024 conv=fdatasync,notrunc | 14 | # | 1073741824 bytes (1.1 GB) copied, 1.34261 seconds, 800 MB/s | 15 | # | $ dd if=/dev/zero of=/tmp/testfile bs=1M count=1024 conv=fdatasync,notrunc | 16 | # | 1073741824 bytes (1.1 GB) copied, 3.07005 seconds, 350 MB/s | 17 | # +--------------------------------------------------------------------------------+ 18 | # Read: 19 | # +--------------------------------------------------------------------------------+ 20 | # | $ echo 3 > /proc/sys/vm/drop_caches | 21 | # | $ dd if=/tmp/tempfile of=/dev/null bs=1M count=1024 | 22 | # +--------------------------------------------------------------------------------+ 23 | 24 | ########## 25 | # ccache # 26 | ########## 27 | 28 | platform=`\which -a arm-linux-gcc 2> /dev/null` 29 | case $platform in 30 | *vivaldi*) 31 | platform_suffix="Vivaldi" 32 | ;; 33 | *bach*) 34 | platform_suffix="Bach" 35 | ;; 36 | *haydn*) 37 | platform_suffix="Haydn" 38 | ;; 39 | *mozart3e*|*mozart3v2*|*mozart3v3*) 40 | platform_suffix="Mozart3x" 41 | ;; 42 | *mozart3*) 43 | platform_suffix="Mozart3" 44 | ;; 45 | *montavista*) 46 | platform_suffix="DM36X" 47 | ;; 48 | *DM8127*) 49 | platform_suffix="DM8127" 50 | ;; 51 | *DM385*) 52 | platform_suffix="DM385" 53 | ;; 54 | *xarina*) 55 | platform_suffix="Xarina" 56 | ;; 57 | "") 58 | echo "[Error] arm-linux-gcc not found." 59 | return 1 60 | ;; 61 | esac 62 | 63 | echo "[Info] You are building on <${platform_suffix}> platform." 64 | 65 | CCACHE_BIN=/usr/bin/ccache 66 | 67 | # Refrence from "man ccache" -> "SHARING A CACHE" 68 | export CCACHE_UMASK="002" 69 | 70 | export PATH=/usr/local/bin:$PATH 71 | export CCACHE_DIR="/tmp/.ccache.${platform_suffix}" 72 | 73 | if [ -d "${CCACHE_DIR}" ]; then 74 | echo "+----------------------------------------------------+" 75 | echo "| Current ccache statistics |" 76 | echo "+----------------------------------------------------+" 77 | $CCACHE_BIN -s 78 | else 79 | mkdir ${CCACHE_DIR} 80 | chmod 1777 ${CCACHE_DIR} 81 | 82 | echo "+----------------------------------------------------+" 83 | echo "| Initial ccache |" 84 | echo "+----------------------------------------------------+" 85 | $CCACHE_BIN --max-size=3G -s 86 | 87 | # Refrence from "man ccache" -> "SHARING A CACHE" 88 | find ${CCACHE_DIR} -type d | xargs chmod g+s 89 | fi 90 | 91 | ########## 92 | # distcc # 93 | ########## 94 | 95 | #export DISTCC_HOSTS='localhost 172.16.7.167' 96 | #export CCACHE_PREFIX="distcc" 97 | 98 | -------------------------------------------------------------------------------- /vvnt-devel-camera: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: execute `source ubnt-devel-aircam` under top level folder of unifi-video-firmware 3 | 4 | git rev-parse --show-toplevel > /dev/null 2>&1 5 | if [ $? -eq 0 ]; then 6 | TOPDIR=$(git rev-parse --show-toplevel) 7 | pushd "$TOPDIR" > /dev/null 8 | else 9 | echo "Please run under a git repo!" 10 | exit 1 11 | fi 12 | 13 | export PRODUCTDIR="$TOPDIR" 14 | 15 | # For Openwrt build system (refer to Openwrt/Makefile) 16 | # Export below variable, you can make any package w/o typing annyoing long string 17 | # make package/xxx/compile => make compile (or just make) 18 | # make package/xxx/install => make install 19 | # make package/xxx/clean => make clean 20 | 21 | # unset $TOPDIR when you hit some clean build issue 22 | #export TOPDIR=${PRODUCTDIR}/build-arm 23 | #export INCLUDE_DIR=${TOPDIR}/include 24 | 25 | # For packages which supports parallel build (PKG_BUILD_PARALLEL:=1) 26 | #export PKG_JOBS="-j$(grep processor /proc/cpuinfo | wc -l)" 27 | 28 | # Fetch $GEN=[genXF] and $CONF=[rel|dbg], read from last built 29 | #MAKE_TARGET=$(ls -t .marker-*_prepare | head -n1) 30 | #MAKE_TARGET=$(ls -td openwrt-gen* | head -n1) 31 | #export GEN=$(echo "$MAKE_TARGET" | cut -d '_' -f 1 | cut -d '-' -f 2) 32 | #export CONF=$(echo "$MAKE_TARGET" | cut -d '_' -f 1 | cut -d '-' -f 3) 33 | #echo Last build: GEN="$GEN" CONF="$CONF" 34 | 35 | # export some useful env var 36 | #export IMAGEDIR=${TOPDIR}/build-arm/images/ 37 | #export STAGINGDIR=${PRODUCTDIR}/.openwrt/staging_dir 38 | #export STAGINGBINDIR=${PRODUCTDIR}/.openwrt/staging_dir/host/bin 39 | #export MWDIR=${PRODUCTDIR}/packages/packages-ubnt/ubnt-middleware/unifi-video-fw-middleware/ 40 | 41 | #export PATH=$STAGINGBINDIR:$PATH 42 | alias om='PATH=$STAGINGBINDIR:$PATH make -j$(nproc)' 43 | alias omc='PATH=$STAGINGBINDIR:$PATH m clean' 44 | alias omi='PATH=$STAGINGBINDIR:$PATH m install' 45 | 46 | # Make symlink # symlink name 47 | #ln -sf openwrt-"${GEN}"-"${CONF}" .openwrt 48 | ln -sf ${TOPDIR}/build-arm/images rel-artifacts 49 | ln -sf ${TOPDIR}/build-yocto-arm/firmware/ rel-artifacts-cooper 50 | ln -sf ${TOPDIR}/subprojects/camera-soc*/*/ambarella/out/*/fakeroot rootfs-flexible 51 | ln -sf ${TOPDIR}/subprojects/camera-soc-yocto/cooper_linux_sdk/ambarella/out/yocto_out/*/tmp/work/*-poky-linux/ipcam-image/1.0*/rootfs rootfs-cooper 52 | 53 | ln -sf ${TOPDIR}/subprojects/camera-soc-cv/cv2x_linux_sdk_*/ambarella/out/cv*_*/symbols non-stripped-symbols-yocto 54 | ln -sf ${TOPDIR}/build-yocto-arm/tmp/sysroots-components/aarch64/linux-libc-headers/usr/include linux-include 55 | ln -sf ${TOPDIR}/build-arm/target/aarch64-unknown-linux-gnu target 56 | ln -sf ${TOPDIR}/build-arm/target/aarch64-unknown-linux-gnu/release release-yocto 57 | ln -sf ${TOPDIR}/build-yocto-arm/tmp/sysroots-components/aarch64 installDev 58 | 59 | # symlink for Yocto 60 | 61 | #ln -sf .openwrt/artifacts/*bootloader.bin rel-preload_image.bin 62 | #ln -sf $(ls .openwrt/artifacts/*[^bootloader].bin | tail -n1) rel-firmware.bin 63 | 64 | #godir PATTERN 65 | 66 | popd > /dev/null 67 | -------------------------------------------------------------------------------- /vvtk/cdfparse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # CDF.xml parsing script 4 | # 5 | # Author: Ramax Lo <ramax.lo@vivotek.com> 6 | # 7 | # 8 | 9 | import os, sys 10 | import xml.dom.minidom 11 | 12 | params = [] 13 | 14 | def help(): 15 | print 'Usage: cdfparser.xml <CDF.xml>' 16 | 17 | def is_element(e): 18 | return e.nodeType == xml.dom.Node.ELEMENT_NODE 19 | 20 | def is_text(e): 21 | return e.nodeType == xml.dom.Node.TEXT_NODE 22 | 23 | def has_direct_element(element, name): 24 | for e in element.childNodes: 25 | if is_element(e) and e.tagName == name: 26 | return True 27 | 28 | return False 29 | 30 | def get_direct_element(element, name): 31 | for e in element.childNodes: 32 | if is_element(e) and e.tagName == name: 33 | return e 34 | 35 | return None 36 | 37 | def has_alias(element): 38 | return has_direct_element(element, 'aliasxpath') 39 | 40 | def has_value(element): 41 | return has_direct_element(element, 'value') 42 | 43 | def get_text(element): 44 | textnode = element.childNodes[0] 45 | if is_text(textnode): 46 | return textnode.nodeValue 47 | 48 | return None 49 | 50 | def get_seclevel(element): 51 | tmp = element 52 | 53 | while not has_direct_element(tmp, 'seclevel'): 54 | tmp = tmp.parentNode 55 | 56 | if tmp.tagName == 'root': 57 | return 'n/a' 58 | 59 | seclevel = get_direct_element(tmp, 'seclevel') 60 | 61 | return get_text(seclevel) 62 | 63 | def get_alias(element): 64 | alias = get_direct_element(element, 'aliasxpath') 65 | 66 | return get_text(alias) 67 | 68 | def get_check(element): 69 | check = get_direct_element(element, 'check') 70 | 71 | if check: 72 | return get_text(check) 73 | 74 | return 'n/a' 75 | 76 | def store_path(path, element): 77 | seclevel = get_seclevel(element) 78 | check = get_check(element) 79 | 80 | tmp = {} 81 | tmp['path'] = path 82 | tmp['seclevel'] = seclevel 83 | tmp['check'] = check 84 | 85 | params.append(tmp) 86 | 87 | def store_alias_path(path, element): 88 | seclevel = get_seclevel(element) 89 | aliasxpath = get_alias(element) 90 | 91 | tmp = {} 92 | tmp['path'] = path 93 | tmp['aliasxpath'] = aliasxpath 94 | 95 | params.append(tmp) 96 | 97 | def do_parse(path, element): 98 | if has_value(element): 99 | tmp = path + element.tagName 100 | 101 | store_path(tmp, element) 102 | elif has_alias(element): 103 | tmp = path + element.tagName 104 | 105 | store_alias_path(tmp, element) 106 | else: 107 | for e in element.childNodes: 108 | if is_element(e): 109 | tmp = path + '%s_' % element.tagName 110 | do_parse(tmp, e) 111 | 112 | def parse(dom): 113 | root = dom.getElementsByTagName('root')[0] 114 | 115 | for e in root.childNodes: 116 | if is_element(e): 117 | path = '' 118 | do_parse(path, e) 119 | 120 | def param_cmp(x, y): 121 | if x['path'] > y['path']: 122 | return 1 123 | elif x['path'] < y['path']: 124 | return -1 125 | else: 126 | return 0 127 | 128 | def get_origin(alias): 129 | for p in params: 130 | if not p.has_key('aliasxpath') and p['path'] == alias: 131 | return p 132 | 133 | return None 134 | 135 | def dump_params(): 136 | params.sort(cmp = param_cmp) 137 | 138 | for p in params: 139 | if p.has_key('aliasxpath'): 140 | origin = get_origin(p['aliasxpath']) 141 | 142 | if origin: 143 | print '%-5s %s %s' % (origin['seclevel'], p['path'], origin['check']) 144 | else: 145 | print '%-5s %s %s' % ('alias', p['path'], 'alias') 146 | else: 147 | print '%-5s %s %s' % (p['seclevel'], p['path'], p['check']) 148 | 149 | if __name__ == '__main__': 150 | if len(sys.argv) < 2: 151 | help() 152 | sys.exit(1) 153 | 154 | infile = sys.argv[1] 155 | dom = xml.dom.minidom.parse(infile) 156 | 157 | parse(dom) 158 | dump_params() 159 | -------------------------------------------------------------------------------- /vim2html.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Filename: vim2html.bash 4 | # Description: Convert source code to html using vim 5 | # Maintainer: Jeremy Cantrell <jmcantrell@gmail.com> 6 | # Last Modified: Sun 2009-03-08 00:57:35 (-0500) 7 | 8 | # REQUIREMENTS: bash-utils 9 | 10 | # Vim is really good at recognizing filetypes and highlighting the syntax in a 11 | # myriad of colorschemes. Vim is also good at turning that highlighted code 12 | # into HTML. The only missing piece was making this process parameter driven 13 | # and scriptable. That's what this script is intended to solve. 14 | 15 | 16 | # FUNCTIONS {{{1 17 | 18 | cleanup() #{{{2 19 | { 20 | rm -f "$TMP_FILE" 21 | } 22 | 23 | usage_exit() #{{{2 24 | { 25 | cat >&2 <<-EOF 26 | Usage: $SCRIPT_NAME [options] input_file [output_file] 27 | Creates HTML exports of source code via vim. 28 | 29 | -h Display this help message. 30 | 31 | -i Interactive. Prompt for certain actions. 32 | -v Be verbose. 33 | 34 | -f FILETYPE Use FILETYPE as vim filetype. 35 | -n Output line numbers. 36 | -t Use tidy to cleanup HTML. 37 | -c COLORSCHEME Use COLORSCHEME as vim colorscheme. 38 | -l Use light background. 39 | -L List available vim colorschemes. 40 | 41 | EOF 42 | exit ${1:-0} 43 | } 44 | 45 | error_exit() #{{{2 46 | { 47 | msg-error "$1" 48 | exit ${2:-1} 49 | } 50 | 51 | colorscheme_list() #{{{2 52 | { 53 | ( 54 | find "$VIM_HOME/colors" -name "*.vim" 2>/dev/null 55 | find "$HOME/.vim/colors" -name "*.vim" 2>/dev/null 56 | ) | awk -F'/' '{print $NF}' | sed 's/\.vim$//' | sort | uniq 57 | } 58 | 59 | # VARIABLES {{{1 60 | 61 | SCRIPT_NAME=$(basename "$0" .bash) 62 | VIM_CMD="vim -n -u NONE" 63 | VIM_HOME=/usr/share/vim/vimcurrent 64 | COLORSCHEME=inkpot 65 | BACKGROUND=dark 66 | TMP_FILE=$(mktemp) 67 | 68 | # COMMAND-LINE OPTIONS {{{1 69 | 70 | while getopts ":hifvqf:ntc:lL" options; do 71 | case $options in 72 | i) export INTERACTIVE=1 ;; 73 | f) export INTERACTIVE=0 ;; 74 | v) export VERBOSE=1 ;; 75 | q) export VERBOSE=0 ;; 76 | 77 | f) FILETYPE=$OPTARG ;; 78 | n) LINE_NUMBERS=1 ;; 79 | t) TIDY=1 ;; 80 | c) COLORSCHEME=$OPTARG ;; 81 | l) BACKGROUND=light ;; 82 | L) colorscheme_list; exit 0 ;; 83 | 84 | h) usage_exit 0 ;; 85 | *) usage_exit 1 ;; 86 | esac 87 | done && shift $(($OPTIND - 1)) 88 | 89 | trap cleanup INT TERM EXIT 90 | 91 | # ERROR-CHECKING {{{1 92 | 93 | [[ -d $VIM_HOME ]] || 94 | VIM_HOME="$(find /usr/share/vim -mindepth 1 -maxdepth 1 \ 95 | -type d -name "vim*" 2>/dev/null | sort -r | head -n1)" 96 | 97 | [[ "$VIM_HOME" ]] || error_exit "Could not find Vim home directory" 98 | 99 | INFILE=$1 100 | 101 | [[ $INFILE ]] || error_exit "Input file not provided" 102 | [[ -f $INFILE ]] || error_exit "Input file does not exist or is not a regular file" 103 | 104 | OUTFILE=$2 105 | 106 | [[ $OUTFILE ]] || OUTFILE=${INFILE##*/}.html 107 | 108 | 109 | if interactive && [[ -f $OUTFILE ]]; then 110 | question "Overwrite '$OUTFILE'?" || exit 1 111 | fi 112 | 113 | # BUILD CONVERSION SCRIPT {{{1 114 | 115 | : >$TMP_FILE 116 | 117 | cat >>$TMP_FILE<<-EOF 118 | set nocompatible 119 | syntax on 120 | set t_Co=256 121 | set expandtabs 122 | set tabstop=4 123 | set background=$BACKGROUND 124 | let html_ignore_folding = 1 125 | let html_use_css = 0 126 | EOF 127 | 128 | ( 129 | [[ $FILETYPE ]] && echo "set ft=$FILETYPE" 130 | [[ $LINE_NUMBERS ]] && echo "set nu" 131 | [[ $COLORSCHEME ]] && echo "colorscheme $COLORSCHEME" 132 | ) >>$TMP_FILE 133 | 134 | cat >>$TMP_FILE<<-EOF 135 | runtime! syntax/2html.vim 136 | w! $OUTFILE 137 | q! 138 | q! 139 | EOF 140 | #}}} 141 | 142 | verbose && msg-info "Converting file '$INFILE' to '$OUTFILE'" 143 | $VIM_CMD -S "$TMP_FILE" "$INFILE" >/dev/null 2>&1 144 | sed -i "s%<title>.*%$(basename "$INFILE")%" "$OUTFILE" 145 | 146 | if [[ $TIDY ]]; then 147 | verbose && msg-info "Cleaning HTML file '$OUTFILE'" 148 | tidy --tidy-mark no -utf8 -f /dev/null -clean -asxhtml -o "$OUTFILE" "$OUTFILE" 149 | fi 150 | -------------------------------------------------------------------------------- /vvnt_nightly_backup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Mirror SOURCE -> DEST 3 | # - If DEST is a local path: use rsync (FULL clone with --delete) 4 | # - If DEST starts with gs:// : use gsutil rsync (FULL clone with -d) 5 | # Usage: 6 | # rsync-backup.sh [--dry-run] 7 | # Examples: 8 | # rsync-backup.sh /data/projects /mnt/backup/projects 9 | # rsync-backup.sh /data/projects gs://team-taiwan-shared/backup/kent 10 | # rsync-backup.sh /data/projects gs://bucket/path --dry-run 11 | 12 | set -Eeuo pipefail 13 | 14 | # ===== Args ===== 15 | if [[ $# -lt 2 || $# -gt 3 ]]; then 16 | echo "Usage: $0 [--dry-run]" 17 | exit 1 18 | fi 19 | 20 | SOURCE="$1" 21 | DEST="$2" 22 | THIRD_ARG="${3:-}" 23 | 24 | # ===== Settings ===== 25 | LOG_DIR="/var/log/rsync-backup" 26 | RUN_NICE=10 27 | RUN_IONICE_CLASS=2 28 | RUN_IONICE_PRIO=7 29 | EXCLUDES_FILE="" # optional: e.g. /etc/rsync-backup.exclude (one pattern per line) 30 | 31 | # ===== Derived ===== 32 | TS="$(date +'%Y%m%d-%H%M%S')" 33 | mkdir -p "$LOG_DIR" 34 | LOG_FILE="${LOG_DIR}/rsync-backup_${TS}.log" 35 | 36 | LOCK_DIR="/var/lock" 37 | mkdir -p "$LOCK_DIR" 38 | LOCK_FILE="${LOCK_DIR}/rsync-backup.lock" 39 | 40 | DRYRUN=0 41 | if [[ "$THIRD_ARG" == "--dry-run" || "${DRY_RUN:-0}" == "1" ]]; then 42 | DRYRUN=1 43 | fi 44 | 45 | # ===== Helpers ===== 46 | log() { printf '[%s] %s\n' "$(date '+%F %T')" "$*" | tee -a "$LOG_FILE" ; } 47 | die() { log "ERROR: $*"; exit 1; } 48 | 49 | require_cmd() { 50 | command -v "$1" >/dev/null 2>&1 || die "Required command not found: $1" 51 | } 52 | 53 | # ===== Safety checks ===== 54 | [[ -d "$SOURCE" ]] || die "SOURCE does not exist or is not a directory: $SOURCE" 55 | SOURCE_WITH_SLASH="${SOURCE%/}/" 56 | 57 | is_gs_dest=0 58 | if [[ "$DEST" =~ ^gs:// ]]; then 59 | is_gs_dest=1 60 | require_cmd gsutil 61 | else 62 | # Local path destination safety 63 | [[ -e "$DEST" ]] || mkdir -p "$DEST" 64 | [[ -d "$DEST" ]] || die "DEST is not a directory: $DEST" 65 | [[ "$DEST" != "/" && -n "$DEST" ]] || die "Refusing to sync to '/' or empty DEST" 66 | require_cmd rsync 67 | fi 68 | 69 | # ===== Optional excludes ===== 70 | RSYNC_EXCLUDES=() 71 | GSUTIL_EXCLUDE_REGEX="" 72 | if [[ -n "$EXCLUDES_FILE" ]]; then 73 | [[ -f "$EXCLUDES_FILE" ]] || die "EXCLUDES_FILE not found: $EXCLUDES_FILE" 74 | # For rsync: --exclude-from works directly. 75 | RSYNC_EXCLUDES=( --exclude-from="$EXCLUDES_FILE" --delete-excluded ) 76 | 77 | # For gsutil: build a single regex for -x. It matches any path containing one of the patterns. 78 | # Note: patterns are treated as regex, not rsync globs. Keep them simple (e.g., ^\.cache/|\.DS_Store$). 79 | # Convert each non-empty, non-comment line into an alternation; escape slashes. 80 | mapfile -t _lines < <(sed -E '/^\s*($|#)/d' "$EXCLUDES_FILE") 81 | if ((${#_lines[@]})); then 82 | _escaped=() 83 | for l in "${!_lines[@]}"; do 84 | pat="${_lines[$l]}" 85 | pat="${pat//\//\/}" # minimal escaping; user should supply regex-ready patterns 86 | _escaped+=( "$pat" ) 87 | done 88 | GSUTIL_EXCLUDE_REGEX="$(IFS='|'; echo "${_escaped[*]}")" 89 | fi 90 | fi 91 | 92 | # ===== Workers ===== 93 | do_local_rsync() { 94 | local -a opts=( 95 | --archive 96 | --delete 97 | --delete-after 98 | --numeric-ids 99 | --hard-links 100 | --xattrs 101 | --acls 102 | --human-readable 103 | --itemize-changes 104 | --partial 105 | --inplace 106 | --prune-empty-dirs 107 | --exclude='.DS_Store' 108 | ) 109 | if ((DRYRUN)); then 110 | opts+=( --dry-run ) 111 | log "Running LOCAL rsync in DRY RUN mode." 112 | fi 113 | if ((${#RSYNC_EXCLUDES[@]})); then 114 | opts+=( "${RSYNC_EXCLUDES[@]}" ) 115 | fi 116 | 117 | log "Starting rsync: ${SOURCE_WITH_SLASH} -> ${DEST}" 118 | log "Options: ${opts[*]}" 119 | 120 | ionice -c "$RUN_IONICE_CLASS" -n "$RUN_IONICE_PRIO" \ 121 | nice -n "$RUN_NICE" \ 122 | rsync "${opts[@]}" "$SOURCE_WITH_SLASH" "$DEST" | tee -a "$LOG_FILE" 123 | 124 | local rc=${PIPESTATUS[2]} 125 | if [[ $rc -eq 0 || $rc -eq 24 ]]; then 126 | log "Local rsync finished with exit code $rc." 127 | else 128 | die "Local rsync failed with exit code $rc. See log: $LOG_FILE" 129 | fi 130 | } 131 | 132 | do_gsutil_rsync() { 133 | # -m: parallel; -r: recursive; -d: delete; -e: **exclude symlinks** (skip, don’t abort) 134 | local -a opts=( -m rsync -r -d -e ) 135 | ((DRYRUN)) && opts+=( -n ) 136 | [[ -n "$GSUTIL_EXCLUDE_REGEX" ]] && opts+=( -x "$GSUTIL_EXCLUDE_REGEX" ) 137 | 138 | log "Starting gsutil rsync: ${SOURCE_WITH_SLASH} -> ${DEST}" 139 | log "Options: ${opts[*]}" 140 | 141 | ionice -c "$RUN_IONICE_CLASS" -n "$RUN_IONICE_PRIO" \ 142 | nice -n "$RUN_NICE" \ 143 | gsutil "${opts[@]}" "$SOURCE_WITH_SLASH" "$DEST" | tee -a "$LOG_FILE" 144 | 145 | local rc=${PIPESTATUS[2]} 146 | [[ $rc -eq 0 ]] || die "gsutil rsync failed with exit code $rc. See log: $LOG_FILE" 147 | log "gsutil rsync finished with exit code $rc." 148 | } 149 | 150 | # ===== Run with lock ===== 151 | { 152 | flock -n 200 || die "Another backup is running (lock: $LOCK_FILE)." 153 | log "Log file: $LOG_FILE" 154 | if (( is_gs_dest )); then 155 | do_gsutil_rsync 156 | else 157 | do_local_rsync 158 | fi 159 | } 200>"$LOCK_FILE" 160 | -------------------------------------------------------------------------------- /trans_add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # The translation string merging script 4 | # 5 | # Author: Ramax Lo 6 | # 7 | # The script reads translation strings from an Excel file and merges 8 | # them with the existing XML file (translator.xml), while maintaining 9 | # ascending alphabet order. The merged result is written to output.xml, 10 | # if not specified in command line. An option is added to specify which 11 | # sheet in the Excel file is used for merging. 12 | # 13 | # Note to run the script, a Python module 'xlrd' needs to be installed 14 | # for reading data from Excel files. 15 | # 16 | # [2011/01/12 Update] 17 | # 1. Add existing tag overwritting support 18 | # 19 | 20 | import sys 21 | import getopt 22 | import xml.dom.minidom 23 | 24 | sys.path.append('/home/ramax/python/lib/python2.6/site-packages') 25 | import xlrd 26 | 27 | lang_map = { 28 | 'en' : 1, 29 | 'zh-tw': 3, 30 | 'de' : 4, 31 | 'es' : 5, 32 | 'fr' : 6, 33 | 'it' : 7, 34 | 'jp' : 8, 35 | 'po' : 9, 36 | 'zh-cn': 10, 37 | } 38 | 39 | outfile = 'output.xml' 40 | sheet_number = 0 41 | overwritten = False 42 | added_total = 0 43 | overwrite_total = 0 44 | 45 | def help_msg(): 46 | print "Usage: trans_add.py [-w] [-n sheet number] [output xml]" 47 | print ''' 48 | Arguments: 49 | -w Enable overwritting mode 50 | -n Specify the work sheet number in the EXCEL file (start from 0) 51 | The EXCEL file containing translation strings to be merged 52 | The XML file (translator.xml) used as the base for merging 53 | [output xml] The output XML file name 54 | ''' 55 | 56 | def lang_to_idx(lang): 57 | return lang_map[lang] 58 | 59 | def get_str(array, lang): 60 | return array[lang_to_idx(lang)].value 61 | 62 | def get_elements(element): 63 | tmp = [] 64 | 65 | for node in element.childNodes: 66 | if node.nodeType == xml.dom.Node.ELEMENT_NODE: 67 | tmp.append(node) 68 | return tmp 69 | 70 | def insert_str(dom, lang, tag, string): 71 | elements = get_elements(lang) 72 | ref_element = None 73 | duplicate = False 74 | global added_total, overwrite_total 75 | 76 | for element in elements: 77 | if element.tagName > tag: 78 | ref_element = element 79 | break 80 | elif element.tagName == tag: 81 | # The tag already exists 82 | if overwritten: 83 | duplicate = True 84 | ref_element = element 85 | break 86 | else: 87 | return 88 | else: 89 | pass 90 | 91 | if not duplicate: 92 | tmp = dom.createElement(tag) 93 | text = dom.createTextNode(string) 94 | newline = dom.createTextNode(u'\n') 95 | tmp.appendChild(text) 96 | lang.insertBefore(tmp, ref_element) 97 | lang.insertBefore(newline, ref_element) 98 | added_total = added_total + 1 99 | else: 100 | tmp = ref_element.firstChild; 101 | if not tmp: 102 | # Create a new text node 103 | print "Create a text node for <%s>" % ref_element.tagName 104 | tmp = dom.createTextNode(string) 105 | ref_element.appendChild(tmp) 106 | else: 107 | tmp.nodeValue = string 108 | overwrite_total = overwrite_total + 1 109 | 110 | 111 | def check_empty(row): 112 | for i in range(9): 113 | if i == 2: 114 | # We skip the 'note' column 115 | continue 116 | if row[i].ctype == xlrd.XL_CELL_EMPTY: 117 | return True 118 | 119 | return False 120 | 121 | ################### 122 | # START # 123 | ################### 124 | 125 | try: 126 | opts, args = getopt.getopt(sys.argv[1:], 'wn:') 127 | except getopt.GetoptError, e: 128 | print str(e) 129 | help_msg() 130 | sys.exit(1) 131 | 132 | for opt, val in opts: 133 | if opt == '-n': 134 | sheet_number = int(val) 135 | elif opt == '-w': 136 | print "Overwritting mode" 137 | overwritten = True 138 | 139 | if len(args) < 2: 140 | help_msg() 141 | sys.exit(1) 142 | 143 | excel = args[0] 144 | infile = args[1] 145 | if len(args) > 2: 146 | outfile = args[2] 147 | 148 | print "Write output to %s" % outfile 149 | book = xlrd.open_workbook(excel) 150 | sheet = book.sheet_by_index(sheet_number) 151 | 152 | dom = xml.dom.minidom.parse(infile) 153 | langs = dom.getElementsByTagName('lang') 154 | if len(langs) != 9: 155 | print "There must be 9 'lang' elements" 156 | sys.exit(1) 157 | 158 | for i in range(1, sheet.nrows): 159 | row = sheet.row(i) 160 | 161 | if check_empty(row): 162 | print "Skip row %d" % i 163 | continue 164 | 165 | tag = row[0].value 166 | en_str = get_str(row, 'en') 167 | de_str = get_str(row, 'de') 168 | es_str = get_str(row, 'es') 169 | fr_str = get_str(row, 'fr') 170 | it_str = get_str(row, 'it') 171 | jp_str = get_str(row, 'jp') 172 | po_str = get_str(row, 'po') 173 | zh_cn_str = get_str(row, 'zh-cn') 174 | zh_tw_str = get_str(row, 'zh-tw') 175 | 176 | insert_str(dom, langs[0], tag, en_str) 177 | insert_str(dom, langs[1], tag, de_str) 178 | insert_str(dom, langs[2], tag, es_str) 179 | insert_str(dom, langs[3], tag, fr_str) 180 | insert_str(dom, langs[4], tag, it_str) 181 | insert_str(dom, langs[5], tag, jp_str) 182 | insert_str(dom, langs[6], tag, po_str) 183 | insert_str(dom, langs[7], tag, zh_cn_str) 184 | insert_str(dom, langs[8], tag, zh_tw_str) 185 | 186 | out = open(outfile, 'w') 187 | outxml = dom.toxml('UTF-8') 188 | out.write(outxml) 189 | out.close() 190 | print "Added: %d Overwritten: %d" % (added_total, overwrite_total) 191 | -------------------------------------------------------------------------------- /ldd_arm: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Copyright (C) 1996-2001, 2002, 2003 Free Software Foundation, Inc. 3 | # This file is part of the GNU C Library. 4 | 5 | # The GNU C Library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2.1 of the License, or (at your option) any later version. 9 | 10 | # The GNU C Library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with the GNU C Library; if not, write to the Free 17 | # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18 | # 02111-1307 USA. 19 | 20 | 21 | # This is the `ldd' command, which lists what shared libraries are 22 | # used by given dynamically-linked executables. It works by invoking the 23 | # run-time dynamic linker as a command and setting the environment 24 | # variable LD_TRACE_LOADED_OBJECTS to a non-empty value. 25 | 26 | # We should be able to find the translation right at the beginning. 27 | TEXTDOMAIN=libc 28 | TEXTDOMAINDIR=/usr/share/locale 29 | 30 | RTLDLIST=/lib/ld-linux.so.* 31 | warn= 32 | bind_now= 33 | verbose= 34 | 35 | while test $# -gt 0; do 36 | case "$1" in 37 | --vers | --versi | --versio | --version) 38 | echo 'ldd (GNU libc) 2.3.2' 39 | echo $"Copyright (C) 2003 Free Software Foundation, Inc. 40 | This is free software; see the source for copying conditions. There is NO 41 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 42 | Written by Roland McGrath and Ulrich Drepper." 43 | exit 0 44 | ;; 45 | --h | --he | --hel | --help) 46 | echo $"Usage: ldd [OPTION]... FILE... 47 | --help print this help and exit 48 | --version print version information and exit 49 | -d, --data-relocs process data relocations 50 | -r, --function-relocs process data and function relocations 51 | -v, --verbose print all information 52 | Report bugs using the \`glibcbug' script to ." 53 | exit 0 54 | ;; 55 | -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \ 56 | --data-rel | --data-relo | --data-reloc | --data-relocs) 57 | warn=yes 58 | shift 59 | ;; 60 | -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \ 61 | --function | --function- | --function-r | --function-re | --function-rel | \ 62 | --function-relo | --function-reloc | --function-relocs) 63 | warn=yes 64 | bind_now=yes 65 | shift 66 | ;; 67 | -v | --verb | --verbo | --verbos | --verbose) 68 | verbose=yes 69 | shift 70 | ;; 71 | --v | --ve | --ver) 72 | echo >&2 $"ldd: option \`$1' is ambiguous" 73 | exit 1 74 | ;; 75 | --) # Stop option processing. 76 | shift; break 77 | ;; 78 | -*) 79 | echo >&2 'ldd:' $"unrecognized option" "\`$1'" 80 | echo >&2 $"Try \`ldd --help' for more information." 81 | exit 1 82 | ;; 83 | *) 84 | break 85 | ;; 86 | esac 87 | done 88 | 89 | nonelf () 90 | { 91 | # Maybe extra code for non-ELF binaries. 92 | return 1; 93 | } 94 | 95 | add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now" 96 | add_env="$add_env LD_VERBOSE=$verbose" 97 | case $# in 98 | 0) 99 | echo >&2 'ldd:' $"missing file arguments" 100 | echo >&2 $"Try \`ldd --help' for more information." 101 | exit 1 102 | ;; 103 | 1) 104 | single_file=t 105 | ;; 106 | *) 107 | single_file=f 108 | ;; 109 | esac 110 | 111 | result=0 112 | for file do 113 | # We don't list the file name when there is only one. 114 | test $single_file = t || echo "${file}:" 115 | case $file in 116 | */*) : 117 | ;; 118 | *) file=./$file 119 | ;; 120 | esac 121 | if test ! -f "$file"; then 122 | echo "ldd: ${file}:" $"No such file or directory" >&2 123 | result=1 124 | elif test -r "$file"; then 125 | test -x "$file" || echo 'ldd:' $"\ 126 | warning: you do not have execution permission for" "\`$file'" >&2 127 | RTLD= 128 | for rtld in ${RTLDLIST}; do 129 | if test -x $rtld; then 130 | verify_out=`${rtld} --verify "$file"` 131 | ret=$? 132 | case $ret in 133 | [02]) RTLD=${rtld}; break;; 134 | esac 135 | fi 136 | done 137 | if test -z "${RTLD}"; then 138 | set ${RTLDLIST} 139 | RTLD=$1 140 | verify_out=`${RTLD} --verify "$file"` 141 | ret=$? 142 | fi 143 | case $ret in 144 | 0) 145 | eval $add_env '"$file"' || result=1 146 | ;; 147 | 1) 148 | # This can be a non-ELF binary or no binary at all. 149 | nonelf "$file" || { 150 | echo $" not a dynamic executable" 151 | result=1 152 | } 153 | ;; 154 | 2) 155 | eval $add_env \${RTLD} '"$file"' || result=1 156 | ;; 157 | *) 158 | echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2 159 | exit 1 160 | ;; 161 | esac 162 | else 163 | echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2 164 | result=1 165 | fi 166 | done 167 | 168 | exit $result 169 | # Local Variables: 170 | # mode:ksh 171 | # End: 172 | -------------------------------------------------------------------------------- /colormake-vvtk.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # colormake.pl 0.3 4 | # 5 | # Copyright: (C) 1999, Bjarni R. Einarsson 6 | # http://bre.klaki.net/ 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation; either version 2 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | # 22 | 23 | # Some useful color codes, see end of file for more. 24 | # 25 | $col_ltgray = "\033[37m"; 26 | $col_purple = "\033[35m"; 27 | $col_green = "\033[32m"; 28 | $col_cyan = "\033[36m"; 29 | $col_enter= "\e[0;36m"; 30 | $col_leave = "\e[1;36m"; 31 | $col_brown = "\033[33m"; 32 | $col_red = "\033[31m"; 33 | $col_norm = "\033[00m"; 34 | $col_background = "\033[07m"; 35 | $col_brighten = "\033[01m"; 36 | $col_underline = "\033[04m"; 37 | $col_blink = "\033[05m"; 38 | 39 | # Customize colors here... 40 | # 41 | $col_default = $col_ltgray; 42 | #$col_gcc = $col_purple . $col_brighten; 43 | $col_make_enter = $col_enter; 44 | $col_make_leave = $col_leave; 45 | #$col_filename = $col_brown; 46 | #$col_linenum = $col_cyan; 47 | $col_trace = $col_brown; 48 | $col_warning = $col_green; 49 | #$tag_error = "Error: "; 50 | $col_error = $tag_error . $col_red . $col_brighten; 51 | #$error_highlight = $col_brighten; 52 | 53 | # Get size of terminal 54 | # 55 | $lines = shift @ARGV || 0; 56 | $cols = shift @ARGV || 0; 57 | $cols -= 19; 58 | 59 | $in = 'unknown'; 60 | while (<>) 61 | { 62 | $orgline = $thisline = $_; 63 | 64 | # Truncate lines. 65 | # I suppose this is bad, but it's better than what less does! 66 | if ($cols >= 0) 67 | { 68 | $thisline =~ s/^(.{$cols}).....*(.{15})$/$1 .. $2/; 69 | } 70 | 71 | # make[1]: Entering directory `/blah/blah/blah' 72 | #if ($thisline =~ s/^((p|g)?make\[)/$col_make$1/x) 73 | #{ 74 | # $in = 'make'; 75 | # } 76 | elsif ($thisline =~ s/^((g?cc|(g|c)\+\+).*)$/$col_gcc$1$col_norm/) 77 | { 78 | $in = 'gcc'; 79 | } 80 | elsif ($thisline =~ /^(\(|\[|a(r|wk)|c(p|d|h(mod|own))|do(ne)?|e(cho|lse)|f(ind|or)|i(f|nstall)|mv|perl|r(anlib|m(dir)?)|s(e(d|t)|trip)|tar|Compile)\s+/) 81 | { 82 | $in = $1; 83 | } 84 | elsif ($thisline =~ /^((p|g)?make\[.*Entering directory)/) 85 | { 86 | $thisline =~ s/^((p|g)?make\[)/$col_make_enter$1/x; 87 | } 88 | elsif ($thisline =~ /^((p|g)?make\[.*Leaving directory)/) 89 | { 90 | $thisline =~ s/^((p|g)?make\[)/$col_make_leave$1/x; 91 | } 92 | elsif ($thisline =~ /warning:/) 93 | { 94 | #$thisline =~ s|(warning:\s+)(.*)$|$1$col_warning$2|; 95 | $thisline =~ s|(\s+)(.*)$|$1$col_warning$2|; 96 | } 97 | elsif ($thisline =~ /WARNING:/) 98 | { 99 | $thisline =~ s|(\s+)(.*)$|$1$col_brown$2|; 100 | } 101 | elsif ($thisline =~ /error:/) 102 | { 103 | $thisline =~ s/(\d+:\s+)/$1$col_default$col_error/; 104 | $thisline = $error_highlight . $thisline . $col_norm; 105 | } 106 | elsif ($thisline =~ /undefined /) 107 | { 108 | $thisline =~ s/(\d+:\s+)/$1$col_default$col_error/; 109 | $thisline = $error_highlight . $thisline . $col_norm; 110 | } 111 | # elsif ($in eq 'gcc' or $in eq 'Compile') 112 | # { 113 | # # Do interesting things if make is compiling something. 114 | # 115 | # #if (($thisline !~ /[,:]$/) && ($thisline !~ /warning/)) 116 | # 117 | # if ($thisline =~ /error/) 118 | # { 119 | # # error? 120 | # if ($cols >= 0) 121 | # { 122 | # # Retruncate line, because we are about to insert "Error:". 123 | # my $c = $cols - length($tag_error); 124 | # $thisline = $orgline; 125 | # $thisline =~ s/^(.{$c}).....*(.{15})$/$1 .. $2/; 126 | # } 127 | # $thisline =~ s/(\d+:\s+)/$1$col_default$col_error/; 128 | # $thisline = $error_highlight . $thisline . $col_norm; 129 | # } 130 | # elsif ($thisline =~ /warning/) 131 | # { 132 | # # warning 133 | # $thisline =~ s|(warning:\s+)(.*)$|$1$col_warning$2|; 134 | # } 135 | # 136 | # # In file included from main.cpp:38: 137 | # # main.cpp: In function int main(...)': 138 | # $thisline =~ s/(In f(unction|ile))/$col_trace$1/x; 139 | # 140 | # # /blah/blah/blah.cpp:123: 141 | # $thisline =~ s|^([^:]+)|$col_filename$1$col_default|; 142 | # $thisline =~ s|:(\d+)([:,])|:$col_linenum$1$col_default$2|; 143 | # } 144 | 145 | if ($thisline !~ /^\s+/) 146 | { 147 | print $col_norm, $col_default; 148 | } 149 | print $thisline; 150 | } 151 | 152 | print $col_norm; 153 | 154 | # UNUSED: 155 | # 156 | #%colors = ( 157 | # 'black' => "\033[30m", 158 | # 'red' => "\033[31m", 159 | # 'green' => "\033[32m", 160 | # 'yellow' => "\033[33m", 161 | # 'blue' => "\033[34m", 162 | # 'magenta' => "\033[35m", 163 | # 'purple' => "\033[35m", 164 | # 'cyan' => "\033[36m", 165 | # 'white' => "\033[37m", 166 | # 'darkgray' => "\033[30m"); 167 | 168 | -------------------------------------------------------------------------------- /.bashrc_bb_u: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This .bashrc_bb is useful for busybox environment 3 | 4 | BASHRC_FILENAME="/tmp/.bashrc_bb_u" 5 | 6 | ####################### 7 | # Alias # 8 | ####################### 9 | 10 | alias ll='ls -al' # long list format 11 | alias lk='ls -lk' # --block-size=1K 12 | alias lt='ls -ltr' # sort by date (mtime) 13 | alias lc='ls -ltcr' # sort by and show change time 14 | alias la='ls -ltur' # sort by and show access time 15 | alias lx='ls -lX' # sort by extension 16 | alias lz='ls -lSr' # sort by size 17 | alias ld='ls -d */' # es only Dirs 18 | alias l.='ls -dAFh .[^.]*' # ls only Dotfiles 19 | alias lst='ls -hFtal | grep $(date +%Y-%m-%d)' #ls Today 20 | 21 | alias ..='cd ..' 22 | alias ...='cd ../..' 23 | alias ....='cd ../../..' 24 | alias .....='cd ../../../..' 25 | alias ......='cd ../../../../..' 26 | 27 | alias b='cd -' 28 | alias cd..='cd ..' 29 | alias path='echo -e ${PATH//:/\\n}' 30 | 31 | # netstat -npl 32 | alias netstat='netstat -np' 33 | 34 | # UBNT only 35 | alias save='ubnt_cmd_persist.sh' 36 | alias savecfg='cfgmtd -w -f /tmp/system.cfg' 37 | 38 | ####################### 39 | # Env var # 40 | ####################### 41 | 42 | grep "feature_wifi=1" /etc/board.info > /dev/null 2>&1 43 | interface=$([ $? -eq 0 ] && echo wlan0 || echo eth0) 44 | 45 | IP_HERE=$(ifconfig $interface | sed -n -e 's/:127\.0\.0\.1 //g' -e 's/ *inet addr:\([0-9.]\+\).*/\1/gp') 46 | 47 | ####################### 48 | # Functions # 49 | ####################### 50 | 51 | # ls when cd, it's useful 52 | cd () 53 | { 54 | if [ -n "$1" ]; then 55 | chdir "$@"&& ls 56 | else 57 | chdir ~&& ls 58 | fi 59 | } 60 | 61 | fe () 62 | { 63 | find . -iname '*'${1:-}'*' -exec ${2:-ls} {} \; 64 | } 65 | 66 | wg () 67 | { 68 | grep -ri "$1" * 69 | } 70 | 71 | mt () 72 | { 73 | if [ $# -ne 1 ]; then 74 | echo "Usage: mt /path/to/folder" 75 | return 0 76 | fi 77 | 78 | RWDIR=$1 79 | TMPDIR=`mktemp -d -p /tmp/` 80 | cp -a $RWDIR/* $TMPDIR 81 | mount -o bind $TMPDIR $RWDIR 82 | } 83 | 84 | dbgtools () 85 | { 86 | if [ $# -ne 1 ]; then 87 | echo "Usage: dbgtools [2|3|4]" 88 | return 0 89 | fi 90 | 91 | local GEN=$1 92 | local DBG_DIR=/tmp/dbgtools 93 | 94 | mkdir -p $DBG_DIR 95 | for tool in busybox strace gdb lsof libreadline.so.6 libncurses.so.5 librpc.so; do 96 | wget http://$DEV_SERVER:8888/gen$GEN/$tool -P $DBG_DIR 97 | chmod +x $DBG_DIR/$tool 98 | done 99 | export PATH=$DBG_DIR:$PATH 100 | export LD_LIBRARY_PATH=/tmp/dbgtools/ 101 | 102 | # Creating busybox symlinks 103 | mkdir $DBG_DIR/bin_bb; cd $DBG_DIR/bin_bb 104 | busybox --help | busybox grep 'Currently defined functions:' -A300 \ 105 | | busybox grep -v 'Currently defined functions:' \ 106 | | busybox tr , '\n' \ 107 | | busybox xargs -n1 busybox ln -sf ../busybox 108 | export PATH=`pwd`:$PATH 109 | cd - 110 | 111 | # Fancy colorful prompt support 112 | mv /etc/profile /etc/profile.ori 113 | cp $BASHRC_FILENAME /etc/profile 114 | busybox ash -l 115 | } 116 | 117 | mtubifs () 118 | { 119 | mknod /dev/ubi_ctrl c 10 63 120 | ubiattach /dev/ubi_ctrl -O 2048 -m 9 121 | 122 | ubimkvol /dev/ubi1 -N spare0 -s 50MiB && mkfs.ubifs /dev/ubi1_0 -x none 123 | ubimkvol /dev/ubi1 -N spare1 -s 50MiB && mkfs.ubifs /dev/ubi1_1 -x lzo 124 | 125 | ubinfo -a 126 | 127 | mkdir -p /tmp/ubi_spare0 /tmp/ubi_spare1 128 | mount -t ubifs ubi1:spare0 /tmp/ubi_spare0 129 | mount -t ubifs ubi1:spare1 /tmp/ubi_spare1 130 | } 131 | 132 | runtmux () 133 | { 134 | type "stty" &> /dev/null 135 | if [ 0 -eq $? ]; then 136 | # Resizing a terminal 137 | # Unlike ssh, serial connection doesn't have a mechanism to transfer something like SIGWINCH when a terminal is resized. 138 | # This will cause odd problem with some programs (e.g. less). Resize the terminal via `stty` is a workaround 139 | 140 | # Try to get below corresponding COLUMNS/LINES value by `resize` shell command 141 | COLUMNS=177; LINES=47; 142 | 143 | # serial/uart will get "0(rows) 0(cols)" on running ttysize 144 | [ "`ttysize`" = "0 0" ] && stty cols $COLUMNS rows $LINES 145 | 146 | TERM=xterm tmux -2 -f .tmux_uart.conf 147 | else 148 | echo "Please run dbgtools [2|3] first" 149 | fi 150 | } 151 | 152 | helpme () 153 | { 154 | echo "==================================" 155 | echo "Functions:" 156 | grep " ()$" $BASHRC_FILENAME | tr '\r\n' ' ' 157 | echo "" 158 | echo "==================================" 159 | echo "Alias:" 160 | alias | sort 161 | echo "==================================" 162 | } 163 | 164 | ####################### 165 | # Sysinfo # 166 | ####################### 167 | 168 | echo "==================================" 169 | uname -mnrs 170 | echo "==================================" 171 | uptime 172 | echo "==================================" 173 | cat /etc/board.info |grep board 174 | echo "==================================" 175 | echo "Welcome to $IP_HERE, $FROM_ID " 176 | echo "==================================" 177 | echo "Usage: helpme()" 178 | echo "==================================" 179 | 180 | ####################### 181 | # IP Camera # 182 | ####################### 183 | IP_HERE_SHORT=${IP_HERE#10.2.} 184 | FW_VER=`cat /lib/version` 185 | FW_VER_SHORT=`echo $FW_VER | sed 's/\(.*\)\.v\(.*\)/v\2/'` 186 | MODELNAME=`sed -n "/board.name=\(.*\)/{s//\1/p;q}" /etc/board.info` 187 | 188 | cat /lib/version | grep debug 189 | if [ $? -eq 0 ]; then 190 | # Colorful PS1 191 | TXTGRN="\[\033[0;32m\]" 192 | TXTPUR="\[\033[0;35m\]" 193 | TXTRST="\[\033[0m\]" 194 | PS1=${TXTGRN}"[${MODELNAME}.${FW_VER_SHORT}]"${TXTRST}'@'${TXTPUR}${IP_HERE}${TXTRST}':\w \$ ' 195 | else 196 | PS1=[${MODELNAME}.${FW_VER_SHORT}]'@'${IP_HERE}' # ' 197 | fi 198 | 199 | DEV_SERVER="10.2.2.15" 200 | alias mount-home="mkdir /home; mount -t nfs -o tcp,nolock $DEV_SERVER:/home /home" 201 | alias mount-rw="mount -t ubifs -o rw,remount ubi0:rootfs /" 202 | 203 | -------------------------------------------------------------------------------- /tmux-bootstrap-myproject.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ########### 4 | # General # 5 | ########### 6 | 7 | # Setup some variables needed for bootstrapping the environment 8 | ROOT=$HOME/Project 9 | 10 | ########## 11 | # S:Main # 12 | ########## 13 | 14 | # Bootstrap a new session called "Main" 15 | tmux new-session -d -s Main 16 | 17 | # Rename the first window (using the session-name:id notation) 18 | tmux rename-window -t Main:1 "dev" 19 | tmux new-window -t Main:2 -n "gen2" 20 | tmux new-window -t Main:3 -n "gen3l" 21 | tmux new-window -t Main:4 -n "gen3m" 22 | tmux new-window -t Main:5 -n "gen4l" 23 | tmux new-window -t Main:6 -n "gen4c" 24 | tmux new-window -t Main:7 -n "gen3s" 25 | tmux new-window -t Main:8 -n "owrt" 26 | tmux new-window -t Main:9 -n "vvtk" 27 | tmux new-window -t Main:10 -n "avahi" 28 | tmux new-window -t Main:11 -n "mbpr" 29 | tmux new-window -t Main:12 -n "nvr" 30 | tmux new-window -t Main:13 -n "amba-bsp" 31 | tmux split-window -v -t Main:13 32 | tmux new-window -t Main:14 -n "mcu" 33 | tmux new-window -t Main:15 -n "go" 34 | tmux new-window -t Main:16 -n "ufp" 35 | tmux new-window -t Main:17 -n "eot" 36 | tmux split-window -v -t Main:17 37 | 38 | # Send commands to the windows, use "C-m" to emulate "enter" 39 | 40 | tmux send-keys -t Main:1 "cd ${ROOT}/unifi-video-firmware/; source ubnt-devel-aircam" C-m 41 | tmux send-keys -t Main:2 "cd ${ROOT}/unifi-video-firmware-gen2/; source ubnt-devel-aircam" C-m 42 | tmux send-keys -t Main:3 "cd ${ROOT}/unifi-video-firmware-gen3l/; source ubnt-devel-aircam" C-m 43 | tmux send-keys -t Main:4 "cd ${ROOT}/unifi-video-firmware-gen3m/; source ubnt-devel-aircam" C-m 44 | tmux send-keys -t Main:5 "cd ${ROOT}/unifi-video-firmware-gen4/; source ubnt-devel-aircam" C-m 45 | tmux send-keys -t Main:6 "cd ${ROOT}/unifi-video-firmware-gen4c/; source ubnt-devel-aircam" C-m 46 | tmux send-keys -t Main:7 "cd ${ROOT}/unifi-video-firmware-gen3s/; source ubnt-devel-aircam" C-m 47 | tmux send-keys -t Main:8 "cd ${ROOT}/OpenWrt" C-m 48 | tmux send-keys -t Main:9 "cd ${ROOT}/VVTK" C-m 49 | tmux send-keys -t Main:10 "avahi-browse-domains -a -v -r" C-m 50 | tmux send-keys -t Main:11 "ssh kent-mbpr16-ubnt.local" C-m 51 | tmux send-keys -t Main:12 "cd ${ROOT}/unifi-video; ant -projecthelp" C-m 52 | tmux send-keys -t Main:13.top "cd ${ROOT}/BSP/amba-s2lm; source ./ambarella/build/env/Linaro-multilib-gcc4.9.env" C-m 53 | tmux send-keys -t Main:13.bottom "cd ${ROOT}/BSP/amba-s5lm; source ./ambarella/build/env/aarch64-linaro-gcc.env" C-m 54 | tmux send-keys -t Main:14 "cd ${ROOT}/unicam-mcu-firmware" C-m 55 | tmux send-keys -t Main:15 "cd $GOPATH/src/github.com/ubiquiti/uvcbox/" C-m 56 | tmux send-keys -t Main:16 "cd ~/project/unifi-protect" C-m 57 | tmux send-keys -t Main:17.top "cd ~/project/protect-eot-firmware; source ubnt-devel-eot_sfl" C-m 58 | tmux send-keys -t Main:17.bottom "cd ~/project/protect-eot-firmware-radar; source ubnt-devel-eot_radar" C-m 59 | 60 | # Switch to window 1 61 | tmux select-window -t Main:1 62 | 63 | ############ 64 | # S:Tunnel # 65 | ############ 66 | tmux new-session -d -s Tunnel 67 | 68 | tmux rename-window -t Tunnel:1 "ddwrt" 69 | tmux new-window -t Tunnel:2 70 | tmux split-window -v -t Tunnel:2 71 | tmux new-window -t Tunnel:3 -n "hfs" 72 | tmux new-window -t Tunnel:4 -n "dropbox" 73 | tmux new-window -t Tunnel:5 -n "iperf" 74 | tmux split-window -h -t Tunnel:5 75 | tmux new-window -t Tunnel:6 76 | tmux split-window -v -t Tunnel:6 77 | tmux new-window -t Tunnel:7 -n "ddwrt-tunnel" 78 | tmux new-window -t Tunnel:8 -n "sshuttle" 79 | tmux split-window -v -t Tunnel:8 80 | 81 | tmux send-keys -t Tunnel:1 'cd $TOOLS; ./test.expect' C-m 82 | tmux send-keys -t Tunnel:2.top "watch ccache -s" C-m 83 | tmux send-keys -t Tunnel:2.top "sudo atop" C-m 84 | tmux send-keys -t Tunnel:2.bottom "htop -d 10" C-m 85 | #tmux send-keys -t Tunnel:3 "cd ${HOME}/ArmTools/UVC; ./SimpleHTTPServerWithUpload.py 8888" C-m 86 | tmux send-keys -t Tunnel:3 "cd ${HOME}/ArmTools/UVC; gohttpserver -r ./ --port 8888 --upload" C-m 87 | #tmux send-keys -t Tunnel:4 "dropboxd.py start" C-m 88 | tmux send-keys -t Tunnel:5.left "iperf -s -i1 -m -fk" C-m 89 | tmux send-keys -t Tunnel:5.right "iperf3 -s -i1" C-m 90 | tmux send-keys -t Tunnel:6.top "dstat -cdlmnpsy --top-cpu --top-bio --top-mem --top-latency" C-m 91 | tmux send-keys -t Tunnel:6.bottom "sudo atop" C-m 92 | #tmux send-keys -t Tunnel:7 'cd $TOOLS; ./test2.expect' C-m 93 | tmux send-keys -t Tunnel:8.top 'sshuttle -r root@10.2.0.152 192.168.1.0/24 -v' C-m 94 | tmux send-keys -t Tunnel:8.bottom 'sshuttle -r root@10.2.1.123 192.168.6.0/24 -v' C-m 95 | 96 | # Switch to window 1 97 | tmux select-window -t Tunnel:1 98 | 99 | ######### 100 | # S:SSH # 101 | ######### 102 | tmux new-session -d -s SSH 103 | 104 | tmux rename-window -t SSH:1 "ttyUSB0" 105 | tmux new-window -t SSH:2 -n "ttyUSB1" 106 | tmux new-window -t SSH:3 -n "ttyUSB2" 107 | tmux new-window -t SSH:4 -n "PowerEdge" 108 | tmux new-window -t SSH:5 -n "uck+" 109 | tmux new-window -t SSH:6 110 | 111 | #tmux send-keys -t SSH:1 "miniterm.py --eol CR --raw /dev/ttyUSB0 9600" C-m 112 | tmux send-keys -t SSH:1 "miniterm.py --eol LF --raw /dev/ttyUSB0 115200" C-m 113 | tmux send-keys -t SSH:2 "miniterm.py --eol LF --raw /dev/ttyUSB1 115200" C-m 114 | tmux send-keys -t SSH:3 "miniterm.py --eol LF --raw /dev/ttyUSB2 115200" C-m 115 | tmux send-keys -t SSH:4 "ssh unifivideo@10.2.0.125" C-m 116 | tmux send-keys -t SSH:5 "ssh ufv4-ckplus" C-m 117 | 118 | # Switch to window 1 119 | tmux select-window -t SSH:1 120 | 121 | ######### 122 | # Final # 123 | ######### 124 | 125 | # Force tmux to assume the terminal supports 256 colors and attach to the target session "Main" 126 | tmux -2 attach-session -t Main 127 | 128 | -------------------------------------------------------------------------------- /ydict_: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # Shih-Yuan Lee 3 | # http://fd.idv.tw 4 | 5 | use Term::ANSIColor qw(:constants); 6 | use LWP::Simple; 7 | use strict; 8 | use warnings; 9 | use Encode; 10 | 11 | my $debug = 0; 12 | my $trigger = 0; 13 | 14 | if ($#ARGV == -1) { 15 | print " "; 16 | while (<>) { 17 | chomp; 18 | if ("$_" eq '') { 19 | print " "; 20 | next; 21 | } 22 | ydict($_); 23 | print " "; 24 | } 25 | } else { 26 | while ($#ARGV != -1) { 27 | if ($trigger) { 28 | print "\n"; 29 | } else { 30 | $trigger = 1; 31 | } 32 | ydict(shift); 33 | } 34 | } 35 | 36 | sub ydict 37 | { 38 | my $p = shift; 39 | die if !$p; 40 | my $html = get("http://tw.dictionary.yahoo.com/search?ei=UTF-8&p=$p"); 41 | $html =~ s/\r//g; 42 | $html =~ s/\n//g; 43 | 44 | if ($html =~ m{}) { 45 | if ($html =~ m{.*?>(\S+)<.*?}) { 46 | my $q = $1; 47 | print BOLD . YELLOW . "拼字檢查: $p -> $q" . RESET . "\n\n"; 48 | return ydict($q); 49 | } else { 50 | print BOLD . YELLOW . "查無此字: $p\n" . RESET; 51 | return; 52 | } 53 | } 54 | 55 | print BOLD . YELLOW . "$p 的查詢結果:" . RESET . "\n\n"; 56 | 57 | while ($html =~ m{
}) { 58 | my $block = $`; 59 | $html = $'; 60 | parser($block); 61 | } 62 | parser($html); 63 | } 64 | 65 | sub parser 66 | { 67 | my $html = shift; 68 | if ($html =~ m{

(.*?)

}) { 69 | my $line = $1; 70 | $line =~ s,,[,g; 71 | $line =~ s,,],g; 72 | $line =~ s/<[^>]+>//g; 73 | $line =~ s/^\s+//; 74 | $line =~ s/\s+$//; 75 | print "

" if $debug; 76 | print BOLD."$line".RESET."\n"; 77 | } 78 | parsermore($html); 79 | } 80 | 81 | sub parsermore 82 | { 83 | my $i = 0; 84 | my $flag = 0; 85 | my $html = shift; 86 | # http://tw.dictionary.yahoo.com/search?ei=UTF-8&p=$p 87 | while ($html =~ m{
(.*?)
}i) 88 | { 89 | my $type = $1; 90 | my $line = $2; 91 | my $color = RESET; 92 | my $bold = BOLD; 93 | my $reset = RESET; 94 | $html = $'; 95 | $line =~ s/^\s+//; 96 | $line =~ s/\s+$//; 97 | print "type=$type\nline=$line\n" if $debug; 98 | if ($type eq 'pcixin') 99 | { 100 | $flag = 0; 101 | $i = 0; 102 | $color = BOLD . RED; 103 | next if not ($line); 104 | print "\n" if $debug; 105 | } 106 | elsif ($type eq 'pchi') 107 | { 108 | $color = GREEN; 109 | $reset = RESET.$color; 110 | $line = " $line"; 111 | print "\n" if $debug; 112 | } 113 | elsif ($type eq 'peng') 114 | { 115 | $color = CYAN; 116 | $reset = RESET.$color; 117 | $line = " $line"; 118 | print "\n" if $debug; 119 | } 120 | elsif ($type eq 'chinese') 121 | { 122 | my $num = $line =~ s/
/\n /g; 123 | $line = " $line"; 124 | print "\n" if $debug; 125 | } 126 | elsif ($type eq 'pexplain') 127 | { 128 | if ($flag == 0) { 129 | $i++; 130 | if ($line =~ m{
  • }) { 131 | my $reval; 132 | do { 133 | $reval = $line =~ s/
  • / $i. /; 134 | $i++; 135 | } while ($reval); 136 | my $num = $line =~ s/
    /\n/g; 137 | $i = 0; 138 | } else { 139 | $line = " $i. $line"; 140 | print "\n" if $debug; 141 | } 142 | } else { 143 | $line = " $line" if ($line); 144 | print "\n" if $debug; 145 | } 146 | } 147 | elsif ($type eq 'chinese-explain pexplain') 148 | { 149 | if ($flag == 0) { 150 | $i++; 151 | if ($line =~ m{
  • }) { 152 | my $reval; 153 | do { 154 | $reval = $line =~ s/
  • /\n $i. /; 155 | $i++; 156 | } while ($reval); 157 | my $num = $line =~ s/
    /\n/g; 158 | $i = 0; 159 | } else { 160 | $line = " $i. $line"; 161 | print "\n" if $debug; 162 | } 163 | } else { 164 | $line = " $line" if ($line); 165 | print "\n" if $debug; 166 | } 167 | } 168 | elsif ($type eq 'ptitle') 169 | { 170 | $flag = 1; 171 | $color = BOLD . BLUE; 172 | # next if ($line =~ m{KK} && $line =~ m{DJ}); 173 | 174 | my $dir = 'http://tw.yimg.com/i/tw/dictionary/pic'; 175 | my $map = Encode::decode('utf8', " æa: ɑ ʊɔɝəɚʌeɛŋ ʃʒ θð iɪuopbtdkfvszmnhlrwj`,g ḷṃṇ"); 176 | 177 | $line =~ s/\s+(DJ)/\n$1/g; 178 | 179 | while ($line =~ m{]*['"]$dir/0+(\d+)\.gif['"][^>]*>}ig) { 180 | my $char = Encode::encode('utf8', substr($map, $1, 1)); 181 | my $fname = $1 < 10 ? "00$1" : $1 < 100 ? "0$1" : $1; 182 | $line =~ s!]*['"]$dir/$fname\.gif["'][^>]*>!$char!ig; 183 | } 184 | 185 | print "\n" if $debug; 186 | } 187 | else 188 | { 189 | $color = BOLD . BLUE; 190 | print "\n" if $debug; 191 | next; 192 | } 193 | $line =~ s,,$bold,g; 194 | $line =~ s,,$reset,g; 195 | $line =~ s,,[,g; 196 | $line =~ s,,],g; 197 | $line =~ s/<[^>]+>//g; 198 | print $color."$line".RESET."\n"; 199 | } 200 | } 201 | 202 | -------------------------------------------------------------------------------- /valgrind-run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # --------------------------------------------------------------------------- 3 | # valgrind-run.sh - easy wrapper for running valgrind with common arguments. 4 | # Copyright (c) 2007-2009, Jeff Hung 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # - Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # - Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # - Neither the name of the copyright holders nor the names of its 17 | # contributors may be used to endorse or promote products derived 18 | # from this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | # ---------------------------------------------------------------------------- 32 | 33 | __exe_name__=`basename $0`; 34 | __revision__=`echo '$Rev: 470 $' | cut -d' ' -f2`; 35 | __rev_date__=`echo '$Date: 2009-05-09 01:32:22 +0800 (Sat, 09 May 2009) $' | cut -d' ' -f2`; 36 | 37 | usage() 38 | { 39 | echo >&2 "\ 40 | Usage: $__exe_name__ [