1#!/bin/sh
2
3start() {
4	emule_work_dir=$1
5	[ ! -d $emule_work_dir ] && {
6		echo "emule work dir haven't been prepared exit..." && exit
7	}
8	
9	#update the server.met from web
10	#wget -N http://ed2k.im/server.met -P /tmp
11	#if [ "$?" = "0" ];then
12		#chmod 777 /tmp/server.met
13		#mv /tmp/server.met /etc/aMule/config/server.met
14	#fi
15	#copy amule.conf
16	cp /etc/aMule/amule.conf $emule_work_dir
17	cp /etc/aMule/remote.conf $emule_work_dir
18	cp /etc/aMule/config/*  $emule_work_dir
19	[ ! -f $emule_work_dir/amule.conf -o ! -f $emule_work_dir/remote.conf ] && {
20		echo "Can't get amule configuration exit..." && exit
21	}
22	chmod 777 $emule_work_dir/amule.conf
23	#modify amule.conf
24	dir=$(echo $emule_work_dir | sed 's/\//\\\//g')
25	cat $emule_work_dir/amule.conf | sed -i "s/^TempDir.*/TempDir=$dir\/Temp/" $emule_work_dir/amule.conf
26	cat $emule_work_dir/amule.conf | sed -i "s/^IncomingDir.*/IncomingDir=$dir\/Incoming/" $emule_work_dir/amule.conf
27	cat $emule_work_dir/amule.conf | sed -i "s/^OSDirectory.*/OSDirectory=$dir\//" $emule_work_dir/amule.conf
28
29	#start amuled daomon
30	echo "amule daemon is starting..."
31	amuled -c $emule_work_dir &
32}
33
34stop() {
35	echo "amule daemon is stoping..."
36	killall -9 amuled
37}
38
39restart() {
40	stop
41	start $1
42}
43
44[ $1 = "start" ] && start $2
45[ $1 = "stop" ] && stop
46[ $1 = "restart" ] && restart $2
47