Need Help Writing a Package Script
I have designed a fairly generalized package script for Slackware 12.0. Now, what I want to do make one completely generalized build script. Here's what I have so far.
Code:
name="alsa-utils" Code:
name="alsa-lib" |
Am I right in thinking you want to call:
gen_script alsa-utils-1.0.15.tar.bz2 If so, try: Code:
name =`echo $1|awk -F"-[0-9][0-9]*" ' { print $1 }'` and the version continues until .tar.bz2 |
Yes, you would be correct. Regular expression are confusing me to no end. I'm trying to use expr for the same purpose, but it doesn't seem to give me the correct result.
Code:
bobby@Veronica:~$ expr 'a-b-c' : 'a' |
First when you pass parameters into a script they come in as $1 $2 $3 etc
Therefore if you call: gen_script alsa-utils-1.0.15.tar.bz2 $1 will be equal to "alsa-utils-1.0.15.tar.bz2" I am then passing this string to awk (stay with me) Code:
awk -F"-[0-9][0-9]*" ' { print $1 }' I am then printing the first section { print $1 } Note this $1 is seperate from the $1 passed to our script as it is a part of the awk construct. So now we have our name variable set. The second line passes "alsa-utils-1.0.15.tar.bz2" to sed (string editor) twice, first to search for the $name and the "-" symbol and replace it with nothing sed "s/$name-//" and then to remove the tail part of the string ".tar.bz2" sed 's/.tar.bz2//' I really must go to work now (or I'll be late). |
Wow, thanks I will certainly have to put this stuff to the test.
|
Why don't you have a look at shilo's generic SlackBuild script(see the This is how I do it all sticky) or AlienBob's and rworkmans' scripts at SlackBuilds.org for some ideas. I could suggest that you just use my src2pkg program which obsoletes about 80% of all manually-written SlackBuilds, but I think you are wanting to learn to write bash scripts, so it would be very counter-productive for you to use it. Didn't think I would ever say that... If you just want to make good packages, lots of packages and easily, then do use it. I learned lots of shell language in the process of writing it.
|
Quote:
Here's a perl regex example for you. Code:
$ cat a Using bash/expr Code:
file=alsa-utils-1.0.15.tar.bz2 Code:
file=alsa-utils-1.0.15.tar.bz2 1. remove everything after the last "-" (sets $name to this) 2. remove the $name + a "-" from the beginning ($version="1.0.15.tar.bz2" at this point) 3. remove the ".tar.bz2" from the end of version (setting $version to this) |
Thanks for all your input guys. I'm finally starting to get the hang for regular expressions though I will have to clobber my way through a few more proplems before I can say I have really learned the well. I managed to write my own build script which I'm rather proud of. Here's the code.
Code:
#Assumes that script is run in the same directory as the tar file and that Code:
dest=$1 Code:
-r--r--r-- 1 root root 278 2007-10-30 14:21 alsa-driver-1.0.15.desc |
All times are GMT -5. The time now is 02:48 AM. |