You are not logged in.
Here is the script: http://pastebin.archlinux.org/12509
Basically I'm making this script to automate the process of creating svn repositories a bit, and to help a gaming server (revora.net : C&C community).
If anything I just need help getting that sed section to work, but any other corrections or suggestions for the script would be grea, too. This is my first bash script that has purpos and hopefully I did an ok job with it so far. Yes, that get_input function is copied from adduser script; it came in handy.
After the script is done another community member is going to make a php script which uses this script to allow hostees and staff of the site to create repositories.
So any help or suggestions would be great.
~jnengland77
Offline
I think what you're looking for is this?
# copy svnserve.conf based on whether
if [[ ${priv_pub} = private ]]; then
cp ${svn_stuff}/confs/svnserve.conf_priv svnserve.conf
sed -i "s/password_file/\"$repoconf_dir\"\/${reponame}\/yourmoma/g" ${svnrepo_dir}/conf/svnserve.conf
else
cp ${svn_stuff}/confs/svnserve.conf_pub svnserve.conf
sed -i "s/password_file/\"$repoconf_dir\"\/yourmoma/" ${svnrepo_dir}/conf/svnserve.conf
sed -i "s/division_name/\"$division\"/g" ${svnrepo_dir}/conf/svnserve.conf
fi
Basically, any variables ($foo) between single-quotes ( ' ) are not evaluated. So, in a bash script, '$foo' ends up being exactly the string $foo, whereas "$foo" will evaluate the variable foo.
eg.
#!/bin/bash
foo=4
# will output $foo to the screen
echo '$foo'
# will output 4 to the screen
echo "$foo"
Last edited by Cerebral (2007-08-12 23:32:31)
Offline
Thanks for your help. The one that replaces the division_name works great (I didn't want the " " so I removed them). However, the one with password_file doesn't change.
I think I tried sed before with double-qoutes, but it did and still does give me this error: sed: -e expression #1, char 18: unknown option to `s' . So I tried to find a different way, but couldn't get anything to work.
~jnengland77
Last edited by jnengland77 (2007-08-12 23:59:58)
Offline
what about this?
# copy svnserve.conf based on whether
if [[ ${priv_pub} = private ]]; then
cp ${svn_stuff}/confs/svnserve.conf_priv svnserve.conf
sed -i "s#password_file#${repoconf_dir}/${reponame}/yourmoma#g" ${svnrepo_dir}/conf/svnserve.conf
else
cp ${svn_stuff}/confs/svnserve.conf_pub svnserve.conf
sed -i "s#password_file#${repoconf_dir}/yourmoma#" ${svnrepo_dir}/conf/svnserve.conf
sed -i "s#division_name#${division}#g" ${svnrepo_dir}/conf/svnserve.conf
fi
Just for an explanation - sed will use whatever character follows the 's' as its delimiter. Since your pathnames had the '/' character in them, it was probably confusing sed, because if repoconf_dir=/my/path and reponame=bob, then a line like this
"s/password_file/$repoconf_dir\/$reponame\/yourmoma/g"
would be passed to sed like this:
"s/password_file//my/path\/bob\/yourmoma/g"
Notice how the forward slashes in /my/path would confuse sed, since they're not escaped.
Changing the delimiter to # however, would make the line
"s#password_file#/my/path/bob/yourmoma#"
And no confusion happens - it treats the forward slashes like regular characters.
Last edited by Cerebral (2007-08-13 00:43:11)
Offline
Yeah that works great, thanks. Does the rest of my script look fine?
I did try using # as well, but not work double-qoutes. I guess in the frustion I didn't give it a try.
~jnengland77
Last edited by jnengland77 (2007-08-13 00:53:35)
Offline
Yeah, the rest of it looks pretty alright. There's enough similarity in your input routines that I feel like some refactoring can be done there, (while needinput, get input, validate input) but I'm not sure how I'd do the refactoring personally.
Offline
Yeah I'm not really sure how else to do it. I basically tried to mimic how adduser script works, and used a couple of bash tutorials. Here is the newest script. Not a lot changed, but fixed a few errors. http://pastebin.archlinux.org/12573
Thanks for your input,
jnengland77
Offline