-   Linux - Newbie (
-   -   Adding to DAEMONS/MODULES arrays from bash script (

crabchucker 01-24-2012 04:57 AM

Adding to DAEMONS/MODULES arrays from bash script
I have started playing around with Linux recently (mostly Arch atm) and i am trying to create a Bash script to install the main packages i will be using and to create a user, and i want to be able to add items to the modules and daemons arrays in rc.conf as in changing:



MODULES=(vboxguest vboxsf vboxvideo)

DAEMONS=(hwclock syslog-ng network netfs crond)

DAEMONS=(hwclock syslog-ng network netfs crond sshd vbox-service dbus rpcbind)
What would be the easiest way to do this without destroying my rc.conf file(s)

Also how would i uncomment the Australia mirrors in /etc/pacman.d/mirrorlist from the script aswell

catkin 01-24-2012 05:15 AM

sed with the -i option

crabchucker 01-24-2012 06:41 AM

Thanks for the sed command, i done a bit of searching and came across this website Replace_with_Sed.html and also which helped me understand how to use it and it seems to be working

sed -i 's/#Server = ftp:\/\/\/pub\/archlinux\/$repo\/os\/$arch/Server = ftp:\/\/\/pub\/archlinux\/$repo\/os\/$arch/g' /etc/pacman.d/mirrorlist
plus about 5 more + the modules and daemons arrays, so thanks for the help ^_^
I had to place the backslashes in the url's so it registered the forward slashes in the code instead of other options

David the H. 01-24-2012 10:09 AM

Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.

Perhaps a better way may be to do something like this. Modify the lines in the above script to:


MODULES=( $(</path/to/modulefile ) )
DAEMONS=( hwclock syslog-ng network netfs crond $(</path/to/daemonfile) )"

I'm assuming that this is a bash or ksh script here, as I know of no other shells that use that syntax.

Create those files and put the entries you want inside them, whitespace-delimited. The script should then import them into the arrays. Any other script you write then also only has to append values to those files to make them available.

BTW, have you checked to see whether the script doesn't already support something similar?

Edit: BTW2, your sed command can be made more readable:


sed -i 's|#Server =$repo/os/$arch|Server =$repo/os/$arch|g' /etc/pacman.d/mirrorlist
sed can use any ascii character except newline and null as a substitution delimiter, not just "/".

I'm assuming that the $variables in the urls are meant to be kept literal here? The single quotes around the expression will keep them from expanding. But also, regex expressions match substrings, so you don't really need the whole url, just enough of it to be sure you're getting only the lines you want. You may want to anchor the match to the start of the line as well.


sed -i 's|^#Server =|Server =|g' /etc/pacman.d/mirrorlist

crabchucker 01-24-2012 04:41 PM

Thanks for the advice i will try that out later on, i was just following what i found and was not sure if shortening it would work or not or if i didn't write the whole line, so i will see if that works

All times are GMT -5. The time now is 03:40 AM.