LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-21-2005, 03:56 AM   #1
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Rep: Reputation: 15
checking for dir then moving on


i have now wrote this my first script for a mate who is setting up game servers and it works

but i would like to use the lndir command so what i would like to try and do is

when they try and install a game it checks to see if the base dir is there and if it is it moves on to set up the user dir with the crosslink dirs and other files needed for the server to run

but if it is not there then it unpaks that dir first then moves on to next step of setting up the users dir with linked files and there own files for running the server

any ideas ion how i coul do this

here the the existing script long i know but it works

#!/bin/bash

# Server INstall

clear

echo " Install One Of The Following"
echo " ------- --- -- --- ---------"
echo "Choose one of the following by inputing number then hit return"
echo
echo " 1: Medal of Honour Allied Assault"
echo " 2: Medal of Honour Spearhead"
echo " 3: Call of Duty"
echo " 4: Counterstrike"
echo " 5: Teamspeak"
echo " 6: Ventrillo"
echo
echo " Press enter to exit"
echo

read person

case "$person" in


"1" | "1" )
echo
echo "please type a folder to install to and hit return"
echo
read folder
tar -xvvf mohaa.tar
mv server1 $folder
chmod 755 $folder/mohaa_loop.sh
cd $folder
clear
echo "Setting up mohaa_loop file"
echo "------- -- ---------- ----"
echo
echo "Please enter ip then press enter"
read first
sed s/address/$first/ mohaa_loop.sh > new.sh
echo
echo "Now enter port number followed by enter"
read richard
sed s/fifth/$richard/ new.sh > new4.sh
echo
echo "Nearly done just size of server now and enter"
read server
sed s/sixth/$server/ new4.sh > new5.sh

clear

cd /home/archive/$folder/main

echo "Setting up server.cfg"
echo "------- -- ----------"
echo
echo "Please give server name "
read name
sed "s/clan/$name/g" server.cfg > cfg.cfg
echo
rm server.cfg
echo "Please set an rcon password"
read rcon
sed s/leader/$rcon/g cfg.cfg > cfg1.cfg
echo
rm cfg.cfg
echo "And finally cfg player slots"
read slots
sed s/slots/$slots/g cfg1.cfg > server.cfg
rm cfg1.cfg

clear

echo "Ok now for the in game messages"
echo
echo "First message"
echo "if no message is need just hit enter"
read msg1
sed "s/msg1/$msg1/g" server.cfg > cfg.cfg
rm server.cfg

echo "Second message"
echo "if no message is need just hit enter"
read msg2
sed "s/msg2/$msg2/g" cfg.cfg > cfg1.cfg
rm cfg.cfg

echo "Third message"
echo "if no message is need just hit enter"
read msg3
sed "s/msg3/$msg3/g" cfg1.cfg > cfg2.cfg
rm cfg1.cfg

echo "Forth message"
echo "if no message is need just hit enter"
read msg4
sed "s/msg4/$msg4/g" cfg2.cfg > cfg3.cfg
rm cfg2.cfg

echo "Fifth message"
echo "if no message is need just hit enter"
read msg5
sed "s/msg5/$msg5/g" cfg3.cfg > cfg4.cfg
rm cfg3.cfg

echo "Sixth message"
echo "if no message is need just hit enter"
read msg6
sed "s/msg6/$msg6/g" cfg4.cfg > cfg5.cfg
rm cfg4.cfg

echo "Seventh message"
echo "if no message is need just hit enter"
read msg7
sed "s/msg7/$msg7/g" cfg5.cfg > cfg6.cfg
rm cfg5.cfg

echo "Eighth message"
echo "if no message is need just hit enter"
read msg8
sed "s/msg8/$msg8/g" cfg6.cfg > server.cfg
rm cfg6.cfg

sed s/folder/$folder/g start.sh > $folder
rm start.sh
mv $folder $folder.sh
chmod 755 $folder.sh
mv $folder.sh /home/
cd /home/archive/$folder

rm mohaa_loop.sh
rm new.sh
rm new4.sh
mv new5.sh mohaa_loop.sh
cd /home/archive
chmod 755 $folder/mohaa_loop.sh
mv $folder /home
cd /home/$folder

clear
echo "Game now installed to $folder"
echo
echo "Server IP =$first"
echo "Port =$richard"
echo "Startscript located here /home/$folder.sh"
echo
echo "All Thats left to do is setup ftp now"
echo
echo "This Script was brought to you by an old friend"
echo
echo
;;



* )
# Default option.
# Empty input (hitting RETURN) fits here, too.
echo
echo "Changed your mind then."
;;

esac

echo

exit 0



i have taken out 2 - 6 as not needed for this question as if i get an answer i can adopt it

i would also like to be able to set up ftp accounts via the useradd command but this does not work unless im logged in as root is there away of doing this. i know there is the su cmd and sudo but how would i implement this into the script

thanks might be asking to much here but i know you linux junkies just like me are getting the bug im hook on linux at mo


thanks in advance

Last edited by rharris72; 11-21-2005 at 06:06 AM.
 
Old 11-22-2005, 02:05 PM   #2
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
Checking for a directory:

Code:
if [[ -d $dir ]]; then
        ... do whatever ....
fi
 
Old 11-22-2005, 02:31 PM   #3
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Original Poster
Rep: Reputation: 15
ok thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
moving a file from a cd-rom to root dir stupidloser Linux - Newbie 4 08-06-2004 08:04 AM
copying/moving stalls when moving a lot of data to a usb stick =X= Linux - Hardware 10 07-30-2004 05:29 AM
howto make a dir shared that is not in my home dir Schmurff Linux - Newbie 2 06-19-2004 07:54 PM
krecipes and ./configure -with-qt-dir=DIR disco rugby Linux - Software 4 06-13-2004 09:06 PM
checking for X... no cmd Linux - Newbie 3 02-22-2004 04:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration