From c152d079f40a3c912feb6f45d9f1f00ca10f9c33 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 11 Dec 2017 00:36:07 +0000 Subject: [PATCH] bin/nb-install --- bin/nb-install | 18 +++--------------- etc/git/hooks/pre-commit | 10 ++++++++++ etc/profile.d/functions | 27 +++++++++++++++++++++++++-- etc/vimrc | 23 ----------------------- www/dbq/update.sh | 28 ---------------------------- 5 files changed, 38 insertions(+), 68 deletions(-) create mode 100755 etc/git/hooks/pre-commit delete mode 100644 etc/vimrc delete mode 100755 www/dbq/update.sh diff --git a/bin/nb-install b/bin/nb-install index b4511ef8..b23d4d69 100755 --- a/bin/nb-install +++ b/bin/nb-install @@ -104,24 +104,12 @@ main() { verbose $(chown "$NB_USER" /var/log/nb.log 2> /dev/null) # - # nb-commit + # Git hooks # cd "$NB_ROOT" || exit - rm -f .git/hooks/pre-push - - if [ -w .git/hooks ]; then - - #echo "Create .git/hooks/pre-push" - cat < .git/hooks/pre-commit -#!/bin/sh -echo Git hooks pre-commit $* 1>&2 -$([ -e www/dbq/update.sh ] && echo www/dbq/update.sh) -EOF - - chmod 755 .git/hooks/pre-commit - chown "$NB_USER" .git/hooks/pre-commit - + if [ -w .git/hooks -a -r etc/git/hooks/pre-commit ]; then + cp -a etc/git/hooks/pre-commit .git/hooks/ fi # diff --git a/etc/git/hooks/pre-commit b/etc/git/hooks/pre-commit new file mode 100755 index 00000000..15e7585d --- /dev/null +++ b/etc/git/hooks/pre-commit @@ -0,0 +1,10 @@ +#!/bin/bash -l +echo DEBUG: pre-commit $* 1>&2 +#. /etc/profile +# NB 11.12.17 [ -x www/dbq/update.sh ] && echo www/dbq/update.sh && www/dbq/update.sh +[ -d www/dbq/ ] && cd www/dbq/ && minify_dir | while read -r f; do + echo "$f" + git add "$f" +done + +true diff --git a/etc/profile.d/functions b/etc/profile.d/functions index c18b0d45..07b6ddee 100644 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -875,7 +875,6 @@ tab2space() { local size=2 [ "$1" = "-size" ] && shift && size=$1 && shift local space=$(eval "printf ' %.0s' {1..$size}") -# NB 08.12.17 perl -pe "1 while s/^\t/$space/" $@ perl -pe "s/\G[\t]/$space/g" $@ } @@ -883,6 +882,30 @@ space2tab() { local size=2 [ "$1" = "-size" ] && shift && size=$1 && shift local space=$(eval "printf ' %.0s' {1..$size}") -# NB 08.12.17 perl -pe "1 while s/^$space/\t/" $@ perl -pe "s/^\t/$space/; s/\G[ ]{$size}/\t/g" $@ } + +minify_dir() { + local usage='minify_dir find and minify js and css files into current directory.' + local tmp="/tmp/minify_dir.$$" + local minify="nb-read.php minify_" + which minify &> /dev/null && minify="minify --" + + for f in $(find `pwd` -type f \( -name '*.css' -o -name '*.js' \) -a -not -name '*.min.*'); do + min=$(echo "$f" | sed 's/\./.min./') + ext="${f##*.}" + + $minify$ext < $f > "$tmp" + if [ "$?" != "0" ]; then + echo "Error: $minify$ext" 1>&2 + continue + fi + + diff -q "$tmp" "$min" &> /dev/null && continue + #echo "Minify $f -> $(basename "$min")" + echo "$min" + cat "$tmp" > "$min" + + done + rm -rf "$tmp" +} diff --git a/etc/vimrc b/etc/vimrc deleted file mode 100644 index 0545cf5f..00000000 --- a/etc/vimrc +++ /dev/null @@ -1,23 +0,0 @@ -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" -" ~/.vimrc -" ln -s /opt/nb/etc/vimrc ~/.vimrc -" -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -let $VIMHOME = fnamemodify(resolve(fnamemodify(expand(''),':p')),':h').'/vim' -if empty(glob($VIMHOME)) && filereadable(expand('~/.vim')) - let $VIMHOME = resolve(expand('~/.vim')) -endif - -" NB 08.03.17: infinite loop when link on /etc/vim/vimrc.local -" NB 08.03.17 if filereadable("/etc/vim/vimrc") -" NB 08.03.17 source /etc/vim/vimrc -" NB 08.03.17 endif - -if &runtimepath !~ $VIMHOME - let &runtimepath = &runtimepath . ',' . $VIMHOME -endif - -for file in split(globpath($VIMHOME . '/source/', '*.vim'), '\n') - execute 'source' fnameescape(file) -endfor diff --git a/www/dbq/update.sh b/www/dbq/update.sh deleted file mode 100755 index dd4f8312..00000000 --- a/www/dbq/update.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env sh -! which minify > /dev/null 2>&1 && echo "Please install minify (npm -g install minify) !" 1>&2 && exit 0 -minify -h | grep -qm1 no-comments && echo "Version not supported" 1>&2 && exit 0 - -set -e -cd "$(dirname $0)" - -ex=0 -for f in $(find html -type f \( -name '*.css' -o -name '*.js' \) -a -not -name '*.min.*'); do - - min=$(echo "$f" | sed 's/\./.min./') - ext="${f##*.}" - - echo "Minify "$( ( realpath "$f" 2> /dev/null || echo "$f" ) | sed "s,^$NB_ROOT/,," ) - - eval minify --$ext < "$f" > "$min.new" && mv "$min.new" "$min" - #eval minify --$ext < "$f" > "$min.new" - #nb-read.php minify_$ext < "$f" > "$min.new" - [ "$?" = "0" ] || ex=1 - - #[ -t "$min.new" ] && diff -q "$"$min.new"" "$min" &> /dev/null && mv "$min.new" "$min" || rm "$min.new" - #git add "$min" - #[ "$ex" = "0" ] && echo DEBUG: Should: git add "$min" - #[ "$ex" = "0" ] && git add "$min" && echo "DEBUG: git add $min" - -done - -[ "$ex" = "0" ] || echo Failed 1>&2 -- 2.47.3