Lista plugins/addons för Firefox och Thunderbird

Här diskuterar vi skal, kommandon och klassiska linuxverktyg.
Användarvisningsbild
Osprey
Inlägg: 6310
Blev medlem: 06 apr 2008, 00:09
OS: Ubuntu
Ort: Göteborg/Mölndal/Falkenberg
Kontakt:

Lista plugins/addons för Firefox och Thunderbird

Inlägg av Osprey »

Är det någon mer än jag som har stört sig på att det inte finns något bra sätt att lista filerna för Firefox och Thunderbirds tillägg så att man kan se vad det är för något. Listar man directoryt/mappen där de ligger, så är det till största delen bara en massa obegripliga namn.

Så vid ett anfall av frustration hackade jag ihop ett litet script som gör det här mycket lättare. Namnet är satt till "lsxpi" eftersom de tillägg det listar, heter just *.xpi

För att se hur scriptet funkar så scrolla ner en bit, eller ladda hem det och kör "lsxpi -h" eller "lsxpi --help".

Kod: Markera allt

#! /bin/bash
#
function trim {
	echo "$1" | sed -e 's/^[ \t]*//'
}
function printHead {
	if [[ $FOUND == false ]]; then
		FOUND=true
		echo
		echo "Extension directory:  $EXTDIR"
		echo
		printf "%-50s%s\n" "Filename" "Extension"
		printf "%-50s%s\n" "========" "========="
	fi
}
function printEnd {
	if [[ $FOUND == true ]]; then
		echo
	fi
}
function extract_name {
	NAME=""
	FILETYPE=$(file --mime-type -b $1 | awk -F / '{ print $2 }')
	if [[ $FILETYPE == "zip" ]]; then
		EXTR1=$(unzip -p $1 install.rdf 2> /dev/null | sed -n '/<name>/,$p;/<\/name>/q')
		if [[ -z $EXTR1 ]]; then
			return 2
		fi
	else
		if [[ -r $1/install.rdf ]]; then
			EXTR1=$(cat $1/install.rdf | sed -n '/<name>/,$p;/<\/name>/q')
			if [[ -z $EXTR1 ]]; then
				return 2
			fi
		else
			return 2
		fi
	fi
	EXTR2=$(echo $EXTR1 | awk -F \<name\> '{ print $2 }')
	EXTR3=$(echo $EXTR2 | awk -F \<\/name\> '{ print $1 }')
	EXTR4=$(echo $EXTR3 | sed 's/"//g')
	NAME="$(trim "$EXTR4")"
	return 0
}
function extract_em_text {
	NAME=""
	FILETYPE=$(file --mime-type -b $1 | awk -F / '{ print $2 }')
	if [[ $FILETYPE == "zip" ]]; then
		EXTR1=$(unzip -p $1 install.rdf 2> /dev/null | sed -n '/em:name=/,$p;/em:name/q')
		if [[ -z $EXTR1 ]]; then
			return 2
		fi
	else
		if [[ -r $1/install.rdf ]]; then
			EXTR1=$(cat $1/install.rdf | sed -n '/em:name=/,$p;/em:name/q')
			if [[ -z $EXTR1 ]]; then
				return 2
			fi
		else
			return 2
		fi
	fi
	EXTR2=$(echo $EXTR1 | awk -F em:name= '{ print $2 }')
	EXTR3=$(echo $EXTR2 | awk -F em: '{ print $1 }')
	EXTR4=$(echo $EXTR3 | sed 's/"//g')
	NAME="$(trim "$EXTR4")"
	return 0
}
function extract_em_tag {
	NAME=""
	FILETYPE=$(file --mime-type -b $1 | awk -F / '{ print $2 }')
	if [[ $FILETYPE == "zip" ]]; then
		EXTR1=$(unzip -p $1 install.rdf 2> /dev/null | sed -n '/<em:name>/,$p;/<\/em:name>/q')
		if [[ -z $EXTR1 ]]; then
			return 2
		fi
	else
		if [[ -r $1/install.rdf ]]; then
			EXTR1=$(cat $1/install.rdf | sed -n '/<em:name>/,$p;/<\/em:name>/q')
			if [[ -z $EXTR1 ]]; then
				return 2
			fi
		else
			return 2
		fi
	fi
	EXTR2=$(echo $EXTR1 | awk -F \<em:name\> '{ print $2 }')
	EXTR3=$(echo $EXTR2 | awk -F \<\/em: '{ print $1 }')
	EXTR4=$(echo $EXTR3 | sed 's/"//g')
	NAME="$(trim "$EXTR4")"
	return 0
}
function gethome {
	if [[ -z $1 ]]; then
		HOMEDIR=$(eval echo ~)
	else
		HOMEDIR=$(eval echo "~$1")
		if [[ $HOMEDIR == "~$1" ]]; then
			HOMEDIR=""
		elif [[ -z $HOMEDIR ]]; then
			HOMEDIR=$(grep $1 /etc/passwd | awk -F : '{ print $6 }')
		fi
	fi
}
function argv {
	for a in ${BASH_ARGV[*]} ; do
		echo -n "$a "
	done
	echo
}
function usage {
CMD=$(basename $0)
cat << EOD

NAME
       lsxpi - list Firefox and Thunderbird xpi-files and dirs

SYNOPSIS
       lsxpi  [OPTION]... [FILE]...
             [ {-f|-t} {-g|-u} ]

OPTIONS
       -f, --fire, --firefox
              Show extensions (addons) for Firefox, this is the deafault. Can not be specified in conjunction with "-t".

       -g, --global
              Global shows system-installed extensions that i available for all users. Default is the user-local extensions.
              Can not be specified in conjunction with a username.

       -t, --thunder, --thunderbird
              Show extensions (addons) for Thunderbird. Can not be specified in conjunction with "-f".

       -u uname, --user=uname
              Username for which to show extensions, the default is current user. Can not be specified in conjunction with "-g".

       The default operation if no options are specified is "lsxpi --firefox --user=\$USER"

PARAMETERS
  	FILE may be used to specify which files information is to be retrieved about. If no files are specified, information is
	retrieved about all files. It is possible to use wildcards, but as bash expands them before calling the script ant the
	directory where the files exists may be another than the current, it is necessary to escape the wildcards. For example
	all files beginning with "s" must be specified as s\* and not just as s*

AUTHOR
	Magnus Ewert  <wireless@telia.com>

EOD
}
####################################################################################################################################
TEMP=`getopt -ofghtu: --long fire,firefox,global,help,thunder,thunderbird,user: -n $(basename $0) -- "$@"`
if [[ $? -ne 0 ]]; then
	usage
	exit
fi
eval set -- "$TEMP"
USER=""
FIRE=false
GLOBAL=false
THUNDER=false
while true; do
	case $1 in
		-f|--fire|--firefox)
			FIRE=true
			shift
			;;
		-g|--global)
			GLOBAL=true
			shift
			;;
		-h|--help)
			usage
			exit
			;;
		-t|--thunder|--thunderbird)
			THUNDER=true
			shift
			;;
		-u|--user)
			USER=$2
			shift
			shift
			;;
		--)
			shift
			break
			;;
		*)
			shift
			;;
	esac
done
P1=$1
if [[ $FIRE == true && $THUNDER == true ]]; then
	echo
	echo "-Not possible to specify both Firefox and Thunderbird at the same time"
	echo
	exit
elif [[ $GLOBAL == true && ! -z $USER ]]; then
	echo
	echo "-It it not possible to specify both global and a username"
	echo
	exit
elif [[ $FIRE == false && $THUNDER == false && ! -z $USER ]]; then
	FIRE=true
elif [[ $FIRE == false && $THUNDER == false && $GLOBAL == true ]]; then
	FIRE=true
elif [[ $GLOBAL == true && $FIRE == false && $THUNDER == fasle ]]; then
	echo
	echo "-Global has no meaning if neither Firefox and nor Thunderbird is specified - ignoring"
	echo
fi
if [[ $FIRE == true ]]; then
	if [[ $GLOBAL == true ]]; then
		EXTDIR="/usr/lib/firefox-addons/extensions"
	else
		gethome $USER
		PRFDIR="$HOMEDIR/.mozilla/firefox"
		PRFINI="${PRFDIR}/profiles.ini"
		PROFILE=$(grep "Path=" ${PRFINI} 2> /dev/null | head -n 1 | cut -d'=' -f2)
		if [[ -z $PROFILE ]]; then
			echo
			echo "-No profile exists for user $USER - exiting"
			echo
			exit
		fi
		EXTDIR="$HOMEDIR/.mozilla/firefox/$PROFILE/extensions"
	fi
elif [[ $THUNDER == true ]]; then
	if [[ $GLOBAL == true ]]; then
		EXTDIR="/usr/lib/thunderbird-addons/extensions"
	else
		gethome $USER
		PRFDIR="$HOMEDIR/.thunderbird"
		PRFINI="${PRFDIR}/profiles.ini"
		PROFILE=$(grep "Path=" ${PRFINI} 2> /dev/null | head -n 1 | cut -d'=' -f2)
		if [[ -z $PROFILE ]]; then
			echo
			echo "-No profile exists for user $USER - exiting"
			echo
			exit
		fi
		EXTDIR="$HOMEDIR/.thunderbird/$PROFILE/extensions"
	fi
else
	EXTDIR=$(pwd)
fi
#############################################
if [[ -z $1 ]]; then
	FILES=$(ls -d $EXTDIR/* 2> /dev/null)
else
	FILES=$(ls -d $EXTDIR/$@ 2> /dev/null)
fi
if [[ -z $FILES ]]; then
	exit
fi
FOUND=false
IFS=$(echo -en "\n\b")
for FILE in $FILES; do
	if [[ -d "$FILE" ]]; then
		if [[ -r $FILE/install.rdf ]]; then
			extract_name $FILE
			if [[ -z $NAME ]]; then
				extract_em_text $FILE
				if [[ -z $NAME ]]; then
					extract_em_tag $FILE
					if [[ -z $NAME ]]; then
						continue
					fi
				fi
			fi
			printHead
			FILENAME=$(basename $FILE)
			printf "%-50s%s\n" "$FILENAME" "$NAME"
		fi
	elif [[ -r "$FILE" ]]; then
		FILETYPE=$(file --mime-type -b $FILE | awk -F / '{ print $2 }')
		if [[ $FILETYPE == "zip" ]]; then
			extract_name $FILE
			if [[ -z $NAME ]]; then
				extract_em_text $FILE
				if [[ -z $NAME ]]; then
					extract_em_tag $FILE
					if [[ -z $NAME ]]; then
						continue
					fi
				fi
			fi
			printHead
			FILENAME=$(basename $FILE)
			printf "%-50s%s\n" "$FILENAME" "$NAME"
		fi
	else
		echo "-$FILE does not exist"
	fi
done
printEnd
exit
Agera genom att ta och behålla initiativet, ta de risker detta kräver...
http://www.enargo.com/it/
OpenVMS Shark - i Linux finns inte SYS$CMKRNL...
Användarvisningsbild
Broder Tuck
Inlägg: 3330
Blev medlem: 27 mar 2006, 22:32
OS: Linux Mint
Utgåva: 16.04 Xenial Xerus LTS
Ort: Stockholm / Tumba

Re: Lista plugins/addons för Firefox och Thunderbird

Inlägg av Broder Tuck »

Jag missförstod. Tar bort min kommentar.
Tack ändå, Osprey. Jag tror att du arbetar för en god sak. ;)
Ubuntu med både Gnome och Mate. Kör mestadels med LinuxMint Cinnamon till vardags. Våren 2019.
Skriv svar

Återgå till "Terminalforum"