Register
It is currently Tue Oct 21, 2014 10:48 pm

Need some help with snippet of bash to do something i need


All times are UTC - 6 hours


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPosted: Thu Dec 14, 2006 1:17 am   

Joined: Mon Sep 18, 2006 1:16 pm
Posts: 27
greetings,

ive been wracking my brains out trying to figure out how to do this one thing I need and I cant seem to figure it out, so im asking in this post in case someone knows a solution. any help would greatly be appreciated.

ok heres what im trying to do. Im working on a script which is posted here:
http://bashscripts.org/viewtopic.php?t=268
and it is supposed to install programs that the user requests to be installed. it works great, but only on the Dapper version of Ubuntu, Xubuntu and Kubuntu. I'm wanting to make this script work on Dapper and Edgy.

the idea is the only things different between the 2 versions that i need to worry with it the sources.list file. this file tells apt-get the repositories to look in to find software.

since the script uses apt-get a LOT this is the issue im having. the sources.list for dapper will not work with edgy and vice versa.

so, what i was thinking is to make the script ask the user are they using dapper or edgy. and if they answer dapper then it will copy the dapper sources.list and if they answer edgy then it will copy the edgy sources.list and continue.

i tried some variations of the read -P thing but im still not skilled enough to figure out how to do this. any help would be GREATLY appreciated.

thank you,
mark


Top
 Profile  
 PostPosted: Thu Dec 14, 2006 5:33 am   
User avatar

Joined: Mon Jul 03, 2006 8:58 pm
Posts: 52
Location: Rochester, NY
It might simply be easier to to do:
Code:
cat /proc/version | grep Dapper

or
Code:
cat /proc/version | grep Edgy


and check the result of each for a non-empty string. This should tell you if you're using Dapper or Edgy (of course, that presumes that the text 'Dapper' and 'Edgy' are somewhere in the 1-line output of 'cat /proc/version'.


Top
 Profile WWW  
 PostPosted: Thu Dec 14, 2006 8:30 am   

Joined: Mon Dec 11, 2006 3:26 pm
Posts: 18
actually /proc/version doesn't say edgy or dapper in it.. just the version number... but he said he was running dapper so i'll give him the edgy (current) version number so he can use that instead
cat /proc/version
Linux version 2.6.17-10-386 (root@vernadsky) (gcc version 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)) #2 Fri Oct 13 18:41:40 UTC 2006 (Ubuntu 2.6.17-10.33-386)



but it seems to me if a user has edgy then they have the edgy sources.list and if they have dapper they have the dapper sources.list so why is it so important to know which they have if they already have their own sources.list... then again i haven't looked at your script so maybe you're trying to write the sources list for them


but on that note... you could grep their existing sources.list for either dapper or edgy and that would tell you which version they have and the script could go from there


Top
 Profile  
 PostPosted: Thu Dec 14, 2006 9:53 am   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
Try checking in /etc for something that references Ubuntu's version......For example, Slackware has a file called slacksare-version with a single line in it: Slackware 11.0.0.............In Debian Sarge, the file is /etc/debian_version with only the version number: 3.1.........Most distros usually have a similar file in it for the purpose of identifying the version, so if you know what the different version numbers are for Dapper and Edgy, then you can grep that file in your script........ :-)


Top
 Profile  
 PostPosted: Thu Dec 14, 2006 10:26 am   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
Okay, after a bit of checking, when Ubuntu first came out it had /etc/debian_version with testing/unstable in it but, like Debian, also had an /etc/issue with something like Ubuntu 5.04 "Hoary Hedgehog" n l...............Although there seems to have been a change by replacing debian_version with ubuntu_version.............Whether Ubuntu still has /etc/issue, you'll have to check for it 'cause I don't know.........

HTH :-)
---thegeekster


Top
 Profile  
 PostPosted: Thu Dec 14, 2006 5:37 pm   
User avatar

Joined: Mon Jul 03, 2006 8:58 pm
Posts: 52
Location: Rochester, NY
Yeah, in Arch it's /etc/arch-release.

cat /etc/arch-release
Arch Linux 0.7.2 (Gimmick)


Top
 Profile WWW  
 PostPosted: Fri Dec 15, 2006 6:40 am   

Joined: Mon Sep 18, 2006 1:16 pm
Posts: 27
Quote:
but it seems to me if a user has edgy then they have the edgy sources.list and if they have dapper they have the dapper sources.list so why is it so important to know which they have if they already have their own sources.list... then again i haven't looked at your script so maybe you're trying to write the sources list for them

well some of the applications that would be installed need repositories that the default ubuntu install doesnt have.

Quote:
Whether Ubuntu still has /etc/issue, you'll have to check for it 'cause I don't know.........

yes it does appear ubuntu (dapper at least) has a /etc/issue
Ubuntu 6.06.1 LTS \n \l is my results from cat /etc/issue

it does seem that looking at the /etc/apt/sources.list on the target machine would tell if its dapper or edgy, but that still leaves me with trying to figure out "how" to make the script figure it all out and copy the right sources.list for the version.

im still not familiar with grep or sed and still learning how to make bash scripts do what i need so excuse me if i sound like a total idiot with bash scripts, lol.


i tried this little snippet inside the script and it failed to work, to me it looked like it should work but it doesnt surprise me that it doesnt, lol.
Quote:
read -p "Are You Using Dapper (yes or no)? " ANSWER2
if [[ $ANSWER2 = yes ]]
then
cp config/sources.list.dapper /etc/apt/sources.list;
else
read -p "Are You Using Edgy (yes or no)? " ANSWER3;
if [[ $ANSWER3 = yes ]];
then;
cp config/sources.list.edgy /etc/apt/sources.list;;
fi;
fi


i also tried
Quote:
read -p "Are You Using Dapper (dapper or edgy)? " ANSWER2
if [[ $ANSWER2 = dapper ]]
then
cp config/sources.list.dapper /etc/apt/sources.list;
if [[ $ANSWER2 = edgy ]]
then
cp config/sources.list.edgy /etc/apt/sources.list;
fi
fi

and that didnt work.

so another option is to have the script check the version of ubuntu and copy the sources without user interaction. i do know the dapper sources.list has dapper inside it a lot and the edgy sources.list has edgy in it a lot.

thank you


Top
 Profile  
 PostPosted: Fri Dec 15, 2006 2:03 pm   

Joined: Mon Dec 11, 2006 3:26 pm
Posts: 18
Code:
E_WRONG_VERSION=99

grep dapper /etc/apt/sources.list
if [ $? -eq 0 ]
then
cp config/sources.list.dapper /etc/apt/sources.list
else
grep edgy /etc/apt.sources.list
if [ $? -eq 0 ]
then
cp config/sources.list.edgy /etc/apt/sources.list
else
echo "You are using a version of Ubuntu that is not supported by this script"
exit $E_WRONG_VERSION
fi
fi


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP