5

I'm not a server guru (unfortunately) but have a decent knowledge of linux & bsd. I'm trying to symlink multiple instances of HLDS (game server) but need to exclude certain folders & config files to achieve this properly. I need to do it this way as HLDS loads many mods automatically, and putting an exception to disable the mods doesnt work for all of them.

so basically i want:

/home/user/hlds-install (the base install)
/home/user/server1
/home/user/server2
etc...

and then be able to manually put any configs/mods ive excluded into the server dir's so that each server can be configured individually.

Can anyone tell me how to do this, perhaps some sort of bash script so that I can just change the targets to run it each time i want to create a new one. I have quite a number to make so doing the whole thing manually for each one definately isn't an option and im all for working smarter, not harder!

Thanks :)

Jarrod White
  • 51
  • 1
  • 2

2 Answers2

4

I assume you really mean "symlink everything inside the folder"...

Conceptually, you want something like:

for each file in base folder not in exclude list
    create symlink in target folder pointing back to base folder
done

bash logic to achieve this goes something like

#! /bin/bash

exclude=( "foo.conf" "bar.conf" )

for file in *; do
    for (( index = 0; index < ${#exclude[@]}; index++ )); do
        if [[ ${file} != ${exclude[${index}]} ]]; then
            ln -s ${file} ${target}/${file}
        fi  
    done
done

Assuming you don't know already, the Advanced Bash-Scripting Guide should give you enough to work out what globbing you want (perhaps find) and how to convert that to a function (perhaps a recursive one).

Andrew
  • 7,772
  • 3
  • 34
  • 43
  • thanks :) sorry if I confused the wording. so yeah I do want to make it recursive, to copy the whole folder structure for the base installation - and then just exclude certain folders or files from being linked. will check out that scripting guide! – Jarrod White Jul 30 '10 at 02:36
1

You could (ab)use xstow. This program is designed to populate a forest of symbolic links, which is close to what you want. It doesn't have an option to exclude some files, but you can hack it, sort of. For each server:

  1. Create files that you want to exclude from this server. The contents don't matter, they just have to be easy to tell afterwards, so we'll make them all hard links to one particular file.
  2. (You don't mention this in your requirements but it's easy to fit in.) Symlink files that must have a server-specific contents from a hierarchy that contains only those files.
  3. Symlink files from the base install. Skip over any file that's already present.
  4. Remove the files we in fact wanted to exclude from this server.
cd .../targets/server1
touch .exclude
for x in files to exclude; do mkdir -p "$(dirname "$x")"; ln .exclude "$x"; done
xstow -d .../sources -t . server1-specific-files
xstow -f -d .../sources -t . base-install
find -samefile .exclude -exec rm {} +