commit 1c452ac2c1140f68f1c3f77e230f9a896228aea9 Author: Abhay Rana Date: Sat Jan 28 12:44:33 2012 +0530 Initial commit diff --git a/alsa-info.sh b/alsa-info.sh new file mode 100755 index 0000000..fd7df96 --- /dev/null +++ b/alsa-info.sh @@ -0,0 +1,928 @@ +#!/bin/bash + +SCRIPT_VERSION=0.4.60 +CHANGELOG="http://www.alsa-project.org/alsa-info.sh.changelog" + +################################################################################# +#Copyright (C) 2007 Free Software Foundation. + +#This program is free software; you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation; either version 2 of the License, or +#(at your option) any later version. + +#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, write to the Free Software +#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +################################################################################## + +#The script was written for 2 main reasons: +# 1. Remove the need for the devs/helpers to ask several questions before we can easily help the user. +# 2. Allow newer/inexperienced ALSA users to give us all the info we need to help them. + +#Set the locale (this may or may not be a good idea.. let me know) +export LC_ALL=C + +#Change the PATH variable, so we can run lspci (needed for some distros) +PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin +BGTITLE="ALSA-Info v $SCRIPT_VERSION" +PASTEBINKEY="C9cRIO8m/9y8Cs0nVs0FraRx7U0pHsuc" +#Define some simple functions + +pbcheck(){ + [[ $UPLOAD = "no" ]] && return + + if [[ -z $PASTEBIN ]]; then + [[ $(ping -c1 www.alsa-project.org) ]] || KEEP_FILES="yes" UPLOAD="no" PBERROR="yes" + else + [[ $(ping -c1 www.pastebin.ca) ]] || KEEP_FILES="yes" UPLOAD="no" PBERROR="yes" + fi +} + +update() { + SHFILE=`mktemp -t alsa-info.XXXXXXXXXX` || exit 1 + wget -O $SHFILE "http://www.alsa-project.org/alsa-info.sh" >/dev/null 2>&1 + REMOTE_VERSION=`grep SCRIPT_VERSION $SHFILE |head -n1 |sed 's/.*=//'` + if [ "$REMOTE_VERSION" != "$SCRIPT_VERSION" ]; then + if [[ -n $DIALOG ]] + then + OVERWRITE= + if [ -w $0 ]; then + dialog --yesno "Newer version of ALSA-Info has been found\n\nDo you wish to install it?\nNOTICE: The original file $0 will be overwritten!" 0 0 + DIALOG_EXIT_CODE=$? + if [[ $DIALOG_EXIT_CODE = 0 ]]; then + OVERWRITE=yes + fi + fi + if [ -z "$OVERWRITE" ]; then + dialog --yesno "Newer version of ALSA-Info has been found\n\nDo you wish to download it?" 0 0 + DIALOG_EXIT_CODE=$? + fi + if [[ $DIALOG_EXIT_CODE = 0 ]] + then + echo "Newer version detected: $REMOTE_VERSION" + echo "To view the ChangeLog, please visit $CHANGELOG" + if [ "$OVERWRITE" = "yes" ]; then + cp $SHFILE $0 + echo "ALSA-Info script has been updated to v $REMOTE_VERSION" + echo "Please re-run the script" + rm $SHFILE 2>/dev/null + else + echo "ALSA-Info script has been downloaded as $SHFILE." + echo "Please re-run the script from new location." + fi + exit + else + rm $SHFILE 2>/dev/null + fi + else + echo "Newer version detected: $REMOTE_VERSION" + echo "To view the ChangeLog, please visit $CHANGELOG" + if [ -w $0 ]; then + echo "The original file $0 will be overwritten!" + echo -n "If you do not like to proceed, press Ctrl-C now.." ; read inp + cp $SHFILE $0 + echo "ALSA-Info script has been updated. Please re-run it." + rm $SHFILE 2>/dev/null + else + echo "ALSA-Info script has been downloaded $SHFILE." + echo "Please, re-run it from new location." + fi + exit + fi + else + rm $SHFILE 2>/dev/null + fi +} + +cleanup() { + if [ -n "$TEMPDIR" -a "$KEEP_FILES" != "yes" ]; then + rm -rf "$TEMPDIR" 2>/dev/null + fi + test -n "$KEEP_OUTPUT" || rm -f "$NFILE" +} + + +withaplay() { + echo "!!Aplay/Arecord output" >> $FILE + echo "!!------------" >> $FILE + echo "" >> $FILE + echo "APLAY" >> $FILE + echo "" >> $FILE + aplay -l >> $FILE 2>&1 + echo "" >> $FILE + echo "ARECORD" >> $FILE + echo "" >> $FILE + arecord -l >> $FILE 2>&1 + echo "" >> $FILE +} + +withlsmod() { + echo "!!All Loaded Modules" >> $FILE + echo "!!------------------" >> $FILE + echo "" >> $FILE + lsmod |awk {'print $1'} >> $FILE + echo "" >> $FILE + echo "" >> $FILE +} + +withamixer() { + echo "!!Amixer output" >> $FILE + echo "!!-------------" >> $FILE + echo "" >> $FILE + for i in `grep "]: " /proc/asound/cards | awk -F ' ' '{ print $1} '` ; do + CARD_NAME=`grep "^ *$i " $TEMPDIR/alsacards.tmp|awk {'print $2'}` + echo "!!-------Mixer controls for card $i $CARD_NAME]" >> $FILE + echo "" >>$FILE + amixer -c$i info>> $FILE 2>&1 + amixer -c$i>> $FILE 2>&1 + echo "" >> $FILE + done + echo "" >> $FILE +} + +withalsactl() { + echo "!!Alsactl output" >> $FILE + echo "!!-------------" >> $FILE + echo "" >> $FILE + exe="" + if [ -x /usr/sbin/alsactl ]; then + exe="/usr/sbin/alsactl" + fi + if [ -x /usr/local/sbin/alsactl ]; then + exe="/usr/local/sbin/alsactl" + fi + if [ -z "$exe" ]; then + exe=`whereis alsactl | cut -d ' ' -f 2` + fi + $exe -f $TEMPDIR/alsactl.tmp store + echo "--startcollapse--" >> $FILE + cat $TEMPDIR/alsactl.tmp >> $FILE + echo "--endcollapse--" >> $FILE + echo "" >> $FILE + echo "" >> $FILE +} + +withdevices() { + echo "!!ALSA Device nodes" >> $FILE + echo "!!-----------------" >> $FILE + echo "" >> $FILE + ls -la /dev/snd/* >> $FILE + echo "" >> $FILE + echo "" >> $FILE +} + +withconfigs() { +if [[ -e $HOME/.asoundrc ]] || [[ -e /etc/asound.conf ]] || [[ -e $HOME/.asoundrc.asoundconf ]] +then + echo "!!ALSA configuration files" >> $FILE + echo "!!------------------------" >> $FILE + echo "" >> $FILE + + #Check for ~/.asoundrc + if [[ -e $HOME/.asoundrc ]] + then + echo "!!User specific config file (~/.asoundrc)" >> $FILE + echo "" >> $FILE + cat $HOME/.asoundrc >> $FILE + echo "" >> $FILE + echo "" >> $FILE + fi + #Check for .asoundrc.asoundconf (seems to be Ubuntu specific) + if [[ -e $HOME/.asoundrc.asoundconf ]] + then + echo "!!asoundconf-generated config file" >> $FILE + echo "" >> $FILE + cat $HOME/.asoundrc.asoundconf >> $FILE + echo "" >> $FILE + echo "" >> $FILE + fi + #Check for /etc/asound.conf + if [[ -e /etc/asound.conf ]] + then + echo "!!System wide config file (/etc/asound.conf)" >> $FILE + echo "" >> $FILE + cat /etc/asound.conf >> $FILE + echo "" >> $FILE + echo "" >> $FILE + fi +fi +} + +withsysfs() { + local i f + local printed="" + for i in /sys/class/sound/*; do + case "$i" in + */hwC?D?) + if [ -f $i/init_pin_configs ]; then + if [ -z "$printed" ]; then + echo "!!Sysfs Files" >> $FILE + echo "!!-----------" >> $FILE + echo "" >> $FILE + fi + for f in init_pin_configs driver_pin_configs user_pin_configs init_verbs; do + echo "$i/$f:" >> $FILE + cat $i/$f >> $FILE + echo >> $FILE + done + printed=yes + fi + ;; + esac + done + if [ -n "$printed" ]; then + echo "" >> $FILE + fi +} + +withdmesg() { + echo "!!ALSA/HDA dmesg" >> $FILE + echo "!!------------------" >> $FILE + echo "" >> $FILE + dmesg | grep -C1 -E 'ALSA|HDA|HDMI|sound|hda.codec|hda.intel' >> $FILE + echo "" >> $FILE + echo "" >> $FILE +} + +withall() { + withdevices + withconfigs + withaplay + withamixer + withalsactl + withlsmod + withsysfs + withdmesg +} + +get_alsa_library_version() { + ALSA_LIB_VERSION=`grep VERSION_STR /usr/include/alsa/version.h 2>/dev/null|awk {'print $3'}|sed 's/"//g'` + + if [ -z "$ALSA_LIB_VERSION" ]; then + if [ -f /etc/lsb-release ]; then + . /etc/lsb-release + case "$DISTRIB_ID" in + Ubuntu) + if which dpkg > /dev/null ; then + ALSA_LIB_VERSION=`dpkg -l libasound2 | tail -1 | awk '{print $3}' | cut -f 1 -d -` + fi + + if [ "$ALSA_LIB_VERSION" = "" ]; then + ALSA_LIB_VERSION="" + fi + return + ;; + *) + return + ;; + esac + elif [ -f /etc/debian_version ]; then + if which dpkg > /dev/null ; then + ALSA_LIB_VERSION=`dpkg -l libasound2 | tail -1 | awk '{print $3}' | cut -f 1 -d -` + fi + + if [ "$ALSA_LIB_VERSION" = "" ]; then + ALSA_LIB_VERSION="" + fi + return + fi + fi +} + + +#Run checks to make sure the programs we need are installed. +LSPCI=$(which lspci 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null); +TPUT=$(which tput 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null); +DIALOG=$(which dialog 2>/dev/null | sed 's|^[^/]*||' 2>/dev/null); + +#Check to see if sysfs is enabled in the kernel. We'll need this later on +SYSFS=$(mount |grep sysfs|awk {'print $3'}); + +#Check modprobe config files for sound related options +SNDOPTIONS=$(modprobe -c|sed -n 's/^options \(snd[-_][^ ]*\)/\1:/p') + +KEEP_OUTPUT= +NFILE="" + +PASTEBIN="" +WWWSERVICE="www.alsa-project.org" +WELCOME="yes" +PROCEED="yes" +UPLOAD="ask" +REPEAT="" +while [ -z "$REPEAT" ]; do +REPEAT="no" +case "$1" in + --update|--help|--about) + WELCOME="no" + PROCEED="no" + ;; + --upload) + UPLOAD="yes" + WELCOME="no" + ;; + --no-upload) + UPLOAD="no" + WELCOME="no" + ;; + --pastebin) + PASTEBIN="yes" + WWWSERVICE="pastebin" + ;; + --no-dialog) + DIALOG="" + REPEAT="" + shift + ;; + --stdout) + DIALOG="" + UPLOAD="no" + WELCOME="no" + TOSTDOUT="yes" + ;; +esac +done + + +#Script header output. +if [ "$WELCOME" = "yes" ]; then +greeting_message="\ + +This script visits the following commands/files to collect diagnostic +information about your ALSA installation and sound related hardware. + + dmesg + lspci + lsmod + aplay + amixer + alsactl + /proc/asound/ + /sys/class/sound/ + ~/.asoundrc (etc.) + +See '$0 --help' for command line options. +" +if [[ -n "$DIALOG" ]]; then + dialog --backtitle "$BGTITLE" \ + --title "ALSA-Info script v $SCRIPT_VERSION" \ + --msgbox "$greeting_message" 20 80 +else + echo "ALSA Information Script v $SCRIPT_VERSION" + echo "--------------------------------" + echo "$greeting_message" +fi # dialog +fi # WELCOME + +#Set the output file +TEMPDIR=`mktemp -t -d alsa-info.XXXXXXXXXX` || exit 1 +FILE="$TEMPDIR/alsa-info.txt" +if [ -z "$NFILE" ]; then + NFILE=`mktemp -t alsa-info.txt.XXXXXXXXXX` || exit 1 +fi + +trap cleanup 0 + +if [ "$PROCEED" = "yes" ]; then + +if [[ -z "$LSPCI" ]] +then + echo "This script requires lspci. Please install it, and re-run this script." + exit 0 +fi + +#Fetch the info and store in temp files/variables +DISTRO=`grep -ihs "buntu\|SUSE\|Fedora\|PCLinuxOS\|MEPIS\|Mandriva\|Debian\|Damn\|Sabayon\|Slackware\|KNOPPIX\|Gentoo\|Zenwalk\|Mint\|Kubuntu\|FreeBSD\|Puppy\|Freespire\|Vector\|Dreamlinux\|CentOS\|Arch\|Xandros\|Elive\|SLAX\|Red\|BSD\|KANOTIX\|Nexenta\|Foresight\|GeeXboX\|Frugalware\|64\|SystemRescue\|Novell\|Solaris\|BackTrack\|KateOS\|Pardus" /etc/{issue,*release,*version}` +KERNEL_VERSION=`uname -r` +KERNEL_PROCESSOR=`uname -p` +KERNEL_MACHINE=`uname -m` +KERNEL_OS=`uname -o` +[[ `uname -v |grep SMP` ]] && KERNEL_SMP="Yes" || KERNEL_SMP="No" +ALSA_DRIVER_VERSION=`cat /proc/asound/version |head -n1|awk {'print $7'} |sed 's/\.$//'` +get_alsa_library_version +ALSA_UTILS_VERSION=`amixer -v |awk {'print $3'}` +VENDOR_ID=`lspci -vn |grep 040[1-3] | awk -F':' '{print $3}'|awk {'print substr($0, 2);}' >$TEMPDIR/vendor_id.tmp` +DEVICE_ID=`lspci -vn |grep 040[1-3] | awk -F':' '{print $4}'|awk {'print $1'} >$TEMPDIR/device_id.tmp` +LAST_CARD=$((`grep "]: " /proc/asound/cards | wc -l` - 1 )) + +ESDINST=$(which esd 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null) +PAINST=$(which pulseaudio 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null) +ARTSINST=$(which artsd 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null) +JACKINST=$(which jackd 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null) +DMIDECODE=$(which dmidecode 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null) + +#Check for DMI data +if [ -d /sys/class/dmi/id ]; then + # No root privileges are required when using sysfs method + DMI_SYSTEM_MANUFACTURER=$(cat /sys/class/dmi/id/sys_vendor 2>/dev/null) + DMI_SYSTEM_PRODUCT_NAME=$(cat /sys/class/dmi/id/product_name 2>/dev/null) + DMI_SYSTEM_PRODUCT_VERSION=$(cat /sys/class/dmi/id/product_version 2>/dev/null) +elif [ -x $DMIDECODE ]; then + DMI_SYSTEM_MANUFACTURER=$($DMIDECODE -s system-manufacturer 2>/dev/null) + DMI_SYSTEM_PRODUCT_NAME=$($DMIDECODE -s system-product-name 2>/dev/null) + DMI_SYSTEM_PRODUCT_VERSION=$($DMIDECODE -s system-version 2>/dev/null) +fi + +cat /proc/asound/modules 2>/dev/null|awk {'print $2'}>$TEMPDIR/alsamodules.tmp +cat /proc/asound/cards >$TEMPDIR/alsacards.tmp +lspci |grep -i "multi\|audio">$TEMPDIR/lspci.tmp + +#Check for HDA-Intel cards codec#* +cat /proc/asound/card*/codec\#* > $TEMPDIR/alsa-hda-intel.tmp 2> /dev/null + +#Check for AC97 cards codec +cat /proc/asound/card*/codec97\#0/ac97\#0-0 > $TEMPDIR/alsa-ac97.tmp 2> /dev/null +cat /proc/asound/card*/codec97\#0/ac97\#0-0+regs > $TEMPDIR/alsa-ac97-regs.tmp 2> /dev/null + +#Check for USB mixer setup +cat /proc/asound/card*/usbmixer > $TEMPDIR/alsa-usbmixer.tmp 2> /dev/null + +#Fetch the info, and put it in $FILE in a nice readable format. +if [[ -z $PASTEBIN ]]; then +echo "upload=true&script=true&cardinfo=" > $FILE +else +echo "name=$USER&type=33&description=/tmp/alsa-info.txt&expiry=&s=Submit+Post&content=" > $FILE +fi +echo "!!################################" >> $FILE +echo "!!ALSA Information Script v $SCRIPT_VERSION" >> $FILE +echo "!!################################" >> $FILE +echo "" >> $FILE +echo "!!Script ran on: `LANG=C TZ=UTC date`" >> $FILE +echo "" >> $FILE +echo "" >> $FILE +echo "!!Linux Distribution" >> $FILE +echo "!!------------------" >> $FILE +echo "" >> $FILE +echo $DISTRO >> $FILE +echo "" >> $FILE +echo "" >> $FILE +echo "!!DMI Information" >> $FILE +echo "!!---------------" >> $FILE +echo "" >> $FILE +echo "Manufacturer: $DMI_SYSTEM_MANUFACTURER" >> $FILE +echo "Product Name: $DMI_SYSTEM_PRODUCT_NAME" >> $FILE +echo "Product Version: $DMI_SYSTEM_PRODUCT_VERSION" >> $FILE +echo "" >> $FILE +echo "" >> $FILE +echo "!!Kernel Information" >> $FILE +echo "!!------------------" >> $FILE +echo "" >> $FILE +echo "Kernel release: $KERNEL_VERSION" >> $FILE +echo "Operating System: $KERNEL_OS" >> $FILE +echo "Architecture: $KERNEL_MACHINE" >> $FILE +echo "Processor: $KERNEL_PROCESSOR" >> $FILE +echo "SMP Enabled: $KERNEL_SMP" >> $FILE +echo "" >> $FILE +echo "" >> $FILE +echo "!!ALSA Version" >> $FILE +echo "!!------------" >> $FILE +echo "" >> $FILE +echo "Driver version: $ALSA_DRIVER_VERSION" >> $FILE +echo "Library version: $ALSA_LIB_VERSION" >> $FILE +echo "Utilities version: $ALSA_UTILS_VERSION" >> $FILE +echo "" >> $FILE +echo "" >> $FILE +echo "!!Loaded ALSA modules" >> $FILE +echo "!!-------------------" >> $FILE +echo "" >> $FILE +cat $TEMPDIR/alsamodules.tmp >> $FILE +echo "" >> $FILE +echo "" >> $FILE +echo "!!Sound Servers on this system" >> $FILE +echo "!!----------------------------" >> $FILE +echo "" >> $FILE +if [[ -n $PAINST ]];then +[[ `pgrep '^(.*/)?pulseaudio$'` ]] && PARUNNING="Yes" || PARUNNING="No" +echo "Pulseaudio:" >> $FILE +echo " Installed - Yes ($PAINST)" >> $FILE +echo " Running - $PARUNNING" >> $FILE +echo "" >> $FILE +fi +if [[ -n $ESDINST ]];then +[[ `pgrep '^(.*/)?esd$'` ]] && ESDRUNNING="Yes" || ESDRUNNING="No" +echo "ESound Daemon:" >> $FILE +echo " Installed - Yes ($ESDINST)" >> $FILE +echo " Running - $ESDRUNNING" >> $FILE +echo "" >> $FILE +fi +if [[ -n $ARTSINST ]];then +[[ `pgrep '^(.*/)?artsd$'` ]] && ARTSRUNNING="Yes" || ARTSRUNNING="No" +echo "aRts:" >> $FILE +echo " Installed - Yes ($ARTSINST)" >> $FILE +echo " Running - $ARTSRUNNING" >> $FILE +echo "" >> $FILE +fi +if [[ -n $JACKINST ]];then +[[ `pgrep '^(.*/)?jackd$'` ]] && JACKRUNNING="Yes" || JACKRUNNING="No" +echo "Jack:" >> $FILE +echo " Installed - Yes ($JACKINST)" >> $FILE +echo " Running - $JACKRUNNING" >> $FILE +echo "" >> $FILE +fi +if [[ -z "$PAINST" && -z "$ESDINST" && -z "$ARTSINST" && -z "$JACKINST" ]];then +echo "No sound servers found." >> $FILE +echo "" >> $FILE +fi +echo "" >> $FILE +echo "!!Soundcards recognised by ALSA" >> $FILE +echo "!!-----------------------------" >> $FILE +echo "" >> $FILE +cat $TEMPDIR/alsacards.tmp >> $FILE +echo "" >> $FILE +echo "" >> $FILE +echo "!!PCI Soundcards installed in the system" >> $FILE +echo "!!--------------------------------------" >> $FILE +echo "" >> $FILE +cat $TEMPDIR/lspci.tmp >> $FILE +echo "" >> $FILE +echo "" >> $FILE +echo "!!Advanced information - PCI Vendor/Device/Subsystem ID's" >> $FILE +echo "!!--------------------------------------------------------" >> $FILE +echo "" >> $FILE +lspci -vvn |grep -A1 040[1-3] >> $FILE +echo "" >> $FILE +echo "" >> $FILE + +if [ "$SNDOPTIONS" ] +then +echo "!!Modprobe options (Sound related)" >> $FILE +echo "!!--------------------------------" >> $FILE +echo "" >> $FILE +modprobe -c|sed -n 's/^options \(snd[-_][^ ]*\)/\1:/p' >> $FILE +echo "" >> $FILE +echo "" >> $FILE +fi + +if [ -d "$SYSFS" ] +then +echo "!!Loaded sound module options" >> $FILE +echo "!!--------------------------" >> $FILE +echo "" >> $FILE +for mod in `cat /proc/asound/modules|awk {'print $2'}`;do +echo "!!Module: $mod" >> $FILE +for params in `echo $SYSFS/module/$mod/parameters/*`; do + echo -ne "\t"; + echo "$params : `cat $params`" | sed 's:.*/::'; +done >> $FILE +echo "" >> $FILE +done +echo "" >> $FILE +fi + +if [ -s "$TEMPDIR/alsa-hda-intel.tmp" ] +then + echo "!!HDA-Intel Codec information" >> $FILE + echo "!!---------------------------" >> $FILE + echo "--startcollapse--" >> $FILE + echo "" >> $FILE + cat $TEMPDIR/alsa-hda-intel.tmp >> $FILE + echo "--endcollapse--" >> $FILE + echo "" >> $FILE + echo "" >> $FILE +fi + +if [ -s "$TEMPDIR/alsa-ac97.tmp" ] +then + echo "!!AC97 Codec information" >> $FILE + echo "!!---------------------------" >> $FILE + echo "--startcollapse--" >> $FILE + echo "" >> $FILE + cat $TEMPDIR/alsa-ac97.tmp >> $FILE + echo "" >> $FILE + cat $TEMPDIR/alsa-ac97-regs.tmp >> $FILE + echo "--endcollapse--" >> $FILE + echo "" >> $FILE + echo "" >> $FILE +fi + +if [ -s "$TEMPDIR/alsa-usbmixer.tmp" ] +then + echo "!!USB Mixer information" >> $FILE + echo "!!---------------------------" >> $FILE + echo "--startcollapse--" >> $FILE + echo "" >> $FILE + cat $TEMPDIR/alsa-usbmixer.tmp >> $FILE + echo "--endcollapse--" >> $FILE + echo "" >> $FILE + echo "" >> $FILE +fi + +#If no command line options are specified, then run as though --with-all was specified +if [[ -z "$1" ]] +then + update + withall + pbcheck +fi + +fi # proceed + +#loop through command line arguments, until none are left. +if [[ -n "$1" ]] +then + until [ -z "$1" ] + do + case "$1" in + --pastebin) + update + withall + pbcheck + ;; + --update) + update + exit + ;; + --upload) + UPLOAD="yes" + withall + ;; + --no-upload) + UPLOAD="no" + withall + ;; + --output) + shift + NFILE="$1" + KEEP_OUTPUT="yes" + ;; + --debug) + echo "Debugging enabled. $FILE and $TEMPDIR will not be deleted" + KEEP_FILES="yes" + echo "" + withall + ;; + --with-all) + withall + ;; + --with-aplay) + withaplay + ;; + --with-amixer) + withamixer + ;; + --with-alsactl) + withalsactl + ;; + --with-devices) + withdevices + ;; + --with-dmesg) + withdmesg + ;; + --with-configs) + if [[ -e $HOME/.asoundrc ]] || [[ -e /etc/asound.conf ]] + then + echo "!!ALSA configuration files" >> $FILE + echo "!!------------------------" >> $FILE + echo "" >> $FILE + + #Check for ~/.asoundrc + if [[ -e $HOME/.asoundrc ]] + then + echo "!!User specific config file ($HOME/.asoundrc)" >> $FILE + echo "" >> $FILE + cat $HOME/.asoundrc >> $FILE + echo "" >> $FILE + echo "" >> $FILE + fi + + #Check for /etc/asound.conf + if [[ -e /etc/asound.conf ]] + then + echo "!!System wide config file (/etc/asound.conf)" >> $FILE + echo "" >> $FILE + cat /etc/asound.conf >> $FILE + echo "" >> $FILE + echo "" >> $FILE + fi + fi + ;; + --stdout) + UPLOAD="no" + withall + cat $FILE + rm $FILE + ;; + --about) + echo "Written/Tested by the following users of #alsa on irc.freenode.net:" + echo "" + echo " wishie - Script author and developer / Testing" + echo " crimsun - Various script ideas / Testing" + echo " gnubien - Various script ideas / Testing" + echo " GrueMaster - HDA Intel specific items / Testing" + echo " olegfink - Script update function" + echo " TheMuso - display to stdout functionality" + exit 0 + ;; + *) + echo "alsa-info.sh version $SCRIPT_VERSION" + echo "" + echo "Available options:" + echo " --with-aplay (includes the output of aplay -l)" + echo " --with-amixer (includes the output of amixer)" + echo " --with-alsactl (includes the output of alsactl)" + echo " --with-configs (includes the output of ~/.asoundrc and" + echo " /etc/asound.conf if they exist)" + echo " --with-devices (shows the device nodes in /dev/snd/)" + echo " --with-dmesg (shows the ALSA/HDA kernel messages)" + echo "" + echo " --output FILE (specify the file to output for no-upload mode)" + echo " --update (check server for script updates)" + echo " --upload (upload contents to remote server)" + echo " --no-upload (do not upload contents to remote server)" + echo " --pastebin (use http://pastebin.ca) as remote server" + echo " instead www.alsa-project.org" + echo " --stdout (print alsa information to standard output" + echo " instead of a file)" + echo " --about (show some information about the script)" + echo " --debug (will run the script as normal, but will not" + echo " delete $FILE)" + exit 0 + ;; + esac + shift 1 + done +fi + +if [ "$PROCEED" = "no" ]; then + exit 1 +fi + +if [ "$UPLOAD" = "ask" ]; then + if [[ -n "$DIALOG" ]]; then + dialog --backtitle "$BGTITLE" --title "Information collected" --yes-label " UPLOAD / SHARE " --no-label " SAVE LOCALLY " --defaultno --yesno "\n\nAutomatically upload ALSA information to $WWWSERVICE?" 10 80 + DIALOG_EXIT_CODE=$? + if [ $DIALOG_EXIT_CODE != 0 ]; then + UPLOAD="no" + else + UPLOAD="yes" + fi + else + echo -n "Automatically upload ALSA information to $WWWSERVICE? [y/N] : " + read -e CONFIRM + if [ "$CONFIRM" != "y" ]; then + UPLOAD="no" + else + UPLOAD="yes" + fi + fi + +fi + +if [ "$UPLOAD" = "no" ]; then + + if [ -z "$TOSTDOUT" ]; then + mv -f $FILE $NFILE || exit 1 + KEEP_OUTPUT="yes" + fi + + if [[ -n $DIALOG ]] + then + if [[ -n $PBERROR ]]; then + dialog --backtitle "$BGTITLE" --title "Information collected" --msgbox "An error occurred while contacting the $WWWSERVICE.\n Your information was NOT automatically uploaded.\n\nYour ALSA information is in $NFILE" 10 100 + else + dialog --backtitle "$BGTITLE" --title "Information collected" --msgbox "\n\nYour ALSA information is in $NFILE" 10 60 + fi + else + echo + + if [[ -n $PBERROR ]]; then + echo "An error occurred while contacting the $WWWSERVICE." + echo "Your information was NOT automatically uploaded." + echo "" + echo "Your ALSA information is in $NFILE" + echo "" + else + if [ -z "$TOSTDOUT" ]; then + echo "" + echo "Your ALSA information is in $NFILE" + echo "" + fi + fi + fi + + exit + +fi # UPLOAD + +#Test that wget is installed, and supports --post-file. Upload $FILE if it does, and prompt user to upload file if it doesnt. +if +WGET=$(which wget 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null); [[ -n "${WGET}" ]] && [[ -x "${WGET}" ]] && [[ `wget --help |grep post-file` ]] +then + +if [[ -n $DIALOG ]] +then + +if [[ -z $PASTEBIN ]]; then + wget -O - --tries=5 --timeout=60 --post-file=$FILE "http://www.alsa-project.org/cardinfo-db/" &>$TEMPDIR/wget.tmp || echo "Upload failed; exit" + { for i in 10 20 30 40 50 60 70 80 90; do + echo $i + sleep 0.2 + done + echo; } |dialog --backtitle "$BGTITLE" --guage "Uploading information to www.alsa-project.org ..." 6 70 0 +else + wget -O - --tries=5 --timeout=60 --post-file=$FILE "http://pastebin.ca/quiet-paste.php?api=$PASTEBINKEY&encrypt=t&encryptpw=blahblah" &>$TEMPDIR/wget.tmp || echo "Upload failed; exit" + { for i in 10 20 30 40 50 60 70 80 90; do + echo $i + sleep 0.2 + done + echo; } |dialog --backtitle "$BGTITLE" --guage "Uploading information to www.pastebin.ca ..." 6 70 0 +fi + +dialog --backtitle "$BGTITLE" --title "Information uploaded" --yesno "Would you like to see the uploaded information?" 5 100 +DIALOG_EXIT_CODE=$? +if [ $DIALOG_EXIT_CODE = 0 ]; then + grep -v "alsa-info.txt" $FILE >$TEMPDIR/uploaded.txt + dialog --backtitle "$BGTITLE" --textbox $TEMPDIR/uploaded.txt 0 0 +fi + +clear + +# no dialog +else + +if [[ -z $PASTEBIN ]]; then + echo -n "Uploading information to www.alsa-project.org ... " + wget -O - --tries=5 --timeout=60 --post-file=$FILE http://www.alsa-project.org/cardinfo-db/ &>$TEMPDIR/wget.tmp & +else + echo -n "Uploading information to www.pastebin.ca ... " + wget -O - --tries=5 --timeout=60 --post-file=$FILE http://pastebin.ca/quiet-paste.php?api=$PASTEBINKEY &>$TEMPDIR/wget.tmp & +fi + +#Progess spinner for wget transfer. +i=1 +sp="/-\|" +echo -n ' ' +while pgrep wget &>/dev/null +do + echo -en "\b${sp:i++%${#sp}:1}" +done + +echo -e "\b Done!" +echo "" + +fi #dialog + +#See if tput is available, and use it if it is. +if [[ -n "$TPUT" ]] +then + if [[ -z $PASTEBIN ]]; then + FINAL_URL=`tput setaf 1; grep "SUCCESS:" $TEMPDIR/wget.tmp | cut -d ' ' -f 2 ; tput sgr0` + else + FINAL_URL=`tput setaf 1; grep "SUCCESS:" $TEMPDIR/wget.tmp |sed -n 's/.*\:\([0-9]\+\).*/http:\/\/pastebin.ca\/\1/p';tput sgr0` + fi +else + if [[ -z $PASTEBIN ]]; then + FINAL_URL=`grep "SUCCESS:" $TEMPDIR/wget.tmp | cut -d ' ' -f 2` + else + FINAL_URL=`grep "SUCCESS:" $TEMPDIR/wget.tmp |sed -n 's/.*\:\([0-9]\+\).*/http:\/\/pastebin.ca\/\1/p'` + fi +fi + +#Output the URL of the uploaded file. +echo "Your ALSA information is located at $FINAL_URL" +echo "Please inform the person helping you." +echo "" + +#We couldnt find a suitable wget, so tell the user to upload manually. +else + mv -f $FILE $NFILE || exit 1 + KEEP_OUTPUT="yes" + if [[ -z $DIALOG ]] + then + if [[ -z $PASTEBIN ]]; then + echo "" + echo "Could not automatically upload output to http://www.alsa-project.org" + echo "Possible reasons are:" + echo " 1. Couldnt find 'wget' in your PATH" + echo " 2. Your version of wget is less than 1.8.2" + echo "" + echo "Please manually upload $NFILE to http://www.alsa-project.org/cardinfo-db/ and submit your post." + echo "" + else + echo "" + echo "Could not automatically upload output to http://www.pastebin.ca" + echo "Possible reasons are:" + echo " 1. Couldnt find 'wget' in your PATH" + echo " 2. Your version of wget is less than 1.8.2" + echo "" + echo "Please manually upload $NFILE to http://www.pastebin.ca/upload.php and submit your post." + echo "" + fi + else + if [[ -z $PASTEBIN ]]; then + dialog --backtitle "$BGTITLE" --msgbox "Could not automatically upload output to http://www.alsa-project.org.\nPossible reasons are:\n\n 1. Couldn't find 'wget' in your PATH\n 2. Your version of wget is less than 1.8.2\n\nPlease manually upload $NFILE to http://www.alsa-project,org/cardinfo-db/ and submit your post." 25 100 + else + dialog --backtitle "$BGTITLE" --msgbox "Could not automatically upload output to http://www.pastebin.ca.\nPossible reasons are:\n\n 1. Couldn't find 'wget' in your PATH\n 2. Your version of wget is less than 1.8.2\n\nPlease manually upload $NFILE to http://www.pastebin.ca/upload.php and submit your post." 25 100 + fi + fi +fi + + diff --git a/ansi2html.sh b/ansi2html.sh new file mode 100755 index 0000000..0b02d57 --- /dev/null +++ b/ansi2html.sh @@ -0,0 +1,331 @@ +#!/bin/sh + +# Convert ANSI (terminal) colours and attributes to HTML + +# Author: +# http://www.pixelbeat.org/docs/terminal_colours/ +# Examples: +# ls -l --color=always | ansi2html.sh > ls.html +# git show --color | ansi2html.sh > last_change.html +# Generally one can use the `script` util to capture full terminal output. +# Changes: +# V0.1, 24 Apr 2008, Initial release +# V0.2, 01 Jan 2009, Phil Harnish +# Support `git diff --color` output by +# matching ANSI codes that specify only +# bold or background colour. +# P@draigBrady.com +# Support `ls --color` output by stripping +# redundant leading 0s from ANSI codes. +# Support `grep --color=always` by stripping +# unhandled ANSI codes (specifically ^[[K). +# V0.3, 20 Mar 2009, http://eexpress.blog.ubuntu.org.cn/ +# Remove cat -v usage which mangled non ascii input. +# Cleanup regular expressions used. +# Support other attributes like reverse, ... +# P@draigBrady.com +# Correctly nest tags (even across lines). +# Add a command line option to use a dark background. +# Strip more terminal control codes. +# V0.4, 17 Sep 2009, P@draigBrady.com +# Handle codes with combined attributes and color. +# Handle isolated attributes with css. +# Strip more terminal control codes. +# V0.12, 12 Jul 2011 +# http://github.com/pixelb/scripts/commits/master/scripts/ansi2html.sh + +if [ "$1" = "--version" ]; then + echo "0.12" && exit +fi + +if [ "$1" = "--help" ]; then + echo "This utility converts ANSI codes in data passed to stdin" >&2 + echo "It has 2 optional parameters:" >&2 + echo " --bg=dark --palette=linux|solarized|tango|xterm" >&2 + echo "E.g.: ls -l --color=always | ansi2html.sh --bg=dark > ls.html" >&2 + exit +fi + +[ "$1" = "--bg=dark" ] && { dark_bg=yes; shift; } + +if [ "$1" = "--palette=solarized" ]; then + # See http://ethanschoonover.com/solarized + P0=073642; P1=D30102; P2=859900; P3=B58900; + P4=268BD2; P5=D33682; P6=2AA198; P7=EEE8D5; + P8=002B36; P9=CB4B16; P10=586E75; P11=657B83; + P12=839496; P13=6C71C4; P14=93A1A1; P15=FDF6E3; + shift; +elif [ "$1" = "--palette=solarized-xterm" ]; then + # Above mapped onto the xterm 256 color palette + P0=262626; P1=AF0000; P2=5F8700; P3=AF8700; + P4=0087FF; P5=AF005F; P6=00AFAF; P7=E4E4E4; + P8=1C1C1C; P9=D75F00; P10=585858; P11=626262; + P12=808080; P13=5F5FAF; P14=8A8A8A; P15=FFFFD7; + shift; +elif [ "$1" = "--palette=tango" ]; then + # Gnome default + P0=000000; P1=CC0000; P2=4E9A06; P3=C4A000; + P4=3465A4; P5=75507B; P6=06989A; P7=D3D7CF; + P8=555753; P9=EF2929; P10=8AE234; P11=FCE94F; + P12=729FCF; P13=AD7FA8; P14=34E2E2; P15=EEEEEC; + shift; +elif [ "$1" = "--palette=xterm" ]; then + P0=000000; P1=CD0000; P2=00CD00; P3=CDCD00; + P4=0000EE; P5=CD00CD; P6=00CDCD; P7=E5E5E5; + P8=7F7F7F; P9=FF0000; P10=00FF00; P11=FFFF00; + P12=5C5CFF; P13=FF00FF; P14=00FFFF; P15=FFFFFF; + shift; +else # linux console + P0=000000; P1=AA0000; P2=00AA00; P3=AA5500; + P4=0000AA; P5=AA00AA; P6=00AAAA; P7=AAAAAA; + P8=555555; P9=FF5555; P10=55FF55; P11=FFFF55; + P12=5555FF; P13=FF55FF; P14=55FFFF; P15=FFFFFF; + [ "$1" = "--palette=linux" ] && shift +fi + +[ "$1" = "--bg=dark" ] && { dark_bg=yes; shift; } + +echo -n " + + + + + + +
+'
+
+p='\x1b\['        #shortcut to match escape codes
+P="\(^[^°]*\)¡$p" #expression to match prepended codes below
+
+# Handle various xterm control sequences.
+# See /usr/share/doc/xterm-*/ctlseqs.txt
+sed "
+s#\x1b[^\x1b]*\x1b\\\##g  # strip anything between \e and ST
+s#\x1b][0-9]*;[^\a]*\a##g # strip any OSC (xterm title etc.)
+
+#handle carriage returns
+s#^.*\r\{1,\}\([^$]\)#\1#
+s#\r\$## # strip trailing \r
+
+# strip other non SGR escape sequences
+s#[\x07]##g
+s#\x1b[]>=\][0-9;]*##g
+s#\x1bP+.\{5\}##g
+s#${p}[0-9;?]*[^0-9;?m]##g
+
+#remove backspace chars and what they're backspacing over
+:rm_bs
+s#[^\x08]\x08##g; t rm_bs
+" |
+
+# Normalize the input before transformation
+sed "
+# escape HTML
+s#\&#\&#g; s#>#\>#g; s#<#\<#g; s#\"#\"#g
+
+# normalize SGR codes a little
+
+# split 256 colors out and mark so that they're not
+# recognised by the following 'split combined' line
+:e
+s#${p}\([0-9;]\{1,\}\);\([34]8;5;[0-9]\{1,3\}\)m#${p}\1m${p}¬\2m#g; t e
+s#${p}\([34]8;5;[0-9]\{1,3\}\)m#${p}¬\1m#g;
+
+:c
+s#${p}\([0-9]\{1,\}\);\([0-9;]\{1,\}\)m#${p}\1m${p}\2m#g; t c   # split combined
+s#${p}0\([0-7]\)#${p}\1#g                                 #strip leading 0
+s#${p}1m\(\(${p}[4579]m\)*\)#\1${p}1m#g                   #bold last (with clr)
+s#${p}m#${p}0m#g                                          #add leading 0 to norm
+
+# undo any 256 color marking
+s#${p}¬\([34]8;5;[0-9]\{1,3\}\)m#${p}\1m#g;
+
+# map 16 color codes to color + bold
+s#${p}9\([0-7]\)m#${p}3\1m${p}1m#g;
+s#${p}10\([0-7]\)m#${p}4\1m${p}1m#g;
+
+# change 'reset' code to a single char, and prepend a single char to
+# other codes so that we can easily do negative matching, as sed
+# does not support look behind expressions etc.
+s#°#\°#g; s#${p}0m#°#g
+s#¡#\¡#g; s#${p}[0-9;]*m#¡&#g
+" |
+
+# Convert SGR sequences to HTML
+sed "
+:ansi_to_span # replace ANSI codes with CSS classes
+t ansi_to_span # hack so t commands below only apply to preceeding s cmd
+
+/^[^¡]*°/ { b span_end } # replace 'reset code' if no preceeding code
+
+# common combinations to minimise html (optional)
+s#${P}3\([0-7]\)m¡${p}4\([0-7]\)m#\1#;t span_count
+s#${P}4\([0-7]\)m¡${p}3\([0-7]\)m#\1#;t span_count
+
+s#${P}1m#\1#;                            t span_count
+s#${P}4m#\1#;                       t span_count
+s#${P}5m#\1#;                           t span_count
+s#${P}7m#\1#;                         t span_count
+s#${P}9m#\1#;                    t span_count
+s#${P}3\([0-9]\)m#\1#;                    t span_count
+s#${P}4\([0-9]\)m#\1#;                    t span_count
+
+s#${P}38;5;\([0-9]\{1,3\}\)m#\1#;        t span_count
+s#${P}48;5;\([0-9]\{1,3\}\)m#\1#;        t span_count
+
+s#${P}[0-9;]*m#\1#g; t ansi_to_span # strip unhandled codes
+
+b # next line of input
+
+# add a corresponding span end flag
+:span_count
+x; s/^/s/; x
+b ansi_to_span
+
+# replace 'reset code' with correct number of  tags
+:span_end
+x
+/^s/ {
+  s/^.//
+  x
+  s#°#°#
+  b span_end
+}
+x
+s#°##
+b ansi_to_span
+" |
+
+# Convert alternative character set
+# Note we convert here, as if we do at start we have to worry about avoiding
+# conversion of SGR codes etc., whereas doing here we only have to
+# avoid conversions of stuff between &...; or <...>
+#
+# Note we could use sed to do this based around:
+#   sed 'y/abcdefghijklmnopqrstuvwxyz{}`~/▒␉␌␍␊°±␤␋┘┐┌└┼⎺⎻─⎼⎽├┤┴┬│≤≥π£◆·/'
+# However that would be very awkward as we need to only conv some input.
+# The basic scheme that we do in the python script below is:
+#  1. enable transliterate once ¡ char seen
+#  2. disable once µ char seen (may be on diff line to ¡)
+#  3. never transliterate between &; or <> chars
+sed "
+# change 'smacs' and 'rmacs' to a single char so that we can easily do
+# negative matching, as sed does not support look behind expressions etc.
+# Note we don't use ° like above as that's part of the alternate charset.
+s#\x1b(0#¡#g;
+s#µ#\µ#g; s#\x1b(B#µ#g
+" |
+(
+python -c "
+# vim:fileencoding=utf8
+
+import sys
+import locale
+encoding=locale.getpreferredencoding()
+
+old='abcdefghijklmnopqrstuvwxyz{}\`~'
+new='▒␉␌␍␊°±␤␋┘┐┌└┼⎺⎻─⎼⎽├┤┴┬│≤≥π£◆·'
+new=unicode(new, 'utf-8')
+table=range(128)
+for o,n in zip(old, new): table[ord(o)]=n
+
+(STANDARD, ALTERNATIVE, HTML_TAG, HTML_ENTITY) = (0, 1, 2, 3)
+
+state = STANDARD
+last_mode = STANDARD
+for c in unicode(sys.stdin.read(), encoding):
+  if state == HTML_TAG:
+    if c == '>':
+      state = last_mode
+  elif state == HTML_ENTITY:
+    if c == ';':
+      state = last_mode
+  else:
+    if c == '<':
+      state = HTML_TAG
+    elif c == '&':
+      state = HTML_ENTITY
+    elif c == u'¡' and state == STANDARD:
+      state = ALTERNATIVE
+      last_mode = ALTERNATIVE
+      continue
+    elif c == u'µ' and state == ALTERNATIVE:
+      state = STANDARD
+      last_mode = STANDARD
+      continue
+    elif state == ALTERNATIVE:
+      c = c.translate(table)
+  sys.stdout.write(c.encode(encoding))
+" 2>/dev/null ||
+sed 's/[¡µ]//g' # just strip aternative flag chars
+)
+
+echo "
+ +" diff --git a/apt-fast b/apt-fast new file mode 100755 index 0000000..9ceeac1 --- /dev/null +++ b/apt-fast @@ -0,0 +1,51 @@ +# !/bin/sh +# apt-fast v0.03 by Matt Parnell http://www.mattparnell.com, this thing is fully open-source +# if you do anything cool with it, let me know so I can publish or host it for you +# contact me at admin@mattparnell.com + +# Special thanks +# Travis/travisn000 - support for complex apt-get commands +# Allan Hoffmeister - aria2c support +# Abhishek Sharma - aria2c with proxy support +# Richard Klien - Autocompletion, Download Size Checking (made for on ubuntu, untested on other distros) +# Patrick Kramer Ruiz - suggestions - see Suggestions.txt +# Sergio Silva - test to see if axel is installed, root detection/sudo autorun + +# Use this just like apt-get for faster package downloading. + +# Check for proper priveliges +[ "`whoami`" = root ] || exec sudo "$0" "$@" + +# Test if the axel is installed +if [ ! -x /usr/bin/axel ] +then echo "axel is not installed, perform this?(y/n)" + read ops + case $ops in + y) if apt-get install axel -y --force-yes + then echo "axel installed" + else echo "unable to install the axel. you are using sudo?" ; exit + fi ;; + n) echo "not possible usage apt-fast" ; exit ;; + esac +fi + +# If the user entered arguments contain upgrade, install, or dist-upgrade +if echo "$@" | grep -q "upgrade\|install\|dist-upgrade"; then + echo "Working..."; + + # Go into the directory apt-get normally puts downloaded packages + cd /var/cache/apt/archives/; + + # Have apt-get print the information, including the URI's to the packages + # Strip out the URI's, and download the packages with Axel for speediness + # I found this regex elsewhere, showing how to manually strip package URI's you may need...thanks to whoever wrote it + apt-get -y --print-uris $@ | egrep -o -e "(ht|f)tp://[^\']+" > apt-fast.list && cat apt-fast.list | xargs -l1 axel -a + + # Perform the user's requested action via apt-get + apt-get $@; + + echo -e "\nDone! Verify that all packages were installed successfully. If errors are found, run apt-get clean as root and try again using apt-get directly.\n"; + +else + apt-get $@; +fi diff --git a/bluetooth-pan.sh b/bluetooth-pan.sh new file mode 100755 index 0000000..48b4c59 --- /dev/null +++ b/bluetooth-pan.sh @@ -0,0 +1,5 @@ +#!/bin/bash +sudo modprobe bnep +sudo pand --listen -c 78:CA:04:B7:9E:35 --role=NAP -n --persist +sudo ifconfig bnep0 +sudo ifup bnep0 diff --git a/calibre_cleanup.php b/calibre_cleanup.php new file mode 100755 index 0000000..c6cc3ef --- /dev/null +++ b/calibre_cleanup.php @@ -0,0 +1,22 @@ +#!/usr/bin/php +valid()){ + if (!$it->isDot()){ + $filename = $it->key(); + if(substr($filename,-6)=='.xhtml'){ + echo $filename."\n"; + $f = file($filename); + if(count($f)>10){ + if(strpos($f[10],"@namespace")!==false){ + $f[10]="
\n"; + $contents = join("",$f); + file_put_contents($filename,$contents); + echo "Updated\n"; + } + } + } + } + $it->next(); +} diff --git a/changed.sh b/changed.sh new file mode 100755 index 0000000..3013f30 --- /dev/null +++ b/changed.sh @@ -0,0 +1,3 @@ +#!/bin/sh +echo Search whole filesystem for changed files in the last $1 minutes +find /bin /dev /etc /home /lib /media /mnt /opt /root /sbin /srv /tmp /usr /var -cmin -$1 diff --git a/git-dude b/git-dude new file mode 120000 index 0000000..269b527 --- /dev/null +++ b/git-dude @@ -0,0 +1 @@ +/home/nemo/projects/~github/git-dude/git-dude \ No newline at end of file diff --git a/gmail.py b/gmail.py new file mode 100755 index 0000000..466b72d --- /dev/null +++ b/gmail.py @@ -0,0 +1,60 @@ +import mechanize +import cookielib +from BeautifulSoup import BeautifulSoup +import html2text + +# Browser +br = mechanize.Browser() + +# Cookie Jar +cj = cookielib.LWPCookieJar() +br.set_cookiejar(cj) + +# Browser options +br.set_handle_equiv(True) +br.set_handle_gzip(True) +br.set_handle_redirect(True) +br.set_handle_referer(True) +br.set_handle_robots(False) + +# Follows refresh 0 but not hangs on refresh > 0 +br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) + +# User-Agent (this is cheating, ok?) +br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] + +# The site we will navigate into, handling it's session +br.open('http://gmail.com') + +# Select the first (index zero) form +br.select_form(nr=0) + +# User credentials +br.form['Email'] = 'captn3m0' +br.form['Passwd'] = 'bot_add_ct Shark' + +# Login +br.submit() + +# Filter all links to mail messages in the inbox +all_msg_links = [l for l in br.links(url_regex='\?v=c&th=')] +# Select the first 3 messages +for msg_link in all_msg_links[0:3]: + print msg_link + # Open each message + br.follow_link(msg_link) + html = br.response().read() + soup = BeautifulSoup(html) + # Filter html to only show the message content + msg = str(soup.findAll('div', attrs={'class': 'msg'})[0]) + # Show raw message content + print msg + # Convert html to text, easier to read but can fail if you have intl + # chars +# print html2text.html2text(msg) + print + # Go back to the Inbox + br.follow_link(text='Inbox') + +# Logout +br.follow_link(text='Sign out') diff --git a/hub b/hub new file mode 100755 index 0000000..2dced4e --- /dev/null +++ b/hub @@ -0,0 +1,1707 @@ +#!/usr/bin/env ruby +# +# This file, hub, is generated code. +# Please DO NOT EDIT or send patches for it. +# +# Please take a look at the source from +# https://github.com/defunkt/hub +# and submit patches against the individual files +# that build hub. +# + +require 'shellwords' +require 'forwardable' + +module Hub + module Context + extend Forwardable + + NULL = defined?(File::NULL) ? File::NULL : File.exist?('/dev/null') ? '/dev/null' : 'NUL' + + class GitReader + attr_reader :executable + + def initialize(executable = nil, &read_proc) + @executable = executable || 'git' + read_proc ||= lambda { |cache, cmd| + result = %x{#{command_to_string(cmd)} 2>#{NULL}}.chomp + cache[cmd] = $?.success? && !result.empty? ? result : nil + } + @cache = Hash.new(&read_proc) + end + + def add_exec_flags(flags) + @executable = Array(executable).concat(flags) + end + + def read_config(cmd, all = false) + config_cmd = ['config', (all ? '--get-all' : '--get'), *cmd] + config_cmd = config_cmd.join(' ') unless cmd.respond_to? :join + read config_cmd + end + + def read(cmd) + @cache[cmd] + end + + def stub_config_value(key, value, get = '--get') + stub_command_output "config #{get} #{key}", value + end + + def stub_command_output(cmd, value) + @cache[cmd] = value.nil? ? nil : value.to_s + end + + def stub!(values) + @cache.update values + end + + private + + def to_exec(args) + args = Shellwords.shellwords(args) if args.respond_to? :to_str + Array(executable) + Array(args) + end + + def command_to_string(cmd) + full_cmd = to_exec(cmd) + full_cmd.respond_to?(:shelljoin) ? full_cmd.shelljoin : full_cmd.join(' ') + end + end + + module GitReaderMethods + extend Forwardable + + def_delegator :git_reader, :read_config, :git_config + def_delegator :git_reader, :read, :git_command + + def self.extended(base) + base.extend Forwardable + base.def_delegators :'self.class', :git_config, :git_command + end + end + + private + + def git_reader + @git_reader ||= GitReader.new ENV['GIT'] + end + + include GitReaderMethods + private :git_config, :git_command + + def local_repo + @local_repo ||= begin + LocalRepo.new git_reader, current_dir if is_repo? + end + end + + repo_methods = [ + :current_branch, :master_branch, + :current_project, :upstream_project, + :repo_owner, + :remotes, :remotes_group, :origin_remote + ] + def_delegator :local_repo, :name, :repo_name + def_delegators :local_repo, *repo_methods + private :repo_name, *repo_methods + + class LocalRepo < Struct.new(:git_reader, :dir) + include GitReaderMethods + + def name + if project = main_project + project.name + else + File.basename(dir) + end + end + + def repo_owner + if project = main_project + project.owner + end + end + + def main_project + remote = origin_remote and remote.project + end + + def upstream_project + if upstream = current_branch.upstream + remote = remote_by_name upstream.remote_name + remote.project + end + end + + def current_project + upstream_project || main_project + end + + def current_branch + if branch = git_command('symbolic-ref -q HEAD') + Branch.new self, branch + end + end + + def master_branch + Branch.new self, 'refs/heads/master' + end + + def remotes + @remotes ||= begin + list = git_command('remote').to_s.split("\n") + main = list.delete('origin') and list.unshift(main) + list.map { |name| Remote.new self, name } + end + end + + def remotes_group(name) + git_config "remotes.#{name}" + end + + def origin_remote + remotes.first + end + + def remote_by_name(remote_name) + remotes.find {|r| r.name == remote_name } + end + end + + class GithubProject < Struct.new(:local_repo, :owner, :name) + def name_with_owner + "#{owner}/#{name}" + end + + def ==(other) + name_with_owner == other.name_with_owner + end + + def remote + local_repo.remotes.find { |r| r.project == self } + end + + def web_url(path = nil) + project_name = name_with_owner + if project_name.sub!(/\.wiki$/, '') + unless '/wiki' == path + path = if path =~ %r{^/commits/} then '/_history' + else path.to_s.sub(/\w+/, '_\0') + end + path = '/wiki' + path + end + end + 'https://github.com/' + project_name + path.to_s + end + + def git_url(options = {}) + if options[:https] then 'https://github.com/' + elsif options[:private] then 'git@github.com:' + else 'git://github.com/' + end + name_with_owner + '.git' + end + end + + class Branch < Struct.new(:local_repo, :name) + alias to_s name + + def short_name + name.split('/').last + end + + def master? + short_name == 'master' + end + + def upstream + if branch = local_repo.git_command("rev-parse --symbolic-full-name #{short_name}@{upstream}") + Branch.new local_repo, branch + end + end + + def remote? + name.index('refs/remotes/') == 0 + end + + def remote_name + name =~ %r{^refs/remotes/([^/]+)} and $1 or + raise "can't get remote name from #{name.inspect}" + end + end + + class Remote < Struct.new(:local_repo, :name) + alias to_s name + + def ==(other) + other.respond_to?(:to_str) ? name == other.to_str : super + end + + def project + if urls.find { |u| u =~ %r{\bgithub\.com[:/](.+)/(.+).git$} } + GithubProject.new local_repo, $1, $2 + end + end + + def urls + @urls ||= local_repo.git_config("remote.#{name}.url", :all).to_s.split("\n") + end + end + + + def github_project(name, owner = nil) + if owner and owner.index('/') + owner, name = owner.split('/', 2) + elsif name and name.index('/') + owner, name = name.split('/', 2) + else + name ||= repo_name + owner ||= github_user + end + + GithubProject.new local_repo, owner, name + end + + def git_url(owner = nil, name = nil, options = {}) + project = github_project(name, owner) + project.git_url({:https => https_protocol?}.update(options)) + end + + LGHCONF = "http://help.github.com/set-your-user-name-email-and-github-token/" + + def github_user(fatal = true) + if user = ENV['GITHUB_USER'] || git_config('github.user') + user + elsif fatal + abort("** No GitHub user set. See #{LGHCONF}") + end + end + + def github_token(fatal = true) + if token = ENV['GITHUB_TOKEN'] || git_config('github.token') + token + elsif fatal + abort("** No GitHub token set. See #{LGHCONF}") + end + end + + def http_clone? + git_config('--bool hub.http-clone') == 'true' + end + + def https_protocol? + git_config('hub.protocol') == 'https' or http_clone? + end + + def git_alias_for(name) + git_config "alias.#{name}" + end + + PWD = Dir.pwd + + def current_dir + PWD + end + + def git_dir + git_command 'rev-parse -q --git-dir' + end + + def is_repo? + !!git_dir + end + + def git_editor + editor = git_command 'var GIT_EDITOR' + editor = ENV[$1] if editor =~ /^\$(\w+)$/ + editor = File.expand_path editor if (editor =~ /^[~.]/ or editor.index('/')) and editor !~ /["']/ + editor.shellsplit + end + + def browser_launcher + browser = ENV['BROWSER'] || ( + osx? ? 'open' : windows? ? 'start' : + %w[xdg-open cygstart x-www-browser firefox opera mozilla netscape].find { |comm| which comm } + ) + + abort "Please set $BROWSER to a web launcher to use this command." unless browser + Array(browser) + end + + def osx? + require 'rbconfig' + RbConfig::CONFIG['host_os'].to_s.include?('darwin') + end + + def windows? + require 'rbconfig' + RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw|windows/ + end + + def which(cmd) + exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] + ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| + exts.each { |ext| + exe = "#{path}/#{cmd}#{ext}" + return exe if File.executable? exe + } + end + return nil + end + + def command?(name) + !which(name).nil? + end + end +end +module Hub + class Args < Array + attr_accessor :executable + + def initialize(*args) + super + @executable = ENV["GIT"] || "git" + @after = nil + @skip = @noop = false + @original_args = args.first + @chain = [nil] + end + + def after(cmd_or_args = nil, args = nil, &block) + @chain.insert(-1, normalize_callback(cmd_or_args, args, block)) + end + + def before(cmd_or_args = nil, args = nil, &block) + @chain.insert(@chain.index(nil), normalize_callback(cmd_or_args, args, block)) + end + + def chained? + @chain.size > 1 + end + + def commands + chain = @chain.dup + chain[chain.index(nil)] = self.to_exec + chain + end + + def skip! + @skip = true + end + + def skip? + @skip + end + + def noop! + @noop = true + end + + def noop? + @noop + end + + def to_exec(args = self) + Array(executable) + args + end + + def add_exec_flags(flags) + self.executable = Array(executable).concat(flags) + end + + def words + reject { |arg| arg.index('-') == 0 } + end + + def flags + self - words + end + + def changed? + chained? or self != @original_args + end + + def has_flag?(*flags) + pattern = flags.flatten.map { |f| Regexp.escape(f) }.join('|') + !grep(/^#{pattern}(?:=|$)/).empty? + end + + private + + def normalize_callback(cmd_or_args, args, block) + if block + block + elsif args + [cmd_or_args].concat args + elsif Array === cmd_or_args + self.to_exec cmd_or_args + elsif cmd_or_args + cmd_or_args + else + raise ArgumentError, "command or block required" + end + end + end +end +module Hub + module Commands + instance_methods.each { |m| undef_method(m) unless m =~ /(^__|send|to\?$)/ } + extend self + + extend Context + + API_REPO = 'http://github.com/api/v2/yaml/repos/show/%s/%s' + API_FORK = 'https://github.com/api/v2/yaml/repos/fork/%s/%s' + API_CREATE = 'https://github.com/api/v2/yaml/repos/create' + API_PULL = 'http://github.com/api/v2/json/pulls/%s' + API_PULLREQUEST = 'https://github.com/api/v2/yaml/pulls/%s/%s' + + NAME_WITH_OWNER_RE = /^([\w-]+)(?:\/([\w-]+))?$/ + + def run(args) + slurp_global_flags(args) + + args.unshift 'help' if args.empty? + + cmd = args[0] + expanded_args = expand_alias(cmd) + cmd = expanded_args[0] if expanded_args + + cmd = cmd.sub(/(\w)-/, '\1_') + if method_defined?(cmd) and cmd != 'run' + args[0, 1] = expanded_args if expanded_args + send(cmd, args) + end + rescue Errno::ENOENT + if $!.message.include? "No such file or directory - git" + abort "Error: `git` command not found" + else + raise + end + end + + def pull_request(args) + args.shift + options = { } + force = explicit_owner = false + base_project = local_repo.main_project + head_project = local_repo.current_project + + from_github_ref = lambda do |ref, context_project| + if ref.index(':') + owner, ref = ref.split(':', 2) + project = github_project(context_project.name, owner) + end + [project || context_project, ref] + end + + while arg = args.shift + case arg + when '-f' + force = true + when '-b' + base_project, options[:base] = from_github_ref.call(args.shift, base_project) + when '-h' + head = args.shift + explicit_owner = !!head.index(':') + head_project, options[:head] = from_github_ref.call(head, head_project) + when '-i' + options[:issue] = args.shift + when %r{^https?://github.com/([^/]+/[^/]+)/issues/(\d+)} + options[:issue] = $2 + base_project = github_project($1) + else + if !options[:title] then options[:title] = arg + else + abort "invalid argument: #{arg}" + end + end + end + + options[:project] = base_project + options[:base] ||= master_branch.short_name + + if tracked_branch = options[:head].nil? && current_branch.upstream + if base_project == head_project and tracked_branch.short_name == options[:base] + $stderr.puts "Aborted: head branch is the same as base (#{options[:base].inspect})" + warn "(use `-h ` to specify an explicit pull request head)" + abort + end + end + options[:head] ||= (tracked_branch || current_branch).short_name + + if head_project.owner != github_user and !tracked_branch and !explicit_owner + head_project = github_project(head_project.name, github_user) + end + + remote_branch = "#{head_project.remote}/#{options[:head]}" + options[:head] = "#{head_project.owner}:#{options[:head]}" + + if !force and tracked_branch and local_commits = git_command("rev-list --cherry #{remote_branch}...") + $stderr.puts "Aborted: #{local_commits.split("\n").size} commits are not yet pushed to #{remote_branch}" + warn "(use `-f` to force submit a pull request anyway)" + abort + end + + if args.noop? + puts "Would reqest a pull to #{base_project.owner}:#{options[:base]} from #{options[:head]}" + exit + end + + unless options[:title] or options[:issue] + base_branch = "#{base_project.remote}/#{options[:base]}" + changes = git_command "log --no-color --pretty=medium --cherry %s...%s" % + [base_branch, remote_branch] + + options[:title], options[:body] = pullrequest_editmsg(changes) { |msg| + msg.puts "# Requesting a pull to #{base_project.owner}:#{options[:base]} from #{options[:head]}" + msg.puts "#" + msg.puts "# Write a message for this pull request. The first block" + msg.puts "# of text is the title and the rest is description." + } + end + + pull = create_pullrequest(options) + + args.executable = 'echo' + args.replace [pull['html_url']] + rescue HTTPExceptions + display_http_exception("creating pull request", $!.response) + exit 1 + end + + def clone(args) + ssh = args.delete('-p') + has_values = /^(--(upload-pack|template|depth|origin|branch|reference)|-[ubo])$/ + + idx = 1 + while idx < args.length + arg = args[idx] + if arg.index('-') == 0 + idx += 1 if arg =~ has_values + else + if arg =~ NAME_WITH_OWNER_RE + project = github_project(arg) + ssh ||= args[0] != 'submodule' && project.owner == github_user(false) + args[idx] = project.git_url(:private => ssh, :https => https_protocol?) + end + break + end + idx += 1 + end + end + + def submodule(args) + return unless index = args.index('add') + args.delete_at index + + branch = args.index('-b') || args.index('--branch') + if branch + args.delete_at branch + branch_name = args.delete_at branch + end + + clone(args) + + if branch_name + args.insert branch, '-b', branch_name + end + args.insert index, 'add' + end + + def remote(args) + if %w[add set-url].include?(args[1]) && args.last =~ NAME_WITH_OWNER_RE + user, repo = $1, $2 || repo_name + else + return # do not touch arguments + end + + ssh = args.delete('-p') + + if args.words[2] == 'origin' && args.words[3].nil? + user, repo = github_user, repo_name + elsif args.words[-2] == args.words[1] + idx = args.index( args.words[-1] ) + args[idx] = user + else + args.pop + end + + args << git_url(user, repo, :private => ssh) + end + + def fetch(args) + if args.include?('--multiple') + names = args.words[1..-1] + elsif remote_name = args.words[1] + if remote_name =~ /^\w+(,\w+)+$/ + index = args.index(remote_name) + args.delete(remote_name) + names = remote_name.split(',') + args.insert(index, *names) + args.insert(index, '--multiple') + else + names = [remote_name] + end + else + names = [] + end + + names.reject! { |name| + name =~ /\W/ or remotes.include?(name) or + remotes_group(name) or not repo_exists?(name) + } + + if names.any? + names.each do |name| + args.before ['remote', 'add', name, git_url(name)] + end + end + end + + def checkout(args) + if (2..3) === args.length and args[1] =~ %r{https?://github.com/(.+?)/(.+?)/pull/(\d+)} + owner, repo, pull_id = $1, $2, $3 + + load_net_http + pull_body = Net::HTTP.get URI(API_PULL % File.join(owner, repo, pull_id)) + + user, branch = pull_body.match(/"label":\s*"(.+?)"/)[1].split(':', 2) + new_branch_name = args[2] || "#{user}-#{branch}" + + if remotes.include? user + args.before ['remote', 'set-branches', '--add', user, branch] + args.before ['fetch', user, "+refs/heads/#{branch}:refs/remotes/#{user}/#{branch}"] + else + args.before ['remote', 'add', '-f', '-t', branch, user, github_project(repo, user).git_url] + end + args[1..-1] = ['-b', new_branch_name, "#{user}/#{branch}"] + end + end + + def cherry_pick(args) + unless args.include?('-m') or args.include?('--mainline') + case ref = args.words.last + when %r{^(?:https?:)//github.com/(.+?)/(.+?)/commit/([a-f0-9]{7,40})} + user, repo, sha = $1, $2, $3 + args[args.index(ref)] = sha + when /^(\w+)@([a-f0-9]{7,40})$/ + user, repo, sha = $1, nil, $2 + args[args.index(ref)] = sha + else + user = nil + end + + if user + if user == repo_owner + args.before ['fetch', origin_remote] + elsif remotes.include?(user) + args.before ['fetch', user] + else + args.before ['remote', 'add', '-f', user, git_url(user, repo)] + end + end + end + end + + def am(args) + if url = args.find { |a| a =~ %r{^https?://(gist\.)?github\.com/} } + idx = args.index(url) + gist = $1 == 'gist.' + url = url.sub(%r{(/pull/\d+)/\w*$}, '\1') unless gist + ext = gist ? '.txt' : '.patch' + url += ext unless File.extname(url) == ext + patch_file = File.join(ENV['TMPDIR'], "#{gist ? 'gist-' : ''}#{File.basename(url)}") + args.before 'curl', ['-#LA', "hub #{Hub::Version}", url, '-o', patch_file] + args[idx] = patch_file + end + end + + alias_method :apply, :am + + def init(args) + if args.delete('-g') + url = git_url(github_user, repo_name, :private => true) + args.after ['remote', 'add', 'origin', url] + end + end + + def fork(args) + if github_user && github_token && repo_owner + if repo_exists?(github_user) + warn "#{github_user}/#{repo_name} already exists on GitHub" + else + fork_repo unless args.noop? + end + + if args.include?('--no-remote') + exit + else + url = git_url(github_user, repo_name, :private => true) + args.replace %W"remote add -f #{github_user} #{url}" + args.after 'echo', ['new remote:', github_user] + end + end + rescue HTTPExceptions + display_http_exception("creating fork", $!.response) + exit 1 + end + + def create(args) + if !is_repo? + abort "'create' must be run from inside a git repository" + elsif owner = github_user and github_token + args.shift + options = {} + options[:private] = true if args.delete('-p') + new_repo_name = nil + + until args.empty? + case arg = args.shift + when '-d' + options[:description] = args.shift + when '-h' + options[:homepage] = args.shift + else + if arg =~ /^[^-]/ and new_repo_name.nil? + new_repo_name = arg + owner, new_repo_name = new_repo_name.split('/', 2) if new_repo_name.index('/') + else + abort "invalid argument: #{arg}" + end + end + end + new_repo_name ||= repo_name + repo_with_owner = "#{owner}/#{new_repo_name}" + + if repo_exists?(owner, new_repo_name) + warn "#{repo_with_owner} already exists on GitHub" + action = "set remote origin" + else + action = "created repository" + create_repo(repo_with_owner, options) unless args.noop? + end + + url = git_url(owner, new_repo_name, :private => true) + + if remotes.first != 'origin' + args.replace %W"remote add -f origin #{url}" + else + args.replace %W"remote -v" + end + + args.after 'echo', ["#{action}:", repo_with_owner] + end + rescue HTTPExceptions + display_http_exception("creating repository", $!.response) + exit 1 + end + + def push(args) + return if args[1].nil? || !args[1].index(',') + + branch = (args[2] ||= current_branch.short_name) + remotes = args[1].split(',') + args[1] = remotes.shift + + remotes.each do |name| + args.after ['push', name, branch] + end + end + + def browse(args) + args.shift + browse_command(args) do + dest = args.shift + dest = nil if dest == '--' + + if dest + project = github_project dest + else + project = current_project + end + + abort "Usage: hub browse [/]" unless project + + path = case subpage = args.shift + when 'commits' + branch = (!dest && current_branch.upstream) || master_branch + "/commits/#{branch.short_name}" + when 'tree', NilClass + branch = !dest && current_branch.upstream + "/tree/#{branch.short_name}" if branch and !branch.master? + else + "/#{subpage}" + end + + project.web_url(path) + end + end + + def compare(args) + args.shift + browse_command(args) do + if args.empty? + branch = current_branch.upstream + if branch and not branch.master? + range = branch.short_name + project = current_project + else + abort "Usage: hub compare [USER] [...]" + end + else + sha_or_tag = /(\w{1,2}|\w[\w.-]+\w)/ + range = args.pop.sub(/^#{sha_or_tag}\.\.#{sha_or_tag}$/, '\1...\2') + project = if owner = args.pop then github_project(nil, owner) + else current_project + end + end + + project.web_url "/compare/#{range}" + end + end + + def hub(args) + return help(args) unless args[1] == 'standalone' + require 'hub/standalone' + $stdout.puts Hub::Standalone.build + exit + rescue LoadError + abort "hub is running in standalone mode." + end + + def alias(args) + shells = { + 'sh' => 'alias git=hub', + 'bash' => 'alias git=hub', + 'zsh' => 'function git(){hub "$@"}', + 'csh' => 'alias git hub', + 'fish' => 'alias git hub' + } + + silent = args.delete('-s') + + if shell = args[1] + if silent.nil? + puts "Run this in your shell to start using `hub` as `git`:" + print " " + end + else + puts "usage: hub alias [-s] SHELL", "" + puts "You already have hub installed and available in your PATH," + puts "but to get the full experience you'll want to alias it to" + puts "`git`.", "" + puts "To see how to accomplish this for your shell, run the alias" + puts "command again with the name of your shell.", "" + puts "Known shells:" + shells.map { |key, _| key }.sort.each do |key| + puts " " + key + end + puts "", "Options:" + puts " -s Silent. Useful when using the output with eval, e.g." + puts " $ eval `hub alias -s bash`" + + exit + end + + if shells[shell] + puts shells[shell] + else + abort "fatal: never heard of `#{shell}'" + end + + exit + end + + def version(args) + args.after 'echo', ['hub version', Version] + end + alias_method "--version", :version + + def help(args) + command = args.words[1] + + if command == 'hub' + puts hub_manpage + exit + elsif command.nil? && !args.has_flag?('-a', '--all') + ENV['GIT_PAGER'] = '' unless args.has_flag?('-p', '--paginate') # Use `cat`. + puts improved_help_text + exit + end + end + alias_method "--help", :help + + private + + def improved_help_text + <<-help +usage: git [--version] [--exec-path[=]] [--html-path] [--man-path] [--info-path] + [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] + [--git-dir=] [--work-tree=] [--namespace=] + [-c name=value] [--help] + [] + +Basic Commands: + init Create an empty git repository or reinitialize an existing one + add Add new or modified files to the staging area + rm Remove files from the working directory and staging area + mv Move or rename a file, a directory, or a symlink + status Show the status of the working directory and staging area + commit Record changes to the repository + +History Commands: + log Show the commit history log + diff Show changes between commits, commit and working tree, etc + show Show information about commits, tags or files + +Branching Commands: + branch List, create, or delete branches + checkout Switch the active branch to another branch + merge Join two or more development histories (branches) together + tag Create, list, delete, sign or verify a tag object + +Remote Commands: + clone Clone a remote repository into a new directory + fetch Download data, tags and branches from a remote repository + pull Fetch from and merge with another repository or a local branch + push Upload data, tags and branches to a remote repository + remote View and manage a set of remote repositories + +Advanced commands: + reset Reset your staging area or working directory to another point + rebase Re-apply a series of patches in one branch onto another + bisect Find by binary search the change that introduced a bug + grep Print files with lines matching a pattern in your codebase + +See 'git help ' for more information on a specific command. +help + end + + def slurp_global_flags(args) + flags = %w[ --noop -c -p --paginate --no-pager --no-replace-objects --bare --version --help ] + flags2 = %w[ --exec-path= --git-dir= --work-tree= ] + + globals = [] + locals = [] + + while args[0] && (flags.include?(args[0]) || flags2.any? {|f| args[0].index(f) == 0 }) + flag = args.shift + case flag + when '--noop' + args.noop! + when '--version', '--help' + args.unshift flag.sub('--', '') + when '-c' + config_pair = args.shift + key, value = config_pair.split('=', 2) + git_reader.stub_config_value(key, value) + + globals << flag << config_pair + when '-p', '--paginate', '--no-pager' + locals << flag + else + globals << flag + end + end + + git_reader.add_exec_flags(globals) + args.add_exec_flags(globals) + args.add_exec_flags(locals) + end + + def browse_command(args) + url_only = args.delete('-u') + warn "Warning: the `-p` flag has no effect anymore" if args.delete('-p') + url = yield + + args.executable = url_only ? 'echo' : browser_launcher + args.push url + end + + def hub_manpage + abort "** Can't find groff(1)" unless command?('groff') + + require 'open3' + out = nil + Open3.popen3(groff_command) do |stdin, stdout, _| + stdin.puts hub_raw_manpage + stdin.close + out = stdout.read.strip + end + out + end + + def groff_command + "groff -Wall -mtty-char -mandoc -Tascii" + end + + def hub_raw_manpage + if File.exists? file = File.dirname(__FILE__) + '/../../man/hub.1' + File.read(file) + else + DATA.read + end + end + + def puts(*args) + page_stdout + super + end + + def page_stdout + return if not $stdout.tty? or windows? + + read, write = IO.pipe + + if Kernel.fork + $stdin.reopen(read) + read.close + write.close + + ENV['LESS'] = 'FSRX' + + Kernel.select [STDIN] + + pager = ENV['GIT_PAGER'] || + `git config --get-all core.pager`.split.first || ENV['PAGER'] || + 'less -isr' + + pager = 'cat' if pager.empty? + + exec pager rescue exec "/bin/sh", "-c", pager + else + $stdout.reopen(write) + $stderr.reopen(write) if $stderr.tty? + read.close + write.close + end + end + + def repo_exists?(user, repo = repo_name) + load_net_http + url = API_REPO % [user, repo] + Net::HTTPSuccess === Net::HTTP.get_response(URI(url)) + end + + def fork_repo + load_net_http + response = http_post API_FORK % [repo_owner, repo_name] + response.error! unless Net::HTTPSuccess === response + end + + def create_repo(name, options = {}) + params = {'name' => name.sub(/^#{github_user}\//, '')} + params['public'] = '0' if options[:private] + params['description'] = options[:description] if options[:description] + params['homepage'] = options[:homepage] if options[:homepage] + + load_net_http + response = http_post(API_CREATE, params) + response.error! unless Net::HTTPSuccess === response + end + + def create_pullrequest(options) + project = options.fetch(:project) + params = { + 'pull[base]' => options.fetch(:base), + 'pull[head]' => options.fetch(:head) + } + params['pull[issue]'] = options[:issue] if options[:issue] + params['pull[title]'] = options[:title] if options[:title] + params['pull[body]'] = options[:body] if options[:body] + + load_net_http + response = http_post(API_PULLREQUEST % [project.owner, project.name], params) + response.error! unless Net::HTTPSuccess === response + if response['Content-type'].to_s.include? 'application/json' + { "html_url" => response.body.match(/"html_url":\s*"(.+?)"/)[1] } + else + require 'yaml' + YAML.load(response.body)['pull'] + end + end + + def pullrequest_editmsg(changes) + message_file = File.join(git_dir, 'PULLREQ_EDITMSG') + File.open(message_file, 'w') { |msg| + msg.puts + yield msg + if changes + msg.puts "#\n# Changes:\n#" + msg.puts changes.gsub(/^/, '# ').gsub(/ +$/, '') + end + } + edit_cmd = Array(git_editor).dup << message_file + system(*edit_cmd) + abort "can't open text editor for pull request message" unless $?.success? + title, body = read_editmsg(message_file) + abort "Aborting due to empty pull request title" unless title + [title, body] + end + + def read_editmsg(file) + title, body = '', '' + File.open(file, 'r') { |msg| + msg.each_line do |line| + next if line.index('#') == 0 + ((body.empty? and line =~ /\S/) ? title : body) << line + end + } + title.tr!("\n", ' ') + title.strip! + body.strip! + + [title =~ /\S/ ? title : nil, body =~ /\S/ ? body : nil] + end + + def expand_alias(cmd) + if expanded = git_alias_for(cmd) + if expanded.index('!') != 0 + require 'shellwords' unless defined?(::Shellwords) + Shellwords.shellwords(expanded) + end + end + end + + def http_post(url, params = nil) + url = URI(url) + post = Net::HTTP::Post.new(url.request_uri) + post.basic_auth "#{github_user}/token", github_token + post.set_form_data params if params + + port = url.port + if use_ssl = 'https' == url.scheme and not use_ssl? + use_ssl = false + port = 80 + end + + http = Net::HTTP.new(url.host, port) + if http.use_ssl = use_ssl + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + http.start { http.request(post) } + end + + def load_net_http + require 'net/https' + rescue LoadError + require 'net/http' + end + + def use_ssl? + defined? ::OpenSSL + end + + module HTTPExceptions + def self.===(exception) + exception.class.ancestors.map {|a| a.to_s }.include? 'Net::HTTPExceptions' + end + end + + def display_http_exception(action, response) + $stderr.puts "Error #{action}: #{response.message} (HTTP #{response.code})" + warn "Check your token configuration (`git config github.token`)" if response.code.to_i == 401 + end + + end +end +module Hub + class Runner + attr_reader :args + + def initialize(*args) + @args = Args.new(args) + Commands.run(@args) + end + + def self.execute(*args) + new(*args).execute + end + + def command + if args.skip? + '' + else + commands.join('; ') + end + end + + def commands + args.commands.map do |cmd| + if cmd.respond_to?(:join) + cmd.map { |arg| arg = arg.to_s; (arg.index(' ') || arg.empty?) ? "'#{arg}'" : arg }.join(' ') + else + cmd.to_s + end + end + end + + def execute + if args.noop? + puts commands + elsif not args.skip? + if args.chained? + execute_command_chain + else + exec(*args.to_exec) + end + end + end + + def execute_command_chain + commands = args.commands + commands.each_with_index do |cmd, i| + if cmd.respond_to?(:call) then cmd.call + elsif i == commands.length - 1 + exec(*cmd) + else + exit($?.exitstatus) unless system(*cmd) + end + end + end + end +end +module Hub + Version = VERSION = '1.7.0' +end +Hub::Runner.execute(*ARGV) +__END__ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "HUB" "1" "November 2011" "DEFUNKT" "Git Manual" +. +.SH "NAME" +\fBhub\fR \- git + hub = github +. +.SH "SYNOPSIS" +\fBhub\fR [\fB\-\-noop\fR] \fICOMMAND\fR \fIOPTIONS\fR +. +.br +\fBhub alias\fR [\fB\-s\fR] \fISHELL\fR +. +.SS "Expanded git commands:" +\fBgit init \-g\fR \fIOPTIONS\fR +. +.br +\fBgit clone\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR +. +.br +\fBgit remote add\fR [\fB\-p\fR] \fIOPTIONS\fR \fIUSER\fR[/\fIREPOSITORY\fR] +. +.br +\fBgit remote set\-url\fR [\fB\-p\fR] \fIOPTIONS\fR \fIREMOTE\-NAME\fR \fIUSER\fR[/\fIREPOSITORY\fR] +. +.br +\fBgit fetch\fR \fIUSER\-1\fR,[\fIUSER\-2\fR,\.\.\.] +. +.br +\fBgit checkout\fR \fIPULLREQ\-URL\fR [\fIBRANCH\fR] +. +.br +\fBgit cherry\-pick\fR \fIGITHUB\-REF\fR +. +.br +\fBgit am\fR \fIGITHUB\-URL\fR +. +.br +\fBgit apply\fR \fIGITHUB\-URL\fR +. +.br +\fBgit push\fR \fIREMOTE\-1\fR,\fIREMOTE\-2\fR,\.\.\.,\fIREMOTE\-N\fR [\fIREF\fR] +. +.br +\fBgit submodule add\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR +. +.SS "Custom git commands:" +\fBgit create\fR [\fINAME\fR] [\fB\-p\fR] [\fB\-d\fR \fIDESCRIPTION\fR] [\fB\-h\fR \fIHOMEPAGE\fR] +. +.br +\fBgit browse\fR [\fB\-u\fR] [[\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR] [SUBPAGE] +. +.br +\fBgit compare\fR [\fB\-u\fR] [\fIUSER\fR] [\fISTART\fR\.\.\.]\fIEND\fR +. +.br +\fBgit fork\fR [\fB\-\-no\-remote\fR] +. +.br +\fBgit pull\-request\fR [\fB\-f\fR] [\fITITLE\fR|\fB\-i\fR \fIISSUE\fR] [\fB\-b\fR \fIBASE\fR] [\fB\-h\fR \fIHEAD\fR]: +. +.SH "DESCRIPTION" +hub enhances various git commands to ease most common workflows with GitHub\. +. +.TP +\fBhub \-\-noop\fR \fICOMMAND\fR +Shows which command(s) would be run as a result of the current command\. Doesn\'t perform anything\. +. +.TP +\fBhub alias\fR [\fB\-s\fR] \fISHELL\fR +Writes shell aliasing code for \fISHELL\fR (\fBbash\fR, \fBsh\fR, \fBzsh\fR, \fBcsh\fR) to standard output\. With the \fB\-s\fR option, the output of this command can be evaluated directly within the shell: +. +.br +\fBeval $(hub alias \-s bash)\fR +. +.TP +\fBgit init\fR \fB\-g\fR \fIOPTIONS\fR +Create a git repository as with git\-init(1) and add remote \fBorigin\fR at "git@github\.com:\fIUSER\fR/\fIREPOSITORY\fR\.git"; \fIUSER\fR is your GitHub username and \fIREPOSITORY\fR is the current working directory\'s basename\. +. +.TP +\fBgit clone\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR \fIDIRECTORY\fR +Clone repository "git://github\.com/\fIUSER\fR/\fIREPOSITORY\fR\.git" into \fIDIRECTORY\fR as with git\-clone(1)\. When \fIUSER\fR/ is omitted, assumes your GitHub login\. With \fB\-p\fR, clone private repositories over SSH\. For repositories under your GitHub login, \fB\-p\fR is implicit\. +. +.TP +\fBgit remote add\fR [\fB\-p\fR] \fIOPTIONS\fR \fIUSER\fR[\fB/\fR\fIREPOSITORY\fR] +Add remote "git://github\.com/\fIUSER\fR/\fIREPOSITORY\fR\.git" as with git\-remote(1)\. When /\fIREPOSITORY\fR is omitted, the basename of the current working directory is used\. With \fB\-p\fR, use private remote "git@github\.com:\fIUSER\fR/\fIREPOSITORY\fR\.git"\. If \fIUSER\fR is "origin" then uses your GitHub login\. +. +.TP +\fBgit remote set\-url\fR [\fB\-p\fR] \fIOPTIONS\fR \fIREMOTE\-NAME\fR \fIUSER\fR[/\fIREPOSITORY\fR] +Sets the url of remote \fIREMOTE\-NAME\fR using the same rules as \fBgit remote add\fR\. +. +.TP +\fBgit fetch\fR \fIUSER\-1\fR,[\fIUSER\-2\fR,\.\.\.] +Adds missing remote(s) with \fBgit remote add\fR prior to fetching\. New remotes are only added if they correspond to valid forks on GitHub\. +. +.TP +\fBgit checkout\fR \fIPULLREQ\-URL\fR [\fIBRANCH\fR] +Checks out the head of the pull request as a local branch, to allow for reviewing, rebasing and otherwise cleaning up the commits in the pull request before merging\. The name of the local branch can explicitly be set with \fIBRANCH\fR\. +. +.TP +\fBgit cherry\-pick\fR \fIGITHUB\-REF\fR +Cherry\-pick a commit from a fork using either full URL to the commit or GitHub\-flavored Markdown notation, which is \fBuser@sha\fR\. If the remote doesn\'t yet exist, it will be added\. A \fBgit fetch \fR is issued prior to the cherry\-pick attempt\. +. +.TP +\fBgit [am|apply]\fR \fIGITHUB\-URL\fR +Downloads the patch file for the pull request or commit at the URL and applies that patch from disk with \fBgit am\fR or \fBgit apply\fR\. Similar to \fBcherry\-pick\fR, but doesn\'t add new remotes\. \fBgit am\fR creates commits while preserving authorship info while \fBapply\fR only applies the patch to the working copy\. +. +.TP +\fBgit push\fR \fIREMOTE\-1\fR,\fIREMOTE\-2\fR,\.\.\.,\fIREMOTE\-N\fR [\fIREF\fR] +Push \fIREF\fR to each of \fIREMOTE\-1\fR through \fIREMOTE\-N\fR by executing multiple \fBgit push\fR commands\. +. +.TP +\fBgit submodule add\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR +Submodule repository "git://github\.com/\fIUSER\fR/\fIREPOSITORY\fR\.git" into \fIDIRECTORY\fR as with git\-submodule(1)\. When \fIUSER\fR/ is omitted, assumes your GitHub login\. With \fB\-p\fR, use private remote "git@github\.com:\fIUSER\fR/\fIREPOSITORY\fR\.git"\. +. +.TP +\fBgit help\fR +Display enhanced git\-help(1)\. +. +.P +hub also adds some custom commands that are otherwise not present in git: +. +.TP +\fBgit create\fR [\fINAME\fR] [\fB\-p\fR] [\fB\-d\fR \fIDESCRIPTION\fR] [\fB\-h\fR \fIHOMEPAGE\fR] +Create a new public GitHub repository from the current git repository and add remote \fBorigin\fR at "git@github\.com:\fIUSER\fR/\fIREPOSITORY\fR\.git"; \fIUSER\fR is your GitHub username and \fIREPOSITORY\fR is the current working directory name\. To explicitly name the new repository, pass in \fINAME\fR, optionally in \fIORGANIZATION\fR/\fINAME\fR form to create under an organization you\'re a member of\. With \fB\-p\fR, create a private repository, and with \fB\-d\fR and \fB\-h\fR set the repository\'s description and homepage URL, respectively\. +. +.TP +\fBgit browse\fR [\fB\-u\fR] [[\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR] [SUBPAGE] +Open repository\'s GitHub page in the system\'s default web browser using \fBopen(1)\fR or the \fBBROWSER\fR env variable\. If the repository isn\'t specified, \fBbrowse\fR opens the page of the repository found in the current directory\. If SUBPAGE is specified, the browser will open on the specified subpage: one of "wiki", "commits", "issues" or other (the default is "tree")\. +. +.TP +\fBgit compare\fR [\fB\-u\fR] [\fIUSER\fR] [\fISTART\fR\.\.\.]\fIEND\fR +Open a GitHub compare view page in the system\'s default web browser\. \fISTART\fR to \fIEND\fR are branch names, tag names, or commit SHA1s specifying the range of history to compare\. If a range with two dots (\fBa\.\.b\fR) is given, it will be transformed into one with three dots\. If \fISTART\fR is omitted, GitHub will compare against the base branch (the default is "master")\. +. +.TP +\fBgit fork\fR [\fB\-\-no\-remote\fR] +Forks the original project (referenced by "origin" remote) on GitHub and adds a new remote for it under your username\. Requires \fBgithub\.token\fR to be set (see CONFIGURATION)\. +. +.TP +\fBgit pull\-request\fR [\fB\-f\fR] [\fITITLE\fR|\fB\-i\fR \fIISSUE\fR] [\fB\-b\fR \fIBASE\fR] [\fB\-h\fR \fIHEAD\fR] +\fBgit pull\-request\fR [\fB\-f\fR] \fIISSUE\-URL\fR [\fB\-h\fR \fIHEAD\fR] Opens a pull request on GitHub for the project that the "origin" remote points to\. The default head of the pull request is the current branch\. Both base and head of the pull request can be explicitly given in one of the following formats: "branch", "owner:branch", "owner/repo:branch"\. This command will abort operation if it detects that the current topic branch has local commits that are not yet pushed to its upstream branch on the remote\. To skip this check, use \fB\-f\fR\. +. +.IP +If \fITITLE\fR is omitted, a text editor will open in which title and body of the pull request can be entered in the same manner as git commit message\. +. +.IP +If instead of normal \fITITLE\fR an issue number is given with \fB\-i\fR, the pull request will be attached to an existing GitHub issue\. Alternatively, instead of title you can paste a full URL to an issue on GitHub\. +. +.SH "CONFIGURATION" +Use git\-config(1) to display the currently configured GitHub username: +. +.IP "" 4 +. +.nf + +$ git config \-\-global github\.user +. +.fi +. +.IP "" 0 +. +.P +Or, set the GitHub username and token with: +. +.IP "" 4 +. +.nf + +$ git config \-\-global github\.user +$ git config \-\-global github\.token +. +.fi +. +.IP "" 0 +. +.P +You can override these values with \fIGITHUB_USER\fR and \fIGITHUB_TOKEN\fR environment variables\. +. +.P +See \fIhttp://help\.github\.com/set\-your\-user\-name\-email\-and\-github\-token/\fR for more information\. +. +.P +If you prefer the HTTPS protocol for GitHub repositories, you can set "hub\.protocol" to "https"\. This will affect \fBclone\fR, \fBfork\fR, \fBremote add\fR and other operations that expand references to GitHub repositories as full URLs that otherwise use git and ssh protocols\. +. +.IP "" 4 +. +.nf + +$ git config \-\-global hub\.protocol https +. +.fi +. +.IP "" 0 +. +.SH "EXAMPLES" +. +.SS "git clone" +. +.nf + +$ git clone schacon/ticgit +> git clone git://github\.com/schacon/ticgit\.git + +$ git clone \-p schacon/ticgit +> git clone git@github\.com:schacon/ticgit\.git + +$ git clone resque +> git clone git@github\.com/YOUR_USER/resque\.git +. +.fi +. +.SS "git remote add" +. +.nf + +$ git remote add rtomayko +> git remote add rtomayko git://github\.com/rtomayko/CURRENT_REPO\.git + +$ git remote add \-p rtomayko +> git remote add rtomayko git@github\.com:rtomayko/CURRENT_REPO\.git + +$ git remote add origin +> git remote add origin git://github\.com/YOUR_USER/CURRENT_REPO\.git +. +.fi +. +.SS "git fetch" +. +.nf + +$ git fetch mislav +> git remote add mislav git://github\.com/mislav/REPO\.git +> git fetch mislav + +$ git fetch mislav,xoebus +> git remote add mislav \.\.\. +> git remote add xoebus \.\.\. +> git fetch \-\-multiple mislav xoebus +. +.fi +. +.SS "git cherry\-pick" +. +.nf + +$ git cherry\-pick http://github\.com/mislav/REPO/commit/SHA +> git remote add \-f mislav git://github\.com/mislav/REPO\.git +> git cherry\-pick SHA + +$ git cherry\-pick mislav@SHA +> git remote add \-f mislav git://github\.com/mislav/CURRENT_REPO\.git +> git cherry\-pick SHA + +$ git cherry\-pick mislav@SHA +> git fetch mislav +> git cherry\-pick SHA +. +.fi +. +.SS "git am, git apply" +. +.nf + +$ git am https://github\.com/defunkt/hub/pull/55 +> curl https://github\.com/defunkt/hub/pull/55\.patch \-o /tmp/55\.patch +> git am /tmp/55\.patch + +$ git am \-\-ignore\-whitespace https://github\.com/davidbalbert/hub/commit/fdb9921 +> curl https://github\.com/davidbalbert/hub/commit/fdb9921\.patch \-o /tmp/fdb9921\.patch +> git am \-\-ignore\-whitespace /tmp/fdb9921\.patch + +$ git apply https://gist\.github\.com/8da7fb575debd88c54cf +> curl https://gist\.github\.com/8da7fb575debd88c54cf\.txt \-o /tmp/gist\-8da7fb575debd88c54cf\.txt +> git apply /tmp/gist\-8da7fb575debd88c54cf\.txt +. +.fi +. +.SS "git fork" +. +.nf + +$ git fork +[ repo forked on GitHub ] +> git remote add \-f YOUR_USER git@github\.com:YOUR_USER/CURRENT_REPO\.git +. +.fi +. +.SS "git pull\-request" +. +.nf + +# while on a topic branch called "feature": +$ git pull\-request +[ opens text editor to edit title & body for the request ] +[ opened pull request on GitHub for "YOUR_USER:feature" ] + +# explicit title, pull base & head: +$ git pull\-request "I\'ve implemented feature X" \-b defunkt:master \-h mislav:feature + +$ git pull\-request \-i 123 +[ attached pull request to issue #123 ] +. +.fi +. +.SS "git checkout" +. +.nf + +# $ git checkout https://github\.com/defunkt/hub/pull/73 +# > git remote add \-f \-t feature git://github:com/mislav/hub\.git +# > git checkout \-b mislav\-feature mislav/feature + +# $ git checkout https://github\.com/defunkt/hub/pull/73 custom\-branch\-name +. +.fi +. +.SS "git create" +. +.nf + +$ git create +[ repo created on GitHub ] +> git remote add origin git@github\.com:YOUR_USER/CURRENT_REPO\.git + +# with description: +$ git create \-d \'It shall be mine, all mine!\' + +$ git create recipes +[ repo created on GitHub ] +> git remote add origin git@github\.com:YOUR_USER/recipes\.git + +$ git create sinatra/recipes +[ repo created in GitHub organization ] +> git remote add origin git@github\.com:sinatra/recipes\.git +. +.fi +. +.SS "git init" +. +.nf + +$ git init \-g +> git init +> git remote add origin git@github\.com:YOUR_USER/REPO\.git +. +.fi +. +.SS "git push" +. +.nf + +$ git push origin,staging,qa bert_timeout +> git push origin bert_timeout +> git push staging bert_timeout +> git push qa bert_timeout +. +.fi +. +.SS "git browse" +. +.nf + +$ git browse +> open https://github\.com/YOUR_USER/CURRENT_REPO + +$ git browse \-\- commit/SHA +> open https://github\.com/YOUR_USER/CURRENT_REPO/commit/SHA + +$ git browse \-\- issues +> open https://github\.com/YOUR_USER/CURRENT_REPO/issues + +$ git browse schacon/ticgit +> open https://github\.com/schacon/ticgit + +$ git browse schacon/ticgit commit/SHA +> open https://github\.com/schacon/ticgit/commit/SHA + +$ git browse resque +> open https://github\.com/YOUR_USER/resque + +$ git browse resque network +> open https://github\.com/YOUR_USER/resque/network +. +.fi +. +.SS "git compare" +. +.nf + +$ git compare refactor +> open https://github\.com/CURRENT_REPO/compare/refactor + +$ git compare 1\.0\.\.1\.1 +> open https://github\.com/CURRENT_REPO/compare/1\.0\.\.\.1\.1 + +$ git compare \-u fix +> (https://github\.com/CURRENT_REPO/compare/fix) + +$ git compare other\-user patch +> open https://github\.com/other\-user/REPO/compare/patch +. +.fi +. +.SS "git submodule" +. +.nf + +$ hub submodule add wycats/bundler vendor/bundler +> git submodule add git://github\.com/wycats/bundler\.git vendor/bundler + +$ hub submodule add \-p wycats/bundler vendor/bundler +> git submodule add git@github\.com:wycats/bundler\.git vendor/bundler + +$ hub submodule add \-b ryppl ryppl/pip vendor/pip +> git submodule add \-b ryppl git://github\.com/ryppl/pip\.git vendor/pip +. +.fi +. +.SS "git help" +. +.nf + +$ git help +> (improved git help) +$ git help hub +> (hub man page) +. +.fi +. +.SH "BUGS" +\fIhttps://github\.com/defunkt/hub/issues\fR +. +.SH "AUTHORS" +\fIhttps://github\.com/defunkt/hub/contributors\fR +. +.SH "SEE ALSO" +git(1), git\-clone(1), git\-remote(1), git\-init(1), \fIhttp://github\.com\fR, \fIhttps://github\.com/defunkt/hub\fR diff --git a/json.sh b/json.sh new file mode 100755 index 0000000..143df85 --- /dev/null +++ b/json.sh @@ -0,0 +1,102 @@ + +throw () { + echo "$*" >&2 + exit 1 +} + +tokenize () { + local ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})' + local CHAR='[^[:cntrl:]"\\]' + local STRING="\"$CHAR*($ESCAPE$CHAR*)*\"" + local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?' + local KEYWORD='null|false|true' + local SPACE='[[:space:]]+' + egrep -ao "$STRING|$NUMBER|$KEYWORD|$SPACE|." --color=never | + egrep -v "^$SPACE$" # eat whitespace +} + +parse_array () { + local index=0 + local ary='' + read -r token + case "$token" in + ']') ;; + *) + while : + do + parse_value "$1" "$index" + let index=$index+1 + ary="$ary""$value" + read -r token + case "$token" in + ']') break ;; + ',') ary="$ary," ;; + *) throw "EXPECTED , or ] GOT ${token:-EOF}" ;; + esac + read -r token + done + ;; + esac + value=`printf '[%s]' $ary` +} + +parse_object () { + local key + local obj='' + read -r token + case "$token" in + '}') ;; + *) + while : + do + case "$token" in + '"'*'"') key=$token ;; + *) throw "EXPECTED string GOT ${token:-EOF}" ;; + esac + read -r token + case "$token" in + ':') ;; + *) throw "EXPECTED : GOT ${token:-EOF}" ;; + esac + read -r token + parse_value "$1" "$key" + obj="$obj$key:$value" + read -r token + case "$token" in + '}') break ;; + ',') obj="$obj," ;; + *) throw "EXPECTED , or } GOT ${token:-EOF}" ;; + esac + read -r token + done + ;; + esac + value=`printf '{%s}' "$obj"` +} + +parse_value () { + local jpath="${1:+$1,}$2" + case "$token" in + '{') parse_object "$jpath" ;; + '[') parse_array "$jpath" ;; + # At this point, the only valid single-character tokens are digits. + ''|[^0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;; + *) value=$token ;; + esac + printf "[%s]\t%s\n" "$jpath" "$value" +} + +parse () { + read -r token + parse_value + read -r token + case "$token" in + '') ;; + *) throw "EXPECTED EOF GOT $token" ;; + esac +} + +if [ $0 = $BASH_SOURCE ]; +then + tokenize | parse +fi diff --git a/kiss.sh b/kiss.sh new file mode 100755 index 0000000..7d920fe Binary files /dev/null and b/kiss.sh differ diff --git a/mfd.sh b/mfd.sh new file mode 100755 index 0000000..96d8243 --- /dev/null +++ b/mfd.sh @@ -0,0 +1,12 @@ +#! /bin/bash +#echo Mediafire Download Script using Plowdown + Axel +#echo Usage mfd URL [num] +url=$1 +if [ ${url:0:4} != http ]; then + url="http://$url" +fi +#echo ${url:0:4} +echo Downloading $url +plowdown -p mtvz --run-download="axel -n 20 -a %url" $url +#Plowdown using axel and 10 threads to download the url + diff --git a/offline_filter.pl b/offline_filter.pl new file mode 100755 index 0000000..06e5090 --- /dev/null +++ b/offline_filter.pl @@ -0,0 +1,142 @@ +#!/usr/bin/perl -Tw + +# Simple liferea (and possibly for other things) conversion filter to download +# content for offline viewing during feed updates. +# +# Pigeon +# +# http://pigeond.net/ +# +# Latest version of this script can be found at: +# git://pigeond.net/offline_filter/ +# +# GPLv2 +# +# +# What it currently does: +# - Look for matching pattern (e.g. img src url). +# - Download it using wget if it is not already downloaded. +# - Replace original src in the feed with the local downloaded one. +# +# Limitations: +# - Will download all matched elements (img), one by one. +# - Will not redownload a file if it has been changed remotely. +# +# TODO: +# - Doesn't handle things spanned across multiple lines +# + +use strict; +use Digest::SHA1 qw(sha1_hex); +use HTML::Entities; + +delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)}; + +my ($HOME) = ($ENV{'HOME'} =~ /([a-zA-Z0-9\/\.\_]+)/); + +my $SAVE_PATH = "${HOME}/.liferea_1.4/cache/saves"; +my $WGET = '/usr/bin/wget'; +my $WGET_TIMEOUT = 5; + +my @BLACKLIST_RE = ( +); + +my $debug = 0; + + +sub url_fetch { + + my ($url) = @_; + + my ($ok) = undef; + + my $outfile = $SAVE_PATH.'/'.sha1_hex($url); + + if ($url =~ m/(\.[a-zA-Z]{3,4})$/) { + $outfile .= lc($1); + } + + if (-f $outfile) { + + if ($debug) { + print(STDERR "Skipping [${url}], already in [${outfile}]\n"); + } + + } else { + + $url = decode_entities($url); + + # use one upper level as referer + my $referer = $url; + $referer =~ s![^/]*?$!!; + + my @args = ($WGET, '-O', $outfile, '-T', $WGET_TIMEOUT); + if (!$debug) { + push(@args, '-q'); + } + + push(@args, "--referer=${referer}"); + + push(@args, $url); + + if ($debug) { + print(STDERR "Running [".join(' ', @args)."]\n"); + } + + if (system(@args) != 0) { + if ($debug) { + print(STDERR "Fetch failed for [${url}]\n"); + } + unlink(${outfile}); + $outfile = undef; + } + } + + return $outfile; +} + + +sub img_func { + my ($matched, $src) = @_; + my ($ok) = undef; + + if ($src ne '') { + + foreach my $u (@BLACKLIST_RE) { + return ${matched} if (${src} =~ ${u}); + } + + my $outfile = url_fetch($src); + + if ($outfile) { + $matched =~ s!\Q${src}\E!file://${outfile}!g; + } + } + return $matched; +} + + +my %handler = ( + + # save images for offline viewing + qr{(?:<|<)img .*?src=(?:"|'|")?(http://.*?)(?:>|>|"|'|"|\s)}i => + 'img_func($&, $1)', + +); + + + + +my @lines = <>; + +system("mkdir -p ${SAVE_PATH}"); + +foreach my $l (@lines) { + foreach my $regex (keys(%handler)) { + $l =~ s/$regex/$handler{$regex}/gee; + } + print($l); +} + +exit(0); + diff --git a/pass.php b/pass.php new file mode 100755 index 0000000..c7fe747 --- /dev/null +++ b/pass.php @@ -0,0 +1,21 @@ +#! /usr/bin/php +" + exit 1 +fi +VIMEO_ID=`echo $1 | awk -F / '{print $NF}'` + +which wget +if [ $? -eq 0 ]; then + echo "Using wget..." + GET_CMD="wget -O -" +else + which curl + if [ $? -eq 0 ]; then + echo "Using curl..." + GET_CMD="curl -L" + else + echo "Could not find wget or curl" + exit 2 + fi +fi + +which perl +if [ $? -eq 0 ]; then + echo "Using perl..." + USING_PERL=1 +else + echo "Using sed..." + USING_PERL=0 +fi + +VIDEO_XML=`${GET_CMD} http://www.vimeo.com/moogaloop/load/clip:${VIMEO_ID}` + +if [ $USING_PERL -eq 1 ]; then + REQUEST_SIGNATURE=`echo $VIDEO_XML | perl -p -e 's:^.*?\(.*?)\.*$:$1:g'` + REQUEST_SIGNATURE_EXPIRES=`echo $VIDEO_XML | perl -p -e 's:^.*?\(.*?)\.*$:$1:g'` + CAPTION=`echo $VIDEO_XML | perl -p -e 's:^.*?\(.*?)\.*$:$1:g'` + ISHD=`echo $VIDEO_XML | perl -p -e 's:^.*?\(.*?)\.*$:$1:g'` + + if [ ${ISHD} -eq 1 ]; then + ISHD="hd" + else + ISHD="sd" + fi + + # caption can contain bad characters (like '/') so don't use it for now + #FILENAME="${CAPTION}-(${ISHD}${VIMEO_ID}).flv" + + FILENAME="${VIMEO_ID}-${ISHD}.flv" +else + REQUEST_SIGNATURE=`echo $VIDEO_XML | sed -e 's/^.*\([^<]*\)<.*$/\1/g'` + REQUEST_SIGNATURE_EXPIRES=`echo $VIDEO_XML | sed -e 's/^.*\([^<]*\)<.*$/\1/g'` + ISHD="sd" + FILENAME=${VIMEO_ID}.flv +fi + +echo "\nDownloading video ${VIMEO_ID} to ${FILENAME}...\nRequest_signature=${REQUEST_SIGNATURE}\nRequest_signature_expires=${REQUEST_SIGNATURE_EXPIRES}\n" +axel -n 10 -a "http://www.vimeo.com/moogaloop/play/clip:${VIMEO_ID}/${REQUEST_SIGNATURE}/${REQUEST_SIGNATURE_EXPIRES}/?q=${ISHD}" -o "${FILENAME}" +echo "Video ${VIMEO_ID} saved to ${FILENAME}" +echo `file "${FILENAME}"` +echo