From: Nicolas Boisselier Date: Mon, 17 Nov 2014 21:09:47 +0000 (+0100) Subject: bin + etc X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=a45b44b95340d36be4587b3f051d0f62a7122002;p=nb.git bin + etc --- diff --git a/bin/nb-install b/bin/nb-install new file mode 100755 index 00000000..ff5dea78 --- /dev/null +++ b/bin/nb-install @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +declare -r NAME="$(basename "${0}")" +declare -r NB_ROOT="$(readlink -f $(dirname $0)/../)" + +# +# Cron +# +rsync -au --force etc/cron/nb /etc/cron.d/nb + +# +# Profile +# +echo "[ -x $NB_ROOT/etc/profile.sh ] && . $ROOT/etc/profile.sh" > /tmp/nb-profile.sh \ + && rsync -c -au --force /tmp/nb-profile.sh /etc/profile.d/nb-profile.sh \ + && chmod 755 /etc/profile.d/nb-profile.sh \ +; + +rm -f /tmp/nb-profile.sh diff --git a/bin/nb-update b/bin/nb-update index b8fd8169..8256db8c 100755 --- a/bin/nb-update +++ b/bin/nb-update @@ -1,15 +1,12 @@ #!/usr/bin/env bash declare -r NAME="$(basename "${0}")" -declare -r ROOT="$(readlink -f $(dirname $0)/../)" +declare -r NB_ROOT="$(readlink -f $(dirname $0)/../)" ##################################################################### # Git pull # -cd $ROOT || exit +cd $NB_ROOT || exit git pull -##################################################################### -# Cron -# -rsync -au --force etc/cron/nb /etc/cron.d/nb +nb-install diff --git a/etc/bashrc b/etc/bashrc index d2cd0abf..02418d10 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -1,8 +1,8 @@ -##################################################################### +################################################################################# # # FUNCTIONS # -##################################################################### +################################################################################# git-commit-push() { git commit -m "$@" -a git push @@ -25,18 +25,22 @@ env-add-path() { echo "$env_value" } -##################################################################### +################################################################################# # # VARS # -##################################################################### -declare -r ROOT="$(readlink -f $(dirname $0)/../)" +################################################################################# +declare -r NB_ROOT="$(readlink -f $(dirname $0)/../)" +[ -z "$HOSTNAME" ] && HOSTNAME=`hostname` +[ -z "$UID" ] && UID=`id -u` +[ -z "$USER" ] && USER=`whoami` +[ -z "$HOME" ] && HOME=`readlink -f ~/` -##################################################################### +################################################################################# # # ENV # -##################################################################### +################################################################################# # # PATH @@ -50,9 +54,238 @@ PATH=`env-add-path "$PATH" \ /opt/local/sbin \ /usr/local/bin \ /usr/local/sbin \ - $ROOT/bin \ - $ROOT/sbin \ + $NB_ROOT/bin \ + $NB_ROOT/sbin \ $HOME/bin \ $HOME/sbin \ + /usr/share/awstats/tools \ + /home/bin \ + /home/www/wp/bin \ ` export PATH + +# +# OTHERS +# + +export IGNOREEOF=0 +export LESS="-iMR" +export EDITOR=vim + +# +# Color / PS1 +# +declare color_prompt color char +case "$TERM" in + xterm-color) color_prompt=yes;; + *screen*) color_prompt=yes;; + linux) color_prompt=yes;; +esac + +case `hostname -s|tr A-Z a-z` in + pi*) color=31 ;; + *.ovh.net) color=33 ;; + *.kimsufi.com) color=33 ;; + *.ip-*.eu) color=33 ;; + Nicolas-Boisselier-MacBook*) h="macbook" + color=35 + ;; + MacMini*) color=35 ;; + *) color=36 ;; +esac + +char='$'; [ $UID == "0" ] && char='#' +if [ "$color_prompt" = yes ]; then + PS1="\[\033[01;${color}m\]\u@$h:\[\033[00m\]\W${char} " +else + PS1="\u@\h:\W${char} " +fi +unset color char + +################################################################################# +# +# Aliases +# +################################################################################# + +#-------------------------------------------------------------------------------- +# Others +# +alias uuid-hds='blkid -o full -s UUID' +alias myip='lynx --dump --source http://www.ipchicken.com/ | sed -ne "s/^.*[^0-9]\(\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*$/\1/p"' +alias dpkg-sort-size="dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1nr" +alias password-gener='apg -m 12 -x 12 -a 0 -M L|head -1;' +alias mysqlshow-view="mysql -e \"SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'VIEW'\"" +alias nmap-ping="nmap -sP -PE -PS443 -PA21,22,23,80,3389" +alias arp-list="arp -an" + +#-------------------------------------------------------------------------------- +# ls +# +ls_opt='-a' +case "$OSTYPE" in + darwin*) + [ "$color_prompt" = yes ] && ls_opt="$ls_opt -G" + ;; + *) + ls_opt="$ls_opt --time-style=long-iso" + [ "$color_prompt" = yes ] && ls_opt="$ls_opt --color=auto" + ;; +esac +[ "$ls_opt" == "" ] || alias ls="ls $ls_opt" +unset ls_opt +alias ll='ls -lh' +unset color_prompt + +#-------------------------------------------------------------------------------- +# Etherwake +# Cable: alias advent-on="etherwake -i eth0 00:22:68:7b:fb:99 -D -b" +# +#which etherwake &> /dev/null && alias advent-on="etherwake -i eth0 48:5b:39:eb:db:8a -D -b" + +#-------------------------------------------------------------------------------- +# seq / jot +# +case "$OSTYPE" in + darwin*) alias seq='jot' ;; + *) alias jot='seq' ;; +esac + +#-------------------------------------------------------------------------------- +# Beep +# +alias beep='printf "\a"' + +#-------------------------------------------------------------------------------- +# Mac iTerm.app +# +test "$TERM_PROGRAM" = "iTerm.app" && export PROMPT_COMMAND='printf "\033]0;%s\007" "${USER}@${HOSTNAME%%.*}"' + +#-------------------------------------------------------------------------------- +# Get / Head +# +alias Head="lynx -dump -head -width=1000" +alias Get="lynx -source -width=1000" + +#-------------------------------------------------------------------------------- +# bc +# +alias bc="bc -q" + +#-------------------------------------------------------------------------------- +# iconv +# +alias latin1_utf8='iconv -f latin1 -t utf8' +alias utf8_latin1='iconv -f utf8 -t latin1' + +#-------------------------------------------------------------------------------- +# vim +# +alias vi=vim + +#-------------------------------------------------------------------------------- +# xterm +# +[ -z /usr/bin/xterm ] && alias xterm="xterm -bg black -fg gray -fn 10x20" + +#-------------------------------------------------------------------------------- +# Torrent +# +opt="--max_upload_rate 1 --minport 6881 --maxport 6999" +if which btlaunchmanycurses.py &> /dev/null; then + + opt="$opt --max_download_rate 150 --max_files_open 0" + + alias torrent="btdownloadcurses.py $opt" + + alias torrentdir="btlaunchmanycurses.py $opt" + +elif which btdownloadcurses &> /dev/null; then + + alias torrent="btdownloadcurses $opt" + alias torrentdir="btlaunchmanycurses $opt" + +fi +unset opt + +#-------------------------------------------------------------------------------- +# debian upgrade +# +alias servers-upgrade='server-package.pl update,upgrade $(printf "localhost\nbig\n";mysql -h mysql izi -NBe "select host from server where not hidden")' + +#-------------------------------------------------------------------------------- +# Screen +# +#alias "screen-ssh"="screen -Rd" + +#-------------------------------------------------------------------------------- +# Mac OS +# + +case "$OSTYPE" in +darwin*) + +alias strace='dtruss' +alias updatedb='bash -c "cd / && /usr/libexec/locate.updatedb &"' +alias mac-dns-flush='dscacheutil -flushcache' +#alias mac-wakeup-screen="pmset schedule wake '\$(date +\"%d/%m/%Y %T\")'" +#alias mac-wakeup-screen2='osascript -e \'tell application "System Events" to key code 123\'' +alias mac-sleep='pmset sleepnow' +alias mac-halt='halt=1 && bash -c "(sleep 3 && halt) &" && logout' +alias mac-top-proc="echo 'TOP PROCESSES:'; ps -Aro'%cpu, ucomm, user' | grep $USER | grep -v ' 0.0 '" +alias mac-automount='sudo automount -v' +alias mac-vlc-playlists="open -a vlc --args /home/nico/Music/*/*.m3u" +# NB 25.02.14 alias hibernate='sudo pmset -a hibernatemode 25' +# NB 25.02.14 alias sleep='sudo pmset -a hibernatemode 0' +# NB 25.02.14 alias safesleep='sudo pmset -a hibernatemode 3' +# NB 25.02.14 alias smartsleep='sudo pmset -a hibernatemode 2' +mac_xmessagei() { + osascript -e 'tell app "System Events" to display dialog "'$@'"' +} + +mac_config() { + echo "Finder path : YES" + defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES + echo "Finder quit : YES" + defaults write com.apple.finder QuitMenuItem -bool YES + echo "Finder show all files : FALSE" + defaults write com.apple.finder AppleShowAllFiles FALSE +} +;; +esac + +################################################################################# +# +# Functions +# +################################################################################# +ascii() { + perl -e 'binmode(STDOUT, ":utf8"); for(32..255){ print "$_:".chr($_)."\n"; }' +} + +psmem() { + #ps -C $1 -O rss | xargs -r cat | gawk '\ + #ps -p `pgrep -f $1` -O rss 2>/dev/null| xargs -r | gawk '\ + ps=`ps ax -O rss 2>/dev/null` + echo "$ps"| awk "\ +BEGIN { count = 0; sum= 0; } +/^ *[0-9]+/ && /$1/ { count ++; sum += \$2 } +END { + print \"Number of processes =\",count; + if (count < 1) { count = 1 } + print \"Memory usage per process =\",sum/1024/count, \"MB\"; + print \"Total memory usage =\", sum/1024, \"MB\"; +} +" + return +} + +unzipurl() { + declare url=$1 + #declare file=`echo "$url"|sed 's,^.*?\([^/]+\.zip\)$,\1,'` + declare file=`echo "$url"|awk -F/ '/\.zip$/ { print $NF }'` + [ -z "$file" ] && file="$FUNCNAME.zip" + #echo "$url -> $file" + wget "$url" -O "$file" && unzip "$file" + rm "$file" +} diff --git a/etc/profile.sh b/etc/profile.sh new file mode 100644 index 00000000..6286e163 --- /dev/null +++ b/etc/profile.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +declare -r NB_ROOT="$(readlink -f $(dirname $0)/../)" +[ -r "$NB_ROOT/etc/bashrc" ] && . "$NB_ROOT/etc/bashrc"