Font Helper

A slightly tweaked follow up to the previous script…

Font Helper

#!/bin/bash
clear

fontsite=($(
        dialog --nocancel --backtitle "Font Helper" \
        --menu "Font site" --stdout 0 0 0 1 dafont.com \
        2 simplythebest.net
))

let fontsite=$fontsite-1
if [[ "$fontsite" == "0" ]]; then
    fontsite="http://www.dafont.com"
    fonturl="http://img.dafont.com/dl/?f="
elif [[ "$fontsite" == "1" ]]; then
    fontsite="http://simplythebest.net"
    fonturl="http://simplythebest.net/fonts/fonts/font_downloads"
else
    clear
    exit 0
fi

fontlist=($(
        dialog --nocancel --backtitle "Font Helper - ${fontsite}" \
        --inputbox "Space separated list, replace spaces in font names with '-'" --stdout 0 65
))

clear

if [[ -z $fontlist ]]; then
    exit 0
else
    if [[ "$fontsite" == "http://www.dafont.com" ]]; then
            fontsite="http://img.dafont.com/dl/?f="
        fontlist=($(echo ${fontlist[@]} | sed -e 's|-|_|g' | tr "[:upper:]" "[:lower:]"))
        lfont="index.html?f="
        for i in ${fontlist[@]}; do
            i=$(echo ${i} | sed -e 's| ||g')
            tmplist=($(echo ${tmplist[@]} ${i}))
        done
    elif [[ "$fontsite" == "http://simplythebest.net" ]]; then
            fontsite="http://simplythebest.net/fonts/fonts/font_downloads/"
        ext=".zip"
        for i in ${fontlist[@]}; do
            i=$(echo ${i} | sed -e 's|-||g' | tr "[:upper:]" "[:lower:]")
            tmplist=($(echo ${tmplist[@]} ${i}))
        done
    else
            clear
            exit 0
    fi
    fontlist=($(echo ${tmplist[@]}))
fi

[ ! -d /tmp/fonthelper_cache ] && mkdir /tmp/fonthelper_cache
cd /tmp/fonthelper_cache

for i in ${fontlist[@]}; do
    echo -e "\033[1;33m==>\033[1;37m Downloading $i"
    wget -q ${fontsite}${i}${ext}
    ftype=$(file ${lfont}${i}${ext} | awk '{ print $2 }')
    if [[ ${ftype} == "HTML" ]]; then
        echo -e "\033[1;31m==>\033[1;37m Font $i does not exist!"
    else
        [[ "${lfont}${i}${ext}" == "${i}.zip" ]] || mv ${lfont}${i}${ext} ${i}.zip
        exlist="${exlist[@]} ${i}"
    fi
done

if [[ "${exlist[@]}" == "" ]]; then
    echo -e "\033[1;34m==>\033[1;37m No fonts downloaded."
    echo -ne "\033[1;34m==>\033[1;37m Press enter to exit.\033[0m"
    read
    clear
    exit 0
fi
for i in ${exlist[@]}; do
    echo -e "\033[1;34m==>\033[1;37m Extracting $i"
    bsdtar -x -f $i.zip
done

echo -e "\033[1;33m==>\033[1;37m Removing source files..."
for i in ${exlist[@]}; do
    rm $i.zip
done

echo -e "\033[1;33m==>\033[1;37m Checking font directory..."
[ ! -d $HOME/.fonts ] && mkdir $HOME/.fonts

echo -e "\033[1;33m==>\033[1;37m Moving fonts to font directory..."
mv *.[Tt][Tt][Ff] $HOME/.fonts/

echo -e "\033[1;33m==>\033[1;37m Cleaning up..."
cd ..
rm -R /tmp/fonthelper_cache

echo -e "\033[1;32m==>\033[1;37m Done!"
echo -ne "\033[1;32m==>\033[1;37m Press enter to exit.\033[0m"
read
clear

A simple font installer

For those of you who don’t know, my wife is a relatively recent convert to Linux. Although she now wouldn’t switch back to windows for anything, she is far from proficient with the Linux command line. She recently started asking me for help downloading and installing fonts from the dafont website. I decided that I’d rather give her the tools necessary to install fonts herself. The following is what i threw together…

dafontget

#!/bin/bash
clear

fontlist=($(
        dialog --nocancel --backtitle "Font Downloader" \
        --inputbox "Font list - space separated" --stdout 0 0
    ))

clear

if [[ -z $fontlist ]]; then
    exit 0
fi

fontlist=($(echo ${fontlist[@]} | sed -e 's|-|_|g'))

[ ! -d dafont_cache ] && mkdir dafont_cache
cd dafont_cache

for i in ${fontlist[@]}; do
    echo -e "\033[1;33m==>\033[1;37m Downloading $i"
    wget -q http://img.dafont.com/dl/?f=$i
    ftype=$(file index.html?f=$i | awk '{ print $2 }')
    if [[ ${ftype} == "HTML" ]]; then
        echo -e "\033[1;31m==>\033[1;37m Font $i does not exist!"
    else
        mv index.html?f=$i $i.zip
        exlist="${exlist[@]} ${i}"
    fi
done

if [[ "${exlist[@]}" == "" ]]; then
    echo -e "\033[1;34m==>\033[1;37m No fonts downloaded."
    echo -ne "\033[1;34m==>\033[1;37m Press enter to exit.\033[0m"
    read
    clear
    exit 0
fi
for i in ${exlist[@]}; do
    echo -e "\033[1;34m==>\033[1;37m Extracting $i"
    bsdtar -x -f $i.zip
done

echo -e "\033[1;33m==>\033[1;37m Removing source files..."
for i in ${exlist[@]}; do
    rm $i.zip
done

echo -e "\033[1;33m==>\033[1;37m Checking font directory..."
[ ! -d $HOME/.fonts ] && mkdir $HOME/.fonts

echo -e "\033[1;33m==>\033[1;37m Moving fonts to font directory..."
mv *.[Tt][Tt][Ff] $HOME/.fonts/

echo -e "\033[1;33m==>\033[1;37m Cleaning up..."
cd ..
rm -R dafont_cache

echo -e "\033[1;32m==>\033[1;37m Done!"
echo -ne "\033[1;32m==>\033[1;37m Press enter to exit.\033[0m"
read
clear

The new ALM wiki page

So I finally got around to adding a wiki page (or rather a set of pages) to the Arch wiki for ALM. For those of you who are interested in contributing, translating, designing, etc I urge you to check out the wiki for information and updates… For those of you who aren’t considering contributing yet… start! We need more content!

Handling PKGBUILD source downloads, part 2

Here’s the next installment in my previous post on handling PKGBUILD source downloads. dlsouce now includes a switch to allow updating the md5sums array in a PKGBUILD as well as downloading the source… and yes, it (usually) falls back gracefully when the md5sums array is missing…

dlsource

#!/bin/bash
#
# dlsource v0.1 - A simple PKGBUILD source downloader.
# Copyright (C) 2009 Daniel J Griffiths <ghost1227@archlinux.us>
#
# 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.

ASK="\e[0;33m==>\e[0;37m"
INFO="\e[0;34m==>\e[0;37m"
ERROR="\e[0;31m==>\e[0;37m"
SUCCESS="\e[0;32m==>\e[0;37m"
RESET="\e[0m"
unset MD5UPDATE

# Display help
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
    echo "Usage: dlsource [option]"
    echo "Download source(s) for a PKGBUILD."
    echo -e "\n  -m, --md5sum   Update md5sums"
    echo "  -h, --help     Display halp and exit"
    exit 0
fi

# Check for existence of PKGBUILD
if [ ! -f PKGBUILD ]; then
    echo -e "${ERROR} PKGBUILD not found!${RESET}"
    exit 1
fi

# Source PKGBUILD
. PKGBUILD

# Check if md5sum should be updated
if [ "$1" == "-m" ] || [ "$1" == "--md5sum" ]; then
    if [ -z "$md5sums" ]; then
        echo -e "${ERROR} PKGBUILD does not contain md5sums array!${RESET}"
    else
    MD5UPDATE=1
    fi
fi

# Check number of items in source array
if [ ${#source[@]} -gt 1 ]; then
    ANS=-1
    echo -e "${INFO} Multiple sources found!${RESET}"
    count=0
    while [[ ${count} -lt ${#source[@]} ]]; do
        echo -e "    $((count+1)). ${source[${count}]}"
        let count=count+1
    done
    while [[ $ANS -le 0 ]] || [[ $ANS -gt ${#source[@]} ]]; do
        echo -ne "${ASK} Download which source file? "
        read ANS
    done
    rsource=${source[$ANS-1]}
    lsource=$(echo $rsource | rev | awk -F'/' '{ print $1 }' | rev)
    if [ -f $rsource ] || [ -f $lsource ]; then
    echo -e "${ERROR} File already exists in build directory!${RESET}"
    if [ "$MD5UPDATE" != "1" ]; then
            MD5=$(md5sum $lsource | awk '{ print $1 }')
            echo -e "${SUCCESS} MD5SUM: \e[0;32m${MD5}${RESET}"
            exit 0
    fi
    else
        echo -e "${INFO} Downloading $lsource ${RESET}"
        wget -nv $rsource
        if [ ! -f $lsource ]; then
            echo -e "${ERROR} Download failed!${RESET}"
            exit 1
        else
            echo -e "${SUCCESS} Download Complete${RESET}"
        fi
    fi
    MD5=$(md5sum $lsource | awk '{ print $1 }')
    echo -e "${SUCCESS} MD5SUM: \e[0;32m${MD5}${RESET}"
else
    lsource=$(echo $rsource | rev | awk -F'/' '{ print $1 }' | rev)
    if [ -f $rsource ] || [ -f $lsource ]; then
        echo -e "${ERROR} File already exists in build directory!${RESET}"
    if [ "$MD5UPDATE" != "1" ]; then
            MD5=$(md5sum $lsource | awk '{ print $1 }')
            echo -e "${SUCCESS} MD5SUM: \e[0;32m${MD5}${RESET}"
            exit 0
    fi
    else
        echo -e "${INFO} Downloading $lsource ${RESET}"
        wget -nv $rsource
        if [ ! -f $lsource ]; then
            echo -e "${ERROR} Download failed!${RESET}"
            exit 1
        else
            echo -e "${SUCCESS} Download Complete${RESET}"
        fi
    fi
    MD5=$(md5sum $lsource | awk '{ print $1 }')
    echo -e "${SUCCESS} MD5SUM: \e[0;32m${MD5}${RESET}"
fi

if [ "$MD5UPDATE" == "1" ]; then
    echo -e "${INFO} Updating md5sum array in PKGBUILD${RESET}"
    if [ ${#source[@]} -gt 1 ]; then
        OLDMD5=${md5sums[$ANS-1]}
    else
        OLDMD5=${md5sums}
    fi
    sed -i "s|${OLDMD5}|${MD5}|" PKGBUILD
fi

echo -e "${SUCCESS} Done!${RESET}"

Handling PKGBUILD source downloads, part 1

For your average packager, the process of either downloading sources by hand or running makepkg and then updating the md5sums in the PKGBUILD for each new release probably isn’t a huge inconvenience. However, for those of us in the Arch Linux Trusted User and Developer communities that process gets increasingly obnoxious with each rebuild we do, particularly when doing massive amounts of consecutive packages (such as the libjpeg/libpng rebuilds currently under way). The following is the first step in a process to come up with a way of handling those updates more efficiently. It started out as a simple script that sourced out a PKGBUILD, downloaded the source, and ran an md5sum check on it. This quickly proved insufficient for my purposes, as many packages require multiple sources, both local and remote. This version attempts to handle both in a (semi-)intelligent manner.

dlsource

#!/bin/bash
#
# dlsource v0.1 - A simple PKGBUILD source downloader.
# Copyright (C) 2009 Daniel J Griffiths <ghost1227@archlinux.us>
#
# 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.

ASK="\e[0;33m==>\e[0;37m"
INFO="\e[0;34m==>\e[0;37m"
ERROR="\e[0;31m==>\e[0;37m"
SUCCESS="\e[0;32m==>\e[0;37m"
RESET="\e[0m"

# Check for existence of PKGBUILD
if [ ! -f PKGBUILD ]; then
    echo -e "${ERROR} PKGBUILD not found!${RESET}"
    exit 1
fi

# Source PKGBUILD
. PKGBUILD

# Check number of items in source array
if [ ${#source[@]} -gt 1 ]; then
    ANS=-1
    echo -e "${INFO} Multiple sources found!${RESET}"
    count=0
    while [[ ${count} -lt ${#source[@]} ]]; do
        echo -e "    $((count+1)). ${source[${count}]}"
        let count=count+1
    done
    while [[ $ANS -le 0 ]] || [[ $ANS -gt ${#source[@]} ]]; do
        echo -ne "${ASK} Download which source file? "
        read ANS
    done
    source=${source[$ANS-1]}
    lsource=$(echo $source | rev | awk -F'/' '{ print $1 }' | rev)
    if [ -f $source ] || [ -f $lsource ]; then
        echo -e "${ERROR} File already exists in build directory!${RESET}"
        exit 0
    else
        echo -e "${INFO} Downloading $lsource ${RESET}"
        wget -nv $source
        if [ ! -f $lsource ]; then
            echo -e "${ERROR} Download failed!${RESET}"
            exit 1
        else
            echo -e "${SUCCESS} Download Complete${RESET}"
            MD5=$(md5sum $lsource | awk '{ print $1 }')
            echo -e "${SUCCESS} MD5SUM: \e[0;32m${MD5}${RESET}"
            exit 0
        fi
    fi
else
    lsource=$(echo $source | rev | awk -F'/' '{ print $1 }' | rev)
    if [ -f $source ] || [ -f $lsource ]; then
        echo -e "${ERROR} File already exists in build directory!${RESET}"
        exit 0
    else
        echo -e "${INFO} Downloading $lsource ${RESET}"
        wget -nv $source
        if [ ! -f $lsource ]; then
            echo -e "${ERROR} Download failed!${RESET}"
            exit 1
        else
            echo -e "${SUCCESS} Download Complete${RESET}"
            MD5=$(md5sum $lsource | awk '{ print $1 }')
            echo -e "${SUCCESS} MD5SUM: \e[0;32m${MD5}${RESET}"
            exit 0
        fi
    fi
fi

A (not so) simple dmenu wrapper

Like many of my fellow tilers (and probably a few floaters), I find myself frequently relying on dmenu to handle application launching. Unfortunately, dmenu isn’t the brightest crayon in the box. The concept is great but your standard configuration lists every application available on your system. I find this significantly more extensive than I require for my day-to-day use. It’s true there are some wonderful wrappers out there that make dmenu smarter (such as b3n’s smart dmenu launcher), but I didn’t want to make it smarter, I wanted to make it more selective. The following is what I came up with.

dmlauncher

#!/bin/bash
# dmlauncher assumes the existence of the directory $HOME/.dmlcache

addlauncher() {
    if [[ -z $app ]]; then
        echo "dmlauncher: error: missing required argument"
        return 1
    fi

    if which $app &>/dev/null; then
        if [[ -L $HOME/.dmlcache/$ln ]]; then
            echo "dmlauncher: error: \"$link\" launcher already exists"
            return 1
        else
            ln -s $(which $app) $HOME/.dmlcache/$link
            return 0
        fi
    else
        echo "dmlauncher: error: \"$link\" not found in \$PATH"
        return 1
    fi
}

dellauncher() {
    if [[ -L $HOME/.dmlcache/$app ]]; then
        rm -f $HOME/.dmlcache/$app
        return 0
    else
        echo "dmlauncher: error: \"$app\" launcher not found"
        return 1
    fi
}

usage() {
    echo "usage: dmlauncher [-a <program>] || [-d <program>] ||"
    echo "  [-i] [-b] [-fn <font>] [-nb <color>] [-nf <color>]"
    echo " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]"
    return 0
}

dmlrun() {
    exe=`ls $HOME/.dmlcache | dmenu $opt` && exec $exe
}

case "$1" in
    '-a'|'--add')
    app=$2
    if [ ! -z $3 ]; then
        link=$3
    else
        link=$app
    fi
    addlauncher
    ;;
    '-d'|'--del')
    app=$2
    dellauncher
    ;;
    '-h'|'--help')
    usage
    ;;
    *)
    opt=$@
    dmlrun
    ;;
esac

Boredom is a wonderful thing

So I’m sitting at work, bored out of my mind and arbitrarily decided that it was high time I posted a few of my configs… Enjoy!

.bashrc

#------------------------------
# COLORS
#------------------------------
NONE="\[\033[0m\]"
BK="\[\033[0;30m\]" #Black
EBK="\[\033[1;30m\]"
RD="\[\033[0;31m\]" #Red
ERD="\[\033[1;31m\]"
GR="\[\033[0;32m\]" #Green
EGR="\[\033[1;32m\]"
YW="\[\033[0;33m\]" #Yellow
EYW="\[\033[1;33m\]"
BL="\[\033[0;34m\]" #Blue
EBL="\[\033[1;34m\]"
MG="\[\033[0;35m\]" #Magenta
EMG="\[\033[1;35m\]"
CY="\[\033[0;36m\]" #Cyan
ECY="\[\033[1;36m\]"
WH="\[\033[0;37m\]" #White
EWH="\[\033[1;37m\]"

#------------------------------
# ENVIRONMENT VARIABLES
#------------------------------

# BASH/SUDO COMPLETION
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi
complete -cf sudo

# SET PATH
if [ -d $HOME/.bin ]; then
    export PATH=$HOME/.bin:$PATH
fi
if [ -d /usr/share/perl5/vendor_perl/auto/share/dist/Cope ]; then
    export PATH=/usr/share/perl5/vendor_perl/auto/share/dist/Cope:$PATH
fi

# MISC OPTIONS
eval `dircolors -b`
export BROWSER=chromium
export EDITOR=vim
export VISUAL=$EDITOR
export OOO_FORCE_DESKTOP=gnome
shopt -s cdable_vars
shopt -s cdspell
shopt -s checkwinsize
shopt -s cmdhist
shopt -s extglob
set -o noclobber
stty -ctlecho

if [ -f $HOME/.ssh/id_rsa ]; then
    eval `ssh-agent`
    keychain -Q -q $HOME/.ssh/id_rsa
    [[ -f $HOME/.keychain/$HOSTNAME-sh ]] && source $HOME/.keychain/$HOSTNAME-sh
fi

# PROMPT
if [ `id -un` != root ]; then
    PS1="[${GR}\u@\h${BL} \W${NONE}]$ "
else
    PS1="[${RD}\u@\h${BL} \W${NONE}]# "
fi

#------------------------------
# ALIASES
#------------------------------
alias abssearch='ls -R /var/abs/ | grep'
alias fixres="xrandr --size 1280x1024"
alias grep='grep -n --color=auto'
alias hostip='echo `wget -q -O - http://www.whatismyip.org`'
alias ls='ls --group-directories-first --color=auto -h'
alias pacman='sudo pacman-color'
alias psearch='ps aux | grep'
alias reload='source ~/.bashrc'

#------------------------------
# FUNCTIONS
#------------------------------
function aurget() {
    if [ -z $1 ]; then
        echo -e "aurget requires an argument!"
        return 1
    fi

    cd ~/Desktop

    if [ -f $1.tar.gz ] || [ -d $1 ]; then
        echo -e "$1 already exists in build directory!"
        return 1
    fi

    wget -q aur.archlinux.org/packages/$1/$1.tar.gz

    if [ ! -f $1.tar.gz ]; then
        echo -e "$1 does not exist in AUR!"
        return 1
    fi

    tar -xvf $1.tar.gz
    rm $1.tar.gz
    cd $1
}

function cpkg() {
    tar -cf $1.tar $1
    gzip $1.tar
    rm -R $1
}

function extract() {
    for file in "$@"; do
        if [ -f ${file} ]; then
            local file_type=$(file -bizL ${file})
            case ${file_type} in
                *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
                    bsdtar -x -f ${file}    ;;
                *application/x-gzip*)
                    gunzip -d -f ${file}    ;;
                *application/x-bzip*)
                    bunzip2 ${file}     ;;
                *application/x-rar*)
                    7z x ${file}        ;;
                *application/octet-stream*)
                    local file_type=$(file -bzL ${file})
                    case ${file_type} in
                        7-zip*) 7z x ${file} ;;
                        *) echo -e "Unknown filetype for '${file}'\n${file_type}" ;;
                    esac ;;
                *)
                    echo -e "Unknown filetype for '${file}'\n${file_type}" ;;
            esac
        else
            echo "'${file}' is not a valid file"
        fi
    done
}

function reconnect() {
    NET=${1}
    if [ -z ${NET} ]; then
        echo "reconnect: error: missing required argument"
        echo "reconnect: usage: reconnect <network>"
        return 1
    elif [ ! -f /etc/network.d/${NET} ]; then
        echo "reconnect: error: network \"${NET}\" does not exist"
        return 1
    fi
    sudo netcfg -a
    sudo netcfg ${NET}
}

function dlsource() {
    if [ ! -f PKGBUILD ]; then
        echo "This script must be executed in the same directory as a PKGBUILD!"
        return 1
    else
        . PKGBUILD
    fi

    wget $source

    source=$(echo $source | rev | awk -F'/' '{ print $1 }' | rev)
    echo -n "md5sum:  "
    md5sum $source
    echo
}

.Xdefaults

urxvt.depth: 32
urxvt.scrollTtyOutput: 0
urxvt.scrollTtyKeypress: 1
urxvt*geometry: 80x24
urxvt*background: black
urxvt*foreground: white
urxvt*tintColor: black
urxvt*saveLines: 10000
urxvt*title: Terminal
urxvt*font: xft:Terminus:pixelsize=8
urxvt*italicfont: xft:Terminus:pixelsize=8:bold
urxvt*urgentOnBell: true
urxvt.transparent: true
urxvt*inheritPixmap: true
urxvt*perl-ext-common:   default,matcher
urxvt*urlLauncher:   /usr/bin/chromium
urxvt*matcher.button:   1
urxvt*matcher.pattern.1: \\bwww\\.[\\w-]+\\.[\\w./?&@#-]*[\\w/-]
urxvt*secondaryScroll: true
urxvt*jumpScroll: true
urxvt*pastableTabs: true
urxvt*scrollBar: false
urxvt*cursorBlink: true

New website!

Ok, so the announcement’s a little late, but ’tis the season right? I recently released a new site called Geeks Anonymous. But what is GA? Cross FMyLife, geeks, and a (not quite) 12-step program. Still lost? Then stop by and check it out!

PasteIt! back online

My personal pastebin site, PasteIt!, just came back online after a complete overhaul. I’ve scrapped the fancy interface (at least for now), fixed the issues with viewing raw pastes, and brought in a few features taken from the official pastebin.com code that should make a few of my users happy. Check it out at pasteit.ghost1227.com. If anyone finds any issues with it, please feel free to let me know!

CDM site online!

Well, I can’t promise that it’s stable, and it’s certainly not complete, but the basic framework for the CDM page is now online! Check it out via the link in the “My Software” menu at the top of the page.