All pastes #1563205 Raw Edit

clueless

public text v1 · immutable
#1563205 ·published 2009-09-12 15:00 UTC
rendered paste body
#!/bin/bashset +x#	-------------------------------------------------------------------##	Shell program to check for new nvidia drivers.##	Copyright 2009, Norbert Varzariu <loomsen@googlemail.com>						##	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.##	Revision History:##	09/01/2009	File created by new_script ver. 2.1.0## ================================================================# If you add something, please update the ChangeLog accordingly. # You may want to add support for legacy versions for instance.# Draft on how the header should look:# * $(date +'%a %b %d %Y') Name Mail - %version## ================================================================##	 ChangeLog:#	* Sat Sep 12 2009 Norbert Varzariu <loomsen@googlemail.com> - 0.0.3#	- fixed x86 download#	* Tue Sep 01 2009 Norbert Varzariu <loomsen@googlemail.com> - 0.0.2#	- added check for currently running driver #	- added check for locally available binary ###	-------------------------------------------------------------------#	Constants#	-------------------------------------------------------------------	PROGNAME=$(basename $0)	VERSION="0.0.2"	DRVINFO=http://people.freedesktop.org/~aplattner/nvidia-versions#	REPO="ftp://download.nvidia.com/XFree86/`uname`-$__UNAME"## only call if new driver download requested, not if dump version only	LOCALVER="`nvidia-settings -q  NvidiaDriverVersion --terse`"# ================== common functions ============================function clean_up{	rm -f ${TEMP_FILE1}}function error_exit{	echo "${PROGNAME}: ${1:-"Unknown Error"}" >&2	clean_up	exit 1}function graceful_exit{	clean_up	exit}function signal_exit{	case $1 in		INT)	echo "$PROGNAME: Program aborted by user" >&2			clean_up			exit			;;		TERM)	echo "$PROGNAME: Program terminated" >&2			clean_up			exit			;;		*)	error_exit "$PROGNAME: Terminating on unknown signal"			;;	esac}function make_temp_files{	if [ -d ~/tmp ]; then		TEMP_DIR=~/tmp	else		TEMP_DIR=/tmp	fi	TEMP_FILE1=$(mktemp -q "${TEMP_DIR}/${PROGNAME}.$$.XXXXXX")	if [ "$TEMP_FILE1" = "" ]; then		error_exit "cannot create temp file!"	fi}function usage{	echo -e "Usage: ${PROGNAME} [-h | --help] [-b] [-B download_dir] [-a] [-A download_dir]\n 	\t     [-o] [-O download_dir] [-s] [-S download_dir]"}function helptext{	local tab=$(echo -en "\t\t")	cat <<- -EOF-	${PROGNAME} ver. ${VERSION}	This is a program to check for currently available nVidia drivers.	$(usage)	Options:	-h, --help		Display this help message and exit.		-s              	list current stable	-S  download_dir	get current stable		-b              	list current beta	-B  download_dir	get current beta		-o              	list opengl3 beta drivers		-O  download_dir	get opengl driver		-a              	list all available	-A  download_dir	get all available-EOF-}# ====================== program specific functions ==========function get_latest_driver_listing {echo -e "Checking for update"wget -q "$DRVINFO" --output-document=$TEMP_FILE1LATEST=$TEMP_FILE1}function getopts_version{REPO="ftp://download.nvidia.com/XFree86/`uname`-$__UNAME"VER_NUM=`grep "$VER" < $LATEST | awk '{print $3}'`# bugfix uname -m outputif [ "`uname -m`" != "x86_64" ]; then	__UNAME="x86"else	__UNAME=`uname -m`fi# bugfix endPKG="NVIDIA-`uname`-$__UNAME-$VER_NUM-pkg0.run"echo "your choice: Driver $VER_NUM"if [ "$LOCALVER" == "$VER_NUM" ]; then	if ! ask_yes_no "you already have that driver installed, do you want me to download the binary regardless? [y/N] "; then		signal_exit INT	fifiif [ -f $OPTARG/$VER_NUM/$PKG ]; then	echo -e "you already have the source available on your local machine, \nlook into $OPTARG/$VER_NUM/"	echo "nothing to do, exiting..."	graceful_exitfi}function download_driver{REPO="ftp://download.nvidia.com/XFree86/`uname`-$__UNAME"echo "downloading, hold on..."mkdir -p $OPTARG/$VER_NUMwget -q $REPO/$VER_NUM/$PKG --output-document=$TEMP_DIR/$PKG || error_exit "couldnt download driver file"mv $TEMP_DIR/$PKG $OPTARG/$VER_NUM || error_exit "couldnt move package to specified dir, do you have proper permissions?"echo -e "done! your files are in \n$OPTARG/$VER_NUM"}function ask_yes_no{	local yn=	while [ "$yn" = "" ]; do		echo -en "$1"		read yn		case $yn in			y|Y)	yn=0 ;;			n|N)	yn=1 ;;			*)	yn=				echo "Invalid response - please answer y or n"				;;		esac	done	return $yn}function get_them_all{if ! ask_yes_no "this will download all files, are you sure?  [y/n] "; then	signal_exit INTelseecho "downloading, hold on..."	PKG=	# bugfix uname -m		if [ "`uname -m`" != "x86_64" ]; then		__UNAME="x86"	else		__UNAME=`uname -m`	fi	REPO="ftp://download.nvidia.com/XFree86/`uname`-$__UNAME"	grep -v '#' $LATEST | head -n 3 > $TEMP_DIR/TEMP_FILE2	for i in `awk '{print $3}' $TEMP_DIR/TEMP_FILE2`; do		mkdir -p $OPTARG/$i		PKG="NVIDIA-`uname`-$__UNAME-$i-pkg0.run"		wget -q $REPO/$i/$PKG --output-document=$TEMP_DIR/$PKG ; mv $TEMP_DIR/$PKG $OPTARG/$i/	doneecho -e "Your files are in $OPTARG/"rm $TEMP_DIR/TEMP_FILE2fi}#	Program starts here# Set file creation mask so that all files are created with 600 permissions.umask 066# Trap TERM, HUP, and INT signals and properly exittrap "signal_exit TERM" TERM HUPtrap "signal_exit INT"  INT# Create temporary file(s)make_temp_files##### Command Line Processing ####### prevent download when usage or help message is to be displayedif [ "$1" = "--help" -o "$1" = "-h" ]; then	helptext	graceful_exitelif [ "$1" = "" ]; then	usage	graceful_exitelse	get_latest_driver_listingfiwhile getopts ":hbB:aA:oO:sS:" opt; do	case $opt in		b )	awk /'current beta'/ $LATEST			echo -e "\nYour local version is: $LOCALVER"			graceful_exit			;;		B )	VER='current beta'			download_dir=$OPTARG			getopts_version			download_driver			graceful_exit			;;		a )	grep -v '#' $LATEST | head -n 3			echo -e "\nYour local version is: $LOCALVER"			graceful_exit			;;		A )	download_dir=$OPTARG			get_them_all			graceful_exit			;;		o )	awk /'opengl'/ $LATEST			echo -e "\nYour local version is: $LOCALVER"			graceful_exit			;;		O )	VER='opengl'			download_dir=$OPTARG			getopts_version			download_driver			graceful_exit			;;		s )	awk /'current official'/ $LATEST			echo -e "\nYour local version is: $LOCALVER"			graceful_exit			;;		S )	VER='current official'			download_dir=$OPTARG			getopts_version			download_driver			graceful_exit			;;		*|? )	usage			clean_up			exit 1	esacdonegraceful_exit