Automating installing xTimeComposer on Linux

Off topic discussions that do not fit into any of the above can go here. Please keep it clean and respectful.
User avatar
Skeksis
Active Member
Posts: 61
Joined: Sat May 28, 2011 9:42 pm
Location: England

Automating installing xTimeComposer on Linux

Postby Skeksis » Sat Mar 30, 2013 9:23 am

Hi all,

I've not been around the forums for a very, very long time; I dug out my board last night to have a tinker & things have changed a bit! Sorting out xTimeComposer took a little while (finding the icon was a pain) so I thought I'd share a Bash script I threw together to automate the process of setting it up.

It's by no means beautiful, but I think it should work for most systems; it needs saving to the same folder as the xTimeComposer tarball, "chmod +x ./filename.sh" and run with sudo.

The script unpacks the tarball to "/opt", creates an application link that includes the icon for the system menu and then adds it to the "Development" section.

Code: Select all

#!/bin/bash

TAR_LOC="./"
TAR_LOC+=$( find *xTIMEcomposer* )
MENU_LOC="/usr/share/applications/xTimeComposer.desktop"
MENU_CONFIG=$HOME"/.config/menus/applications-kmenuedit.menu"

if [[ ! -a $TAR_LOC ]]; then
	if [[ -L $TAR_LOC ]]; then
		echo "Error, '$TAR_LOC' is a broken symlink."
	else
		echo "Error, '$TAR_LOC' does not exist."
	fi
else
	ARRAY=( $( echo $TAR_LOC | tr "()" "\n" ) )
	
	VERSION=${ARRAY[2]}
	
	if [[ "$VERSION" == "" ]]; then
		echo "Error, file version not found."
	else
		tar -xf $TAR_LOC -C /opt
		CHECK=$( ls /opt/XMOS )
		
		if [[ $CHECK == "xTIMEcomposer" ]]; then
echo "[Desktop Entry]
comment=
Exec=/opt/XMOS/xTIMEcomposer/$VERSION/xtimecomposer
GenericName=XMOS Programming Suite
Icon=/opt/XMOS/xTIMEcomposer/$VERSION/xtimecomposer_bin/configuration/org.eclipse.osgi/bundles/11/1/.cp/icons/xde_c_128.png
Name=xTimeComposer
NoDisplay=false
StartupNotify=true
Terminal=0
TerminalOptions=
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=" > $MENU_LOC
			
			DEV_LINE=$( grep -n '<Name>Development</Name>' $MENU_CONFIG | cut -f1 -d: )
			INC_ARRAY=( $( grep -n '</Include>' $MENU_CONFIG | cut -f1 -d: ) )
			
			for LINE in "${INC_ARRAY[@]}"
			do
				if [[ "$LINE" -gt "$DEV_LINE" ]]; then
					sed -i $LINE'i <Filename>xTimeComposer.desktop</Filename>' $MENU_CONFIG
					break
				else
					echo $LINE
				fi
			done
			
			echo "Added to the menu, all done!"
		else
			echo "Error, the extraction failed. Try again with sudo."
		fi
	fi
fi
Pastbin link


All the best,
Skeksis

Who is online

Users browsing this forum: No registered users and 0 guests