Fedora Linux Support Community & Resources Center
  #1  
Old 10th November 2012, 12:35 AM
Ihatewindows Offline
Banned
 
Join Date: Oct 2012
Location: Fort Wayne, IN
Posts: 1,135
linuxfirefox
Bad shell script code??

Hi, I was making a shell script to install the RPM Fusion repository and install mp3/mp4 codecs when I ran into a problem. It says that "sudo yum install gstreamer-plugins bad;sudo yum install gstreamer-plugins-ugly is an ivalid command, so I copy/pase it into the terminal, and lo and behold, it works. Here's my code that I made up in Emacs:
Code:
#!/bin/bash
#RPM Fusion installer script
clear
echo "Welcome to the RPM Fusion installer script. The first thing we will do is 
to update your system. You may be prompted for a password."
read -n1 -r -p "Press ENTER to update..." key ENTER
sudo yum upgrade
echo "Now you are ready to install the RPM Fusion repository."
read -n1 -r -p "Press ENTER to download and install the RPM Fusion repository..." key ENTER
sudo rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
sudo rpm -ivh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
#finishing the install with a question
while true; do
    read -p "Do you want to install mp3 and mp4 codecs? (Y/N)" yn
    case $yn in
        [Yy]* ) "sudo yum install gstreamer-plugins-bad;sudo yum install gstreamer-plugins-ugly"; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer Y/N, or press <CTRL>+<C> to quit.";;
    esac
done
echo "You're done!"
read -n1 -r -p "Press ENTER to exit..." key ENTER
clear
Any help is appreciated! Thanks!
Reply With Quote
  #2  
Old 10th November 2012, 01:04 AM
glennzo Online
Un-Retired Administrator
 
Join Date: Mar 2004
Location: Salem, Mass USA
Age: 57
Posts: 14,805
linuxfirefox
Re: Bad shell script code??

Remove the quotes from this line.
PHP Code:
"sudo yum install gstreamer-plugins-bad;sudo yum install gstreamer-plugins-ugly"; break;; 
Actually, you could change the line to
PHP Code:
sudo yum install gstreamer-plugins-bad gstreamer-plugins-ugly; break;; 
No need to call yum twice. I think you should run the whole script with permissions instead of entering passwords several times.


This would be my take on your script. You would only need to enter sudo password once.
PHP Code:
#!/bin/bash
#RPM Fusion installer script

# Need root permissions
if [[ $EUID -ne 0 ]] ; then
   
echo "Need root permissions to execute this script."
   
exit 1
fi

clear
echo "Welcome to the RPM Fusion installer script. The first thing we will do is 
to update your system. You may be prompted for a password."
read -n1 --"Press ENTER to update..." key ENTER
yum upgrade
echo "Now you are ready to install the RPM Fusion repository."
read -n1 --"Press ENTER to download and install the RPM Fusion repository..." key ENTER
rpm 
-ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
rpm -ivh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
#finishing the install with a question
while true; do
    
read -"Do you want to install mp3 and mp4 codecs? (Y/N)" yn
    
case $yn in
        
[Yy]* ) yum install gstreamer-plugins-bad gstreamer-plugins-ugly; break;;
        [
Nn]* ) exit;;
        * ) echo 
"Please answer Y/N, or press <CTRL>+<C> to quit.";;
    
esac
done
echo "You're done!"
read -n1 --"Press ENTER to exit..." key ENTER
clear 
So to run the script you would execute
PHP Code:
sudo sh script.sh 
Maybe the rpmfusion install line from the rpmfusion web site would be more appropriate.
PHP Code:
yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm 
__________________
Glenn
The Bassinator © ®

[SIGPIC][/SIGPIC]
Laptop: Just a couple of old single core units
Desktop: BioStar MCP6PB M2+ / AMD Phenom 9750 Quad Core / 4GB / Kingston HyperX 3K SSD 240GB SATA 3.0 / 1TB SATA / EVGA GeForce 8400 GS 1GB
Reply With Quote
  #3  
Old 10th November 2012, 01:13 AM
sea Online
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Confoederatio Helvetica (Swissh)
Age: 34
Posts: 3,612
linuxfedorachrome
Re: Bad shell script code??

You could actualy 'parse' the users input and add it up to a list which will be installed only once.

Code:
sudo rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm \
	http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm

read -p "want add mp3/mp4 codecs? (y/n)" -n1 ANSWER

[ "y" = "$ANSWER" ] && \
	list="gstreamer-plugins-bad gstreamer-plugins-ugly" || \
	list=""

[ ! "" = "$list" ] && \
	sudo yum install -y $list
EDIT:
For my taste this list is a bit short, as i'd want more out of these packages.
You might want to have a view at my script:
http://sea.hostingsociety.com/?p=Scripts&stc=sea-tpp
__________________
Laptop: Toshiba satellite p50-a-11 CPU: Intel i7 8*2400 MHz GPU: GeForce GT 745M RAM: 8192 MB Distro: Fedora (Rawhide) DE: Awesome
Guide: Windows 8+ & Fedora 20+ Dualboot
Repo (sea-devel) :: Text User Interface (TUI), Video Handler Script (VHS), efi-helper, grub2-circled-nasa-themes, Essentials (blame, p, rmtf, rnd, siggen, screenshot...), (BETA) Dev-Scripts, (BETA) Fedora Account Scripts (FAS)

Last edited by sea; 10th November 2012 at 01:21 AM.
Reply With Quote
  #4  
Old 10th November 2012, 01:22 AM
Ihatewindows Offline
Banned
 
Join Date: Oct 2012
Location: Fort Wayne, IN
Posts: 1,135
linuxfirefox
Re: Bad shell script code??

The permissions check is actually a really good idea. I'm still kinda new to Linux (only been using it for about a year and a half.) I'm gonna make a cheat sheet. Thanks!
Reply With Quote
Reply

Tags
bad, code, emacs, script, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP script won't render in browser - just displays the code mickburkejnr Servers & Networking 1 11th August 2012 08:56 PM
call remote shell script within an expect script PhillyFloyd Programming & Packaging 2 16th October 2007 11:29 PM
starting a shell script inside a php script gw348 Using Fedora 6 23rd April 2007 10:30 PM
shell script Wangberg Programming & Packaging 13 4th April 2007 05:48 PM
need to run script Bourne-shell script armen Using Fedora 4 4th April 2005 02:16 PM


Current GMT-time: 01:20 (Monday, 24-11-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Carrickfergus Photos - Mandapeta Travel Photos - Chelmno Travel Photos on Instagram