PDA

View Full Version : A small bash script to install smplayer themes and skins in Fedora 20



buchalkalan
18th May 2014, 08:40 PM
In Fedora 20, you can install the SMPlayer via yum but it is not possible to do the same for accompanying themes and skins. This might be an annoyance for the novice users or those who have recently switched to Fedora Linux. I have written a small bash script to automatically install the SMPlayer accompanying themes and skins.The script is attached herewith. Just open a terminal window, make the script executable and run it with administrative privileges. Alternatively, just copy the below commands to your terminal window and hit Enter on the keyboard.

chmod +x smthemesskins.sh; sudo ./smthemesskins.sh
Hopefully, the script works for you. Please share your thoughts on the script. Any improvements/comments/suggestions/errors will be welcomed.

kurtdriver
21st May 2014, 08:53 PM
Two things stand out, one is that your script fails if smplayer is not installed. Why not have the script install it with the other stuff?

The way you call programs is unusal. On the line 40 you call wget, and tar later on, by first declaring a variable which is the output of which and then call the variable. I'd just call the program directly. Tar, Wget, and CP all run well from scripts. Calling them directly speeds a script up and uses fewer of the machines resources.

Edit: You really don't need to unset those variables, either.

ocratato
22nd May 2014, 02:42 AM
A few points if I may:

+ It might be better to save and unpack the files into a temporary directory - it is possible (albeit unlikely) the user will have other files in the directory that match, say from previous experiments.

+ the test for $checksmplayer will crash if the program is not installed since it won't have a value. Same for "$checkwget".

+ checkcp is unused

+ the URLs include the 20131003 directory. It would appear that the script will need to be updated whenever a new version is distributed - but the user will have no way of telling that that has happened.

+ the normal user will not have permission to install into /usr/share/smplayer.

kurtdriver
22nd May 2014, 04:46 AM
I think it's great that you are interested in scripting.

In reading it a second time, the for loops are not needed, you can call tar directly. You already know the name of the tarball.

With regard to for loops, say you have a directory filled with music files, mp3s. flacs, wavs, etc. A for loop will let you act on just one extension file.



for i in *.mp3;
do
cp /home/kurt/music/$i /somewhere/else
done

This would copy all of the mp3s and no others.

buchalkalan
3rd June 2014, 05:09 AM
@KD and Ocratato

Thanks for your comments/suggestions. I have got stuck in some other things at the moment. I will get back to the script after sometime and will try to implement the suggestions mentioned in your posts.

Thanks

buchalkalan
11th September 2014, 05:45 AM
I have updated the script and made some more changes. The updated file is attached to the first post. It would be great if you can provide some input on the shell script.

Thanks in advance.

sea
11th September 2014, 07:06 AM
As already stated, this script requires you having root rights, so add a check like:

[ ! 0 -eq $UID ] && echo "$0: Requires root rights!" && exit 1

When working with multiple files/folders retrieved from somewhere else, actualy cd'ing to the dirs then rm -fr something.. i'd highly recomend to set a variable with the current (base/source) dir.

line 41: you copy themes/skin rather than skin.

What tar's and loops are you talking about?
I actualy re-added a loop :confused:


dest=/usr/share/smplayer
src=$(pwd)
URL="https://subversion.assembla.com/svn/smplayer/smplayer"
[ ! 0 -eq $UID ] && echo "$0: Requires root rights!" && exit 1
if [ -x $(which svn > /dev/zero 2>/dev/zero) ] && [ -o $(which smplayer > /dev/zero 2>/dev/zero) ]
then printf "\nFound svn, fetching the required directories....\n"
svn co $URL-themes/trunk/themes/ themes > /dev/null
svn co $URL-skins/trunk/themes/ skins > /dev/null
else
printf "\e[1;31mThis script requires the installation of SMPlayer and SVN.\e[0m\n"
exit 1
fi

# copy the files to the required directory
for task in themes skins;do
dest+="/$task" # This is only because skins is a subdir of themes
#[ $task = skins ] && dest=${dest/themes/skins} # Uncomment this if(as) 'themes' has no subdir named 'skins'....
# Acutaly, id recoment to use set $dest_work to "$dest/$task" within the loop, and therefor scratch the above lines and change the below ones accordingly
[ -d $dest ] || mkdir -p $dest
cd $src/$task
rm -rf *.qrc Makefile
cp -R * $dest
RET=$?
done
[ 0 -eq $RET ] && \
echo "Script executed successfully." ||
echo "Script failed..."

Hope this helps


EDIT:
But actualy this would suffice :p

dest=/usr/share/smplayer
URL=https://subversion.assembla.com/svn/smplayer/smplayer

[ ! 0 -eq $UID ] && \
echo "$0: Requires root rights!" && \
exit 1
svn co $URL-themes/trunk/themes/ $DEST/themes > /dev/zero
svn co $URL-skins/trunk/themes/ $DEST/themes/skins > /dev/zero
[ 0 -eq $? ] && \
echo "Script executed successfully." ||
echo "Script failed... (requires svn & smplayer installed)"
EDIT2:
IMHO, if one actualy checks for an app to be installed, one should also enable offer to install it (the req's)

buchalkalan
11th September 2014, 04:00 PM
Indeed, the last one seems the most efficient. Thanks for the input. Just couple of points, the downloaded directories contain .qrc files and a Makefile which I believe are unnecessary for the themes to work.