From: Francois Fleuret Date: Sat, 13 Mar 2010 15:53:23 +0000 (+0100) Subject: Initial commit X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=2b983c5c7336826b764036e3e1478a5a8159248a;p=scripts.git Initial commit --- 2b983c5c7336826b764036e3e1478a5a8159248a diff --git a/archivepics.sh b/archivepics.sh new file mode 100755 index 0000000..d96db4e --- /dev/null +++ b/archivepics.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +# (1) Check that all JPG are larger than 1M if there is no +# corresponding MOV + +# (2) Change the modification time to match the EXIF info (use the +# accompanying JPG for the MOV) + +# (3) Move the JPG and MOV to an archive directory of the form +# ${GP_ARCHIVE_DIR}/year/month, create the directory when necessary. + +[[ ${archive_size_min} ]] || archive_size_min=1048576 # 1Mb + +set -e + +if [[ ! ${GP_ARCHIVE_DIR} ]]; then + echo "You have to set \$GP_ARCHIVE_DIR" >&2 + exit 1 +fi + +# Checking the image sizes + +for i in "$@"; do + + if [[ ! -f ${i/JPG/MOV} ]]; then + + if [[ $(stat --printf=%s $i) -lt ${archive_size_min} ]]; then + echo "Image $i is too small." + exit 1 + fi + + fi + +done + +# Setting the file modification date according to the exif tag + +for i in "$@"; do + + ref=${i/MOV/JPG} + + if [[ -f ${ref} ]]; then + + TAG=$(exif --ifd=EXIF -t "Date and Time (original)" ${ref} | grep Value) + + if [[ ${TAG} ]]; then + TIMESTAMP=$(echo ${TAG} | sed -e \ + "s/^ *Value: *\([0-9]*\):\([0-9]*\):\([0-9]*\) *\([0-9]*\):\([0-9]*\):\([0-9]*\).*$/\1\2\3\4\5.\6/") + touch -t $TIMESTAMP $i + else + echo "No exif tag in $i, can not set the date properly." + fi + + else + + echo "Can not find a reference picture file for $i, can not set the date properly." + + fi + +done + +# Moving the file to the proper archive directory, which is created +# first when needed + +for i in "$@"; do + + ARCHIVING_PATH=$(ls -l --time-style=+%Y/%b --format=verbose $i | awk '{ print $6 }') + + mkdir -p ${GP_ARCHIVE_DIR}/${ARCHIVING_PATH} + + echo "Archiving ${GP_ARCHIVE_DIR}/${ARCHIVING_PATH}/$(basename $i)" + + cp -p -i $i ${GP_ARCHIVE_DIR}/${ARCHIVING_PATH} + +done diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000..99f39ef --- /dev/null +++ b/clean.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +TRASH=$(mktemp -d /tmp/trash.XXXXXX) + +# "pdf:fig" "pdf:png" "pdf:pgm" + +for i in "nav:tex" "snm:tex" "toc:tex" "blg:tex" \ + "idx:tex" "ilg:tex" "ind:tex" "lof:tex" "lot:tex" "lou:tex" \ + "dvi:tex" "log:tex" "aux:tex" "bbl:tex" \ + "ps:tex" "pdf:tex" "out:tex" "tpt:tex" "brf:tex" \ + "eps:fig" "eps:png" "eps:pgm" \ + "o:cc" "o:c" ; do + PRODUCED=$(echo $i | cut -f 1 -d:) + SOURCE=$(echo $i | cut -f 2 -d :) + for f in *.$PRODUCED; do + ORIGINAL=${f/.$PRODUCED/.$SOURCE} + if [ -f "${ORIGINAL}" ]; then + echo "move $f to ${TRASH} ($ORIGINAL exists)" + mv $f ${TRASH} + fi + done +done + +for i in "mozilla.ps" "a.out"; do + if [ -f "$i" ]; then + echo "move $i to ${TRASH}" + mv $i ${TRASH} + fi +done + +for f in $(find -type f -executable); do + if [ -f ${f}.cc ] || [ -f ${f}.c ]; then + echo "move $f to ${TRASH} (source code exists)" + mv $f ${TRASH} + fi +done diff --git a/dirtohtml.sh b/dirtohtml.sh new file mode 100755 index 0000000..40c2767 --- /dev/null +++ b/dirtohtml.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +function error () { + echo $1 1>&2 + exit 1 +} + +## Header ############################################################ + +cat < + + + + + + + + + + + +EOF + +## Body ############################################################## + +echo "

Directory content

" + +echo + +echo "
"
+
+for d in $(find . -maxdepth 1 -type d -name "[^.]?*" | \
+    awk '{print $1" "$1}' | \
+    sed -e "s/^[^0-9]*//" | \
+    sort -g | \
+    awk '{print $2}'); do
+
+    most_recent=$(find ${d} -type f -exec stat --printf="%y %n\n" '{}' \; | sort | tail -1 | awk '{print $4}')
+
+    if [[ ${most_recent} ]]; then
+        date=$(stat --printf="%y" ${most_recent})
+    else
+        date=$(stat --printf="%y" ${d})
+    fi
+
+    echo "${date} ${d}"
+done
+
+echo "
" + +echo + +## Footer ############################################################ + +cat < + + +EOF + +###################################################################### diff --git a/dns323-op.sh b/dns323-op.sh new file mode 100755 index 0000000..2aa5c14 --- /dev/null +++ b/dns323-op.sh @@ -0,0 +1,164 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +# A command-line tool to restart, shutdown or get the status of a +# D-Link DNS323. + +set -e + +function rm_temp () { + if [[ ${TEMP} ]]; then + rm ${TEMP} + unset TEMP + fi +} + +function authentify_on_dns323 () { + if [[ ! ${already_authentified} ]]; then + echo "Authentifying on ${DNS323_HOSTNAME}." + curl -s > /dev/null \ + -L http://${DNS323_HOSTNAME}/goform/formLogin \ + -d "f_LOGIN_NAME=admin&f_LOGIN_PASSWD=${DNS323_ADMIN_PASSWORD}&f_login_type=0" || (echo "Failed." >&2 && exit 1) + already_authentified=1 + fi +} + +function check_unmounted () { + if [[ ! ${force_operation} ]]; then + if [[ $(mount | grep ^//${DNS323_HOSTNAME}) ]]; then + echo "//${DNS323_HOSTNAME} appears to be mounted." >&2 + exit 1 + fi + fi +} + +function show_help () { + cat >&2 < ... + + -h, --help shows this help. + -f, --force forces shutdown or restart even if it looks like the samba + drive is mounted. + status gets temperature and RAID info. + shutdown shuts the unit down. + restart restarts the unit. + +EOF +} + +###################################################################### + +trap rm_temp SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM ERR + +if [[ ${DNS323_HOSTNAME} ]] && \ + [[ ${DNS323_ADMIN_PASSWORD} ]]; then + + while [[ $1 ]]; do + + case $1 in + + ################################################################ + + -f|--force) + force_operation=1 + ;; + + ################################################################ + + -h|--help) + show_help + ;; + + ################################################################ + + status) + + authentify_on_dns323 + + # If you think what follows is fugly, please have a + # look at the DNS323's web app HTML + + TEMP=$(mktemp /tmp/status.XXXXXX) + + curl -s \ + -L http://${DNS323_HOSTNAME}/goform/adv_status \ + -d "" > ${TEMP} + + cat ${TEMP} | \ + html2text | \ + grep "\(Sync Time Remaining\|Volume Name\|Volume Type\|Total Hard Drive Capacity\|Used Space\|Unused Space\)": | \ + sed -e "s/^[ \t]*//" + + grep "var temper" ${TEMP} | sed -e "s/^.*\"\([0-9]*\):\([0-9]*\)\".*$/Temperature: \1F \/ \2C/" + + rm_temp + + ;; + + ################################################################ + + shutdown) + + authentify_on_dns323 + + check_unmounted + + curl > /dev/null \ + -s \ + -L http://${DNS323_HOSTNAME}/goform/sysShutDown \ + -d "" + + echo "Shutdown initiated." + + ;; + + ################################################################ + + restart) + + authentify_on_dns323 + + check_unmounted + + curl -s > /dev/null \ + -L http://${DNS323_HOSTNAME}/goform/System_restart \ + -d "" + + echo "Restart initiated." + + ;; + + ################################################################ + + *) + echo "Unknown operation $1" >&2 + show_help + exit 1 + ;; + esac + + shift + + done + +else + + echo "Please set \$DNS323_HOSTNAME and \$DNS323_ADMIN_PASSWORD." + +fi diff --git a/emacs-cvs-in-debian.sh b/emacs-cvs-in-debian.sh new file mode 100755 index 0000000..33bf7ee --- /dev/null +++ b/emacs-cvs-in-debian.sh @@ -0,0 +1,149 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +# You need at least the Debian packages: gcc make cvs texinfo +# libx11-dev libxft-dev libgif-dev libjpeg62-dev libpng12-dev +# libtiff4-dev libxpm-dev + +set -e + +DIR=/usr/local/emacs-snapshot + +while [[ $1 ]]; do + + case $1 in + + ################################################################ + + download) + + mkdir -p ${DIR} + + cd ${DIR} + + cvs -z3 \ + -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/emacs \ + co emacs + + ;; + + ################################################################ + + compile) + + cd ${DIR}/emacs/ + + # I do not like gtk and such, hence the very limited + # configuration options. Feel free to add your own. + + ./configure --prefix=${DIR} \ + --with-xpm --with-jpeg --with-tiff --with-png \ + --with-x --with-xft + + make -k bootstrap + make install + + ;; + + ################################################################ + + install) + + if [[ -a /usr/share/emacs-snapshot ]]; then + echo "You have to remove /usr/share/emacs-snapshot." >&2 + exit 1 + fi + + # We do not know the version you downloaded. This ugly + # command will figure it out for you + + SHARE=$(find ${DIR}/share/emacs/ -maxdepth 1 -mindepth 1 -type d \ + | \grep "/[0-9\.]*$") + + if [[ ! -d "${SHARE}" ]]; then + echo "Can not find ${SHARE}, that's weird." >&2 + exit 1 + fi + + ln -s ${SHARE}/ /usr/share/emacs-snapshot + + for p in emacs ctags etags emacsclient ebrowse; do + # Install the binary as a link in /usr/bin + ln -s ${DIR}/bin/$p /usr/bin/$p-snapshot + # Tell the Debian system that the binary can be used + # as an alternative version + update-alternatives \ + --install /usr/bin/$p $p /usr/bin/$p-snapshot 23 + # Tell the Debian system that that new version should + # be used as default + update-alternatives \ + --set $p /usr/bin/$p-snapshot + done + + mkdir -p /etc/emacs-snapshot/site-start.d + + # Compile and install for that version of emacs all the + # emacs packages installed as Debian packages (vm, bbdb, + # etc.) + /usr/lib/emacsen-common/emacs-install emacs-snapshot + + ;; + + ################################################################ + + deinstall) + + # Remove that version of emacs from the list of versions + # for which Debian emacs-related packages should be + # compiled + /usr/lib/emacsen-common/emacs-remove emacs-snapshot + + rm -rf /etc/emacs-snapshot + + # Remove the alternatives + for p in emacs ctags etags emacsclient ebrowse; do + update-alternatives --remove $p /usr/bin/$p-snapshot + rm /usr/bin/$p-snapshot + done + + rm /usr/share/emacs-snapshot + ;; + + ################################################################ + + remove) + + rm -rf ${DIR} + + ;; + + ################################################################ + + *) + + echo "$0 " >&2 + exit 1 + + ;; + + esac + + shift 1 + +done diff --git a/hotspot.sh b/hotspot.sh new file mode 100755 index 0000000..1cd5a22 --- /dev/null +++ b/hotspot.sh @@ -0,0 +1,352 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +INTERFACE=wlan0 +MTU=512 + +SCAN_OUTPUT=$(mktemp /tmp/scanresult.XXXXXX) +SHOW_CLOSED=0 + +###################################################################### + +VT_CURSOR_OFF=$'\033[?25l' +VT_CURSOR_ON=$'\033[?25h' + +VT_RESET=$'\033[0m' +VT_BOLD=$'\033[1m' +VT_UNDERLINE=$'\033[4m' +VT_BLINK=$'\033[5m' + +VT_BLACK_FG=$'\033[30m' +VT_RED_FG=$'\033[31m' +VT_GREEN_FG=$'\033[32m' +VT_YELLOW_FG=$'\033[33m' +VT_BLUE_FG=$'\033[34m' +VT_MAGENTA_FG=$'\033[35m' +VT_CYAN_FG=$'\033[36m' +VT_WHITE_FG=$'\033[37m' + +VT_BLACK_BG=$'\033[40m' +VT_RED_BG=$'\033[41m' +VT_GREEN_BG=$'\033[42m' +VT_YELLOW_BG=$'\033[43m' +VT_BLUE_BG=$'\033[44m' +VT_MAGENTA_BG=$'\033[45m' +VT_CYAN_BG=$'\033[46m' +VT_WHITE_BG=$'\033[47m' + +###################################################################### + +function cleanup-before-quit () { + echo ${VT_CURSOR_ON} + stty "$stty_state" + rm -f ${SCAN_OUTPUT} + if [[ "${interface_was_up}" == "" ]]; then + echo "The interface was down." + ifconfig ${INTERFACE} down + fi +} + +function sigint-handler () { + cleanup-before-quit + echo "Interrupted" + exit 0 +} + +function scan () { + iwconfig ${INTERFACE} ap off essid "" + iwlist ${INTERFACE} scan | \ + sed -e "s/^[\t ]*//" | grep ^"Cell\|ESSID\|Quality\|Encryption" | \ + sed \ + -e "s/Cell [0-9]* - Address: \([0-9]*\)/AP,\1/" \ + -e "s/^ *ESSID:\\\"\([^\\\"]*\)\\\".*$/ESSID,\1/" \ + -e "s/Quality=\([0-9]*\).*$/QUALITY,\1/" \ + -e "s/Encryption key:/ENCRYPTION,/" | \ + awk 'BEGIN { FS="," } + { + if($1 == "ESSID") { essid=$2 } + else if($1 == "AP") { ap=$2 } + else if($1 == "QUALITY") { quality=$2; } + else if($1 == "ENCRYPTION") { + if($2 == "off") { + open=" " + printf("%d,%s,%s,%s\n",quality,open,essid,ap); + } else { + if('${SHOW_CLOSED}') { + open="(closed)" + printf("%d,%s,%s,%s\n",quality,open,essid,ap); + } + } + } + }' | \ + sort -rn > ${SCAN_OUTPUT} + + number_of_aps=$(wc -l ${SCAN_OUTPUT} | awk '{print $1}') + + chmod a+rw ${SCAN_OUTPUT} +} + +function redisplay () { + clear + + echo + echo -n " ${VT_UNDERLINE}Hotspot selection${VT_RESET}" + if [[ $SHOW_CLOSED == 0 ]]; then + echo " (show only open networks)" + else + echo + fi + echo + echo " [s,r] scan [m] switch the free-only view and scan [q] quit" + echo " [e] select essid + dhcp [a] selects essid/ap + dhcp [k] kill dhcp and quit" + echo + + for i in $(ifconfig -s | grep -E -v ^lo\|Iface\|wmaster | awk '{print $1}'); do + echo " Warning: $i is up" + done + echo + + if [[ ${number_of_aps} == "0" ]]; then + echo " ${VT_RED_FG}${VT_BOLD}No access point detected.${VT_RESET}" + else + + awk < ${SCAN_OUTPUT} 'BEGIN { nb=1; FS="," } + { + if(nb == '$current_ap') { + printf(" =>"); + } else { + printf(" "); + } + if($2 == "(closed)") { + printf("'${VT_RED_FG}'"); + printf("% 3s %s \"%s\" %s'${VT_RESET}'\n", $1, $2, $3, $4); + } else { + printf("'${VT_GREEN_FG}'"); + printf("% 3s %s \"%s\" %s'${VT_RESET}'\n", $1, $2, $3, $4); + } + nb=nb+1; + }' + fi +} + +function get-selected-essid-ap () { + cat ${SCAN_OUTPUT} | \ + awk 'BEGIN { nb=1; FS="," } + { + if(nb == '$current_ap') { + printf("%s,%s\n", $3, $4); + } + nb=nb+1; + }' +} + +function kill-dhcp () { + PID=$(pidof dhclient) + if [[ ${PID} ]]; then + echo "Killing dhclient" + dhclient -x ${INTERFACE} + fi +} + +###################################################################### + +function process-key () { + + case $1 in + e) # Selects essid + dhcp + SELECTED=$(get-selected-essid-ap) + ESSID=$(echo ${SELECTED} | cut -f 1 -d,) + echo "Running DHCP on ${INTERFACE} for ESSID ${ESSID}." + iwconfig ${INTERFACE} ap auto essid "${ESSID}" + kill-dhcp + echo + dhclient ${INTERFACE} + # if [[ $? == 0 ]]; then + # iwconfig ${INTERFACE} > ~/.hotspot-ap + # fi + ifconfig ${INTERFACE} mtu ${MTU} + interface_was_up=1 + cont=0 + ;; + + "return"|a) # Selects essid/ap + dhcp + SELECTED=$(get-selected-essid-ap) + ESSID=$(echo ${SELECTED} | cut -f 1 -d,) + AP=$(echo ${SELECTED} | cut -f 2 -d,) + echo "Running DHCP on ${INTERFACE} for ESSID ${ESSID} and AP ${AP}." + iwconfig ${INTERFACE} ap ${AP} essid "${ESSID}" + kill-dhcp + echo + dhclient ${INTERFACE} + # if [[ $? == 0 ]]; then + # iwconfig ${INTERFACE} > ~/.hotspot-ap + # fi + ifconfig ${INTERFACE} mtu ${MTU} + interface_was_up=1 + cont=0 + ;; + + k) # kill dhcp + echo "Killing DHCP and bringing down ${INTERFACE}." + kill-dhcp + ifconfig ${INTERFACE} down + cont=0 + ;; + + r|s) # re-scanning the access points + echo "Scanning ..." + scan + redisplay + ;; + + m) # Switching the mode to show the protected spots + SHOW_CLOSED=$((1-SHOW_CLOSED)) + echo "Scanning ..." + scan + redisplay + ;; + + "down"|n) + current_ap=$((current_ap+1)) + if [[ $current_ap -gt $number_of_aps ]]; then + current_ap=$number_of_aps + fi + redisplay + ;; + + "up"|p) + current_ap=$((current_ap-1)) + if [[ $current_ap -lt 1 ]]; then + current_ap=1 + fi + redisplay + ;; + + "esc-esc"|q) + echo "quit" + cont=0 + ;; + + *) + ;; + esac +} + +###################################################################### +## The main + +if [[ $1 == "-k" ]]; then + echo "Killing DHCP and bringing down ${INTERFACE}." + kill-dhcp + ifconfig ${INTERFACE} down + exit 1 +fi + +stty_state=$(stty -g) + +trap sigint-handler SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM + +stty -echo -icrnl -icanon -xcase min 1 time 0 + +echo ${VT_CURSOR_OFF} + +current_ap=1 +cont=1 +current_keymap=default + +interface_was_up=$(ifconfig | grep ${INTERFACE}) + +ifconfig ${INTERFACE} up + +scan + +redisplay + +while [[ ${cont} == 1 ]]; do + + CHAR=$(dd bs=1 count=1 2>/dev/null) + + case ${current_keymap} in + default) ################################################## + case ${CHAR} in + + [a-z]) + process-key ${CHAR} + ;; + + " ") + process-key "return" + ;; + + "") + process-key "down" + ;; + + "") + process-key "up" + ;; + + "") #$'\033'") + current_keymap=escape + ;; + + *) + ;; + esac + ;; + + escape) ################################################## + case ${CHAR} in + "$'\033'") + process-key "esc-esc" + ;; + "[") + current_keymap=cursor + ;; + *) + current_keymap=default + ;; + esac + ;; + + cursor) ################################################## + + current_keymap=default + + case ${CHAR} in + A) + process-key "up" + ;; + B) + process-key "down" + ;; + *) + ;; + esac + ;; + + *) + echo "Unknown keymap. This is an internal and weird bug." + cont=0 + ;; + esac + + done + + cleanup-before-quit diff --git a/kill-unused-xterms.sh b/kill-unused-xterms.sh new file mode 100755 index 0000000..6ea3058 --- /dev/null +++ b/kill-unused-xterms.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +# Kills all xterms which are running bash with no sub-process + +set -e + +NB_KILLED=0 +NB_TOTAL=0 +SHELL_NAME=bash + +for ppid in $(ps h -C xterm -o pid); do + N=0 + for pid in $(ps h --ppid $ppid -o pid,cmd | awk '{ if($2 == "'${SHELL_NAME}'") { print $1 }}'); do + K=$(ps h --ppid $pid -o cmd,pid | wc -l) + N=$((N+K+1)) + done + if [[ $N == 1 ]]; then + kill -USR2 $ppid + NB_KILLED=$((NB_KILLED+1)) + fi + NB_TOTAL=$((NB_TOTAL+1)) +done + +echo "Killed ${NB_KILLED} / ${NB_TOTAL} XTerm(s)" diff --git a/picstohtml.sh b/picstohtml.sh new file mode 100755 index 0000000..70310c2 --- /dev/null +++ b/picstohtml.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +function error () { + echo $1 1>&2 + exit 1 +} + +###################################################################### +# Create the directories + +if [[ -z $1 ]] || [[ -z $2 ]]; then + echo "$0 " + exit 1 +fi + +if [[ ! -d $1 ]]; then + echo "Can not find directory $1" + exit 1 +fi + +mkdir $2 || error "Can not create $2." +mkdir $2/pics || error "Can not create $2/pics" +mkdir $2/thumbs || error "Can not create $2/thumbs" + +###################################################################### +# Generate the html header + +cat > $2/index.html < + + + + + + + + + + + +EOF + +###################################################################### +# Generate the thumbnails, html content and copy the images + +for i in $(find $1 -type f | sort); do + FILENAME=$(basename $i) + convert 2> /dev/null -geometry 180x120 $i $2/thumbs/${FILENAME}.jpg + + if [[ $? == 0 ]]; then + echo "Copying ${FILENAME}" + cp $i $2/pics/${FILENAME} + echo "" >> $2/index.html + else + echo "Ignoring $i (not an image?)" + fi + +done + +###################################################################### +# Generate the footer of the html file + +cat >> $2/index.html < + + +EOF + +###################################################################### diff --git a/print.sh b/print.sh new file mode 100755 index 0000000..9ac874d --- /dev/null +++ b/print.sh @@ -0,0 +1,185 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +set -e + +# $Id: print.sh,v 1.19 2006-11-10 15:53:23 fleuret Exp $ + +if [ ! "$*" ]; then + echo "Need filenames to print!" + exit 1 +fi + +tmp=$(mktemp /tmp/print.ps.XXXXXX) +opts="" +printing_cmd="lpr" + +for arg in $*; do + + if [ "${arg}" == "-h" ] || [ "${arg}" == "--help" ]; then + + # The help option + + echo $(basename $0)" [ ... ] [[ ... ] ... ]" + echo + echo "A dumb printing utility. Options:" + echo + echo "-2pp two pages per page" + echo "-4pp four pages per page" + echo "-8pp eight pages per page" + echo "-gv displays the result with gv instead of printing" + echo "-stdout send the result to the standard output" + echo "-P uses instead of $PRINTER" + echo + echo "Contact " + echo "Version \$Id: print.sh,v 1.19 2006-11-10 15:53:23 fleuret Exp $" + + \rm ${tmp} + exit 0 + + elif [[ ${arg} == "-"* ]]; then + + # else, if it starts with '-' it is an option + + opts="${opts} ${arg}" + + else + + # else, it is a filename to print + + if [ -e ${arg} ]; then + + TYPE=$(file -L ${arg}) + + noprint="" + + case $TYPE in + + *"image data"*) + convert ${arg} ps:${tmp} + ;; + + *"TeX DVI"*) + dvips -o ${tmp} ${arg} + ;; + + *"FIG image"*) + fig2dev -L ps ${arg} > ${tmp} + ;; + + *"PostScript"*) + cp ${arg} ${tmp} + ;; + + *"PDF"*) + pdf2ps ${arg} ${tmp} + ;; + + *" text"*) + # a2ps -B -R --columns=1 -f 8 -o ${tmp} ${arg} + a2ps --user-option=lp -o ${tmp} ${arg} + ;; + + *"gzip compressed"*) + echo "Unzipping " + zcat ${arg} > ${tmp} + noprint=1 + $0 ${opts} ${tmp} + ;; + + *) + echo "Unable to handle type \"$TYPE\""; noprint=1 + ;; + + + esac + + if [ ! "$noprint" ]; then + + # We apply all the filters seen up to now + + for f in ${opts}; do + case $f in + -2pp) + tmp2=$(mktemp /tmp/filter.ps.XXXXXX) + psnup -d0 -m5 -2 < ${tmp} > ${tmp2} + mv ${tmp2} ${tmp} + ;; + -4pp) + tmp2=$(mktemp /tmp/filter.ps.XXXXXX) + psnup -d0 -m5 -4 < ${tmp} > ${tmp2} + mv ${tmp2} ${tmp} + ;; + -8pp) + tmp2=$(mktemp /tmp/filter.ps.XXXXXX) + psnup -d0 -m5 -8 < ${tmp} > ${tmp2} + mv ${tmp2} ${tmp} + ;; + -gv) + printing_cmd="gv" + ;; + + -stdout) + printing_cmd="cat" + ;; + + -P*) + printing_cmd="lpr" + PRINTER=$(echo $f | sed -e s/^-P//) + if [[ -z "$PRINTER" ]]; then + echo "Error in the printer name. Use -P with no space." + lpstat -a + exit 1 + else + echo "Using printer \"$PRINTER\"" + fi + ;; + *) + echo "Unknown option $f" + \rm ${tmp} + exit 1;; + esac + done + + if [[ "$printing_cmd" == "lpr" ]]; then + echo "Printing on printer '$PRINTER'" + show_queue=1 + fi + + ${printing_cmd} ${tmp} + + fi + + else + + echo "Can not find file ${arg}" + + fi + + fi + +done + +\rm ${tmp} + +if [[ ${show_queue} ]]; then + lpq +fi + +exit 0