Ajout : rule_user_configure : bash, screen, etckeeper .
authorJulien Moutinho <julm+burette@autogeree.net>
Fri, 22 Feb 2013 19:00:01 +0000 (20:00 +0100)
committerJulien Moutinho <julm+burette@autogeree.net>
Mon, 25 Feb 2013 22:36:00 +0000 (23:36 +0100)
etc/bash.bashrc [new file with mode: 0644]
etc/etckeeper/prompt.sh [new file with mode: 0644]
etc/screenrc [new file with mode: 0644]
vm_hosted

diff --git a/etc/bash.bashrc b/etc/bash.bashrc
new file mode 100644 (file)
index 0000000..ae5f5b1
--- /dev/null
@@ -0,0 +1,126 @@
+# System-wide .bashrc file for interactive bash(1) shells.
+
+# To enable the settings / commands in this file for login shells as well,
+# this file has to be sourced in /etc/profile.
+
+# NOTE: if not running interactively, don't do anything
+[ -z "$PS1" ] && return
+
+[ "${SHELL##*\/}" = bash ] && {
+       # NOTE:  check the window size after each command and, if necessary,
+       #        update the values of LINES and COLUMNS.
+       shopt -s checkwinsize
+ }
+
+# NOTE: set variable identifying the chroot you work in (used in the prompt below)
+if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]
+ then debian_chroot=$(cat /etc/debian_chroot)
+ fi
+
+# NOTE: set a fancy prompt (non-color, overwrite the one in /etc/profile)
+#PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
+
+# NOTE: séquences d’échappement du terminal
+for i in {0..7}
+ do declare tput_setaf_$i="$(tput setaf $i)"
+ done
+tput_sgr0="$(tput sgr0)"
+tput_cnorm="$(tput cnorm)"
+tput_bold="$(tput bold)"
+tput_rev="$(tput rev)"
+
+# NOTE: met un gros curseur bleu non-clignotant dans un TTY
+# VOIR: /usr/src/linux/Documentation/VGA-softcursor.txt
+case $TERM in
+ (*linux) prompt_set_cursor="$tput_cnorm\e[?16;0;16c" ;;
+       # NOTE: last 16 does not seem to be portable
+       #       and you may have to change it to get the right color.
+ (*) prompt_set_cursor=$tput_cnorm ;;
+ esac
+prompt_set_cursor="\\[$prompt_set_cursor\\]"
+alias prompt_errno='test $? = 0 || printf %s "$tput_setaf_1"'
+prompt_text="\\[$tput_setaf_6\\]\\w\\[$tput_sgr0\\] \\[\$(prompt_errno)\\]\\$\\[$tput_sgr0\\] "
+# NOTE: encapsule pour passer l’interprétation de screen
+case $TERM in
+ (screen*) [ -z "$prompt_set_cursor" ] ||
+               prompt_set_cursor="\\[\eP\\]$prompt_set_cursor\\[\e\\\\\\]"
+       ;;
+ (*)
+       # NOTE: rajoute l’hôte quand il n’y a pas screen pour l’afficher
+       prompt_text="\\[$tput_setaf_0$tput_bold\\]\\h $prompt_text"
+       ;;
+ esac
+. /etc/etckeeper/prompt.sh
+PS1="$prompt_set_cursor\\[$tput_setaf_1$tput_bold\\]\$(prompt_etckeeper)\\[$tput_sgr0\\]$prompt_text"
+
+# NOTE: couleurs
+eval $(dircolors --bourne-shell)
+
+# NOTE: alias
+alias cl='clear'
+alias dux='du -cks * | sort -rn | head -11'
+alias e='sudo etckeeper'
+alias ec='sudo etckeeper commit'
+alias ev='sudo etckeeper vcs'
+alias l='ls'
+la ()
+ {
+       local GLOBIGNORE
+       GLOBIGNORE=non-null
+       if [ -z "${@:+set}" ]
+       then chacl -l . .. *
+       else chacl -l "$@"
+       fi
+ }
+alias ll='ls -l'
+lll ()
+ {
+       local GLOBIGNORE
+       GLOBIGNORE=non-null
+       eval "$(if [ -z "${@:+set}" ]
+               then getfacl --absolute-names ${ACLOPTS:---physical} . .. *
+               else getfacl --absolute-names ${ACLOPTS:---physical} "$@"
+               fi |
+               sed -e '/^\# file: /{
+                 N
+                ;N
+                ;x
+                ;s/.*//
+                ;N
+                ;s/^\n\# flags: \([^ ]*\)/f:\1/
+                ;s/^\n//
+                ;: loop
+                ;s/\s*\#effective:\(...\)$/'"$tput_setaf_1"'('"$tput_sgr0"'\1'"$tput_setaf_1"')'"$tput_sgr0"'/
+                ;s/ default:\([^:]\)[^:][^:]*:\([^:]*\):/'"$tput_setaf_0$tput_bold"' d:'"$tput_setaf_0$tput_bold"'\1:'"$tput_sgr0"'\2'"$tput_setaf_0$tput_bold"':'"$tput_sgr0"'/
+                ;s/\(^\| \)\([^:]\)[^:]*:\([^:]*\):\([^:]*\)$/\1'"$tput_setaf_0$tput_bold"'\2:'"$tput_sgr0"'\3'"$tput_setaf_0$tput_bold"':'"$tput_sgr0"'\4/
+                ;N
+                ;s/\n\(.\)/ \1/
+                ;t loop
+                ;s/\n$//
+                ;s/^f:\([^ ]*\) \([^\n]*\)/\2 '"$tput_setaf_0$tput_bold"'f:'"$tput_sgr0"'\1/
+                ;H
+                ;x
+                ;s/^\# file: \([^\n]*\)\n\# owner: \([^\n]*\)\n\# group: \([^\n]*\)\n\(.*\)/ \
+                        echo -En '"'"'\2'"$tput_setaf_0$tput_bold:$tput_sgr0"'\3 \4    '"'"'; \
+                        ls --color=always -d "$(echo -en '"'"'\1'"'"')"/
+                }'
+        )"
+ }
+alias ls='ls -aFh -T 0 --color=auto'
+alias scan='clamdscan --fdpass'
+alias setfacl='setfacl --no-mask'
+alias sl='ls'
+alias vi='vim'
+alias vim='vim -p'
+alias :e='vim'
+alias :q='exit'
+
+# enable bash completion in interactive shells
+if [ -f /etc/bash_completion ]
+ then . /etc/bash_completion
+ fi
+
+mkdir -p ~/var/log/"${SHELL##*/}"
+HISTFILE=~/var/log/"${SHELL##*/}"/history.log
+HISTCONTROL=ignoreboth
+shopt -s histappend
diff --git a/etc/etckeeper/prompt.sh b/etc/etckeeper/prompt.sh
new file mode 100644 (file)
index 0000000..1d1e3ce
--- /dev/null
@@ -0,0 +1,49 @@
+# DESCRIPTION :
+#  - Les variables GIT_AUTHOR_*, utilisées par git pour signer les commits,
+#    seront initialisées en fonction du contenu de ~/.gitconfig
+#    ou du login utilisé pour la connexion.
+#  - La fermeture du shell dans le cas où des modifications de /etc
+#    n'ont pas été enregistrées échouera avec un avertissement.
+
+case $- in
+ (*i*) # NOTE: interactive shell
+       check_uncommitted () {
+               if sudo -n etckeeper unclean 2>/dev/null
+                then printf '%s%s%s\n' >&2 "${tput_rev-}" "/etc has uncommitted changes: please use etckeeper commit." "${tput_sgr0-}"
+                       CHECK_UNCOMMITED="done" $SHELL -$-
+               fi
+        }
+       git_export_env () {
+               local ttyuser ttyuserhome conf
+               
+               ttyuser="$(stat -c "%U" $(tty))"
+               ttyuserhome="$(getent passwd "$ttyuser" | cut -d: -f6)"
+               conf="$ttyuserhome/.gitconfig"
+               
+               if [ -z "$GIT_AUTHOR_NAME" ] && [ -z "$GIT_AUTHOR_EMAIL" ]; then
+                       if [ ! -z "$GIT_CONFIG_LOCAL" ] || [ ! -z "$GIT_CONFIG" ]
+                        then
+                               export GIT_AUTHOR_NAME="$(git config --get user.name)"
+                               export GIT_AUTHOR_EMAIL="$(git config --get user.email)"
+                       elif [ -r "$conf" ]; then
+                               export GIT_AUTHOR_NAME="$(git config --file "$conf" --get user.name)"
+                               export GIT_AUTHOR_EMAIL="$(git config --file "$conf" --get user.email)"
+                       else
+                               export GIT_AUTHOR_NAME="$USER"
+                               export GIT_AUTHOR_EMAIL="$USER@$(hostname -f)"
+                        fi
+                fi
+        }
+       prompt_etckeeper () {
+               errno=$?;
+               if sudo -n etckeeper unclean 2>/dev/null
+                then printf '(!) '
+                fi
+               exit $errno
+        }
+       if [ "$CHECK_UNCOMMITED" != done ]
+        then trap check_uncommitted EXIT
+        fi
+       git_export_env
+       ;;
+ esac
diff --git a/etc/screenrc b/etc/screenrc
new file mode 100644 (file)
index 0000000..f3194ef
--- /dev/null
@@ -0,0 +1,39 @@
+startup_message off
+defutf8 on
+# NOTE: utile pour les connexions SSH fragiles.
+defnonblock 5
+nonblock on
+autodetach on
+defscrollback 5000
+
+bind ^k
+bind ^\
+bind \\ quit
+bind i focus top
+bind k focus bottom
+bind j focus up
+bind l focus down
+bind K kill
+bind I login on
+bind O login off
+bind } history
+
+bind ^B eval "hardcopy_append off" "hardcopy -h $HOME/var/cache/screen/urlview" "screen urlview $HOME/var/cache/screen/urlview"
+bind ^U eval "split -v" "focus bottom" select
+
+# NOTE: add lines to xterm's scrollback buffer.
+termcapinfo xterm*|*rxvt* ti@:te@
+# NOTE: add stuff to xterm (and cousins) title bars.
+termcapinfo * 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'
+# NOTE: terminal understands special xterm sequences (OSC, mouse tracking).
+termcapinfo xterm*|*rxvt* "" XT
+# NOTE: set these terminals up to be 'optimal' instead of vt100.
+termcapinfo xterm*|*rxvt*|Eterm* OP
+
+backtick 1 0 0     hostname
+backtick 2 0 84600 date '+%b'
+hardstatus on
+hardstatus alwayslastline "%{= kb} %-w%{kw}%n %t%{-}%+w %=%{..m} %{= kr}%1` %{kw}%D %d %2` %0c %{= dd}"
+caption splitonly "%?%F%{= .bw}%:%{= .kw}%? %=%{..C}%n%{-} %t%= "
+
+sorendition wk
index cbc6776..46ae2ce 100755 (executable)
--- a/vm_hosted
+++ b/vm_hosted
@@ -22,11 +22,14 @@ rule_help () { # SYNTAX: [--hidden]
                EOF
  }
 
-rule_git_config () {
+rule_git_configure () {
        (
        cd "$tool"
        git config --replace branch.master.remote .
        git config --replace branch.master.merge refs/remotes/master
+       local tool
+       tool=$(cd "$tool"; cd -)
+       sudo ln -fns "$tool"/vm_hosted /usr/local/sbin/
        )
  }
 rule_git_reset () {
@@ -73,8 +76,7 @@ rule_apt_configure () {
        sudo install -m 660 -u root -g root /dev/stdin /etc/apt/sources.list.d/openerp.list <<-EOF
                deb http://nightly.openerp.com/trunk/nightly/deb/ ./
                EOF
- }
-rule_apticron_configure () {
+       sudo apt-get update
        rule apt_get_install apticron
        sudo install -m 644 -u root -g root /dev/stdin /etc/apticron/apticron.conf <<-EOF
                EMAIL="admin@$vm_domainname"
@@ -204,6 +206,9 @@ rule_etckeeper_configure () {
                HIGHLEVEL_PACKAGE_MANAGER=apt
                LOWLEVEL_PACKAGE_MANAGER=dpkg
                EOF
+       sudo install -m 644 -o root -g root \
+         etc/etckeeper/prompt.sh \
+        /etc/etckeeper/prompt.sh
        rule apt_get_install etckeeper
  }
 rule_filesystem_configure () {
@@ -538,18 +543,7 @@ rule_network_configure () {
                    pre-down  ip address delete $vm_ipv4/32 dev \$IFACE
                EOF
  }
-rule_user_configure () {
-       sudo install -d -m 750 -u root -g adm \
-        /etc/skel/etc \
-        /etc/skel/etc/ssh
-       sudo install -d -m 770 -u root -g adm \
-        /etc/skel/etc/apache2 \
-        /etc/skel/var \
-        /etc/skel/var/log \
-        /etc/skel/var/cache \
-        /etc/skel/var/cache/ssh
-       sudo ln -fns etc/ssh /etc/skel/.ssh
-       sudo ln -fns etc/gpg /etc/skel/.gnupg
+rule_ssh_configure () {
        ssh-keygen -F "$vm_fqdn" -f "$tool"/etc/openssh/known_hosts |
        ( while IFS= read -r line
         do case $line in (*" RSA") return 0; break;; esac
@@ -656,6 +650,12 @@ rule_user_configure () {
                sudo /bin/sh -e -f -u -c \
                  'case \$(/usr/bin/passwd --status "\$SUDO_USER") in ("\$SUDO_USER L "*) /usr/bin/passwd \$SUDO_USER;; esac'
                EOF
+       sudo install -m 644 -u root -g root \
+         etc/bash.bashrc \
+        /etc/bash.bashrc
+       sudo install -m 644 -o root -g root \
+         etc/screenrc \
+        /etc/screenrc
  }
 rule_user_root_configure () {
        sudo install -d -m 750 -u root -g adm \
@@ -679,20 +679,18 @@ rule_user_root_configure () {
         do sudo gpg --import "$key"
         done
  }
-rule_bin_configure () {
-       sudo ln -fns "$tool"/vm_hosted /usr/local/sbin/
- }
 rule_configure () {
+       rule apt_configure
+       rule git_configure
        rule etckeeper_configure
        rule locale_configure
        rule network_configure
-       rule apt_configure
        rule filesystem_configure
        rule login_configure
+       rule ssh_configure
        rule user_root_configure
        rule boot_configure
-       rule apticron_configure
-       rule bin_configure
+       rule user_configure
  }
 
 rule_luks_key_change () {