| 1 | #! /bin/sh | 
|---|
| 2 |  | 
|---|
| 3 | readvalue () { | 
|---|
| 4 | dfl="$1" | 
|---|
| 5 | msg="$2" | 
|---|
| 6 | desc="$3" | 
|---|
| 7 |  | 
|---|
| 8 | echo '' | 
|---|
| 9 | echo $msg | 
|---|
| 10 | echo -n "[ $dfl ] ? " | 
|---|
| 11 | read value | 
|---|
| 12 | value=${value:="$dfl"} | 
|---|
| 13 | echo "$desc <- $value" | 
|---|
| 14 | } | 
|---|
| 15 |  | 
|---|
| 16 | cat <<EOF | 
|---|
| 17 |  | 
|---|
| 18 | MAGIC.MC.DAEMON Configuration Script | 
|---|
| 19 | ======================================== | 
|---|
| 20 |  | 
|---|
| 21 | NOTE:: This script WILL NOT create any directory in | 
|---|
| 22 | the case that it does not exist. | 
|---|
| 23 | You MUST have created all the directories for yourself. | 
|---|
| 24 | You will need : | 
|---|
| 25 |  | 
|---|
| 26 | - an [executables directory]: where I will look for | 
|---|
| 27 | the CORSIKA executables and data files, and | 
|---|
| 28 | for the MMD program. | 
|---|
| 29 |  | 
|---|
| 30 | - a [data directory]: where I will save the data. | 
|---|
| 31 |  | 
|---|
| 32 | - an [administration directory]: where some log-files | 
|---|
| 33 | will be created. | 
|---|
| 34 |  | 
|---|
| 35 | If you DO NOT have yet these directories created, press | 
|---|
| 36 | now Ctrl-C, create them, and write afterwards again | 
|---|
| 37 |  | 
|---|
| 38 | $ make script | 
|---|
| 39 |  | 
|---|
| 40 | Press Return to continue, or Ctrl-C to stop this script. | 
|---|
| 41 | EOF | 
|---|
| 42 | read ans | 
|---|
| 43 |  | 
|---|
| 44 | cat <<EOF | 
|---|
| 45 | +---------------------------------------------------+ | 
|---|
| 46 | | This procedure will ask you about some parameters | | 
|---|
| 47 | | of your system. Please, answer all the questions. | | 
|---|
| 48 | | If you have any doubt, press Ctrl-C.              | | 
|---|
| 49 | +---------------------------------------------------+ | 
|---|
| 50 | EOF | 
|---|
| 51 |  | 
|---|
| 52 | readvalue `pwd` \ | 
|---|
| 53 | "Directory where the CORSIKA and daemon executables should be located:" path-exe | 
|---|
| 54 | pathexe="$value" | 
|---|
| 55 |  | 
|---|
| 56 | readvalue "c520-osf" \ | 
|---|
| 57 | "Enter the executable name:" name-exe | 
|---|
| 58 | nameexe="$value" | 
|---|
| 59 |  | 
|---|
| 60 | readvalue "/data" \ | 
|---|
| 61 | "Disk/path where the bulk of data will be stored:" data-disk | 
|---|
| 62 | datadisk="$value" | 
|---|
| 63 |  | 
|---|
| 64 | readvalue "/data" \ | 
|---|
| 65 | "Disk/path where the administration files will be stored:" adm-disk | 
|---|
| 66 | admdisk="$value" | 
|---|
| 67 |  | 
|---|
| 68 | echo '' | 
|---|
| 69 |  | 
|---|
| 70 | readvalue "0" \ | 
|---|
| 71 | "Final NICE value to use when running CORSIKA" niceval | 
|---|
| 72 | niceval="$value" | 
|---|
| 73 |  | 
|---|
| 74 | readvalue "0" \ | 
|---|
| 75 | "What is your site seed generator?" siteval | 
|---|
| 76 | siteval="$value" | 
|---|
| 77 |  | 
|---|
| 78 | readvalue "no" \ | 
|---|
| 79 | "Do you want to check the system load before running CORSIKA (yes/no)" MACH | 
|---|
| 80 | MACH="$value" | 
|---|
| 81 |  | 
|---|
| 82 | echo '' | 
|---|
| 83 |  | 
|---|
| 84 | readvalue "$USER@$HOST" \ | 
|---|
| 85 | "Enter the e-mail address to sent the log-mailing to" email-add | 
|---|
| 86 | useradd="$value" | 
|---|
| 87 |  | 
|---|
| 88 | echo '' | 
|---|
| 89 |  | 
|---|
| 90 | echo 'Preparing daemon . . .' | 
|---|
| 91 |  | 
|---|
| 92 | cat <<EOF >dmy.sed | 
|---|
| 93 | s=#USERADD#=$useradd=g | 
|---|
| 94 | s=#DATADISK#=$datadisk=g | 
|---|
| 95 | s=#ADMDISK#=$admdisk=g | 
|---|
| 96 | s=#PATHEXE#=$pathexe=g | 
|---|
| 97 | s=#NAMEEXE#=$nameexe=g | 
|---|
| 98 | s=#NICE#=$niceval=g | 
|---|
| 99 | s=#SITE#=$siteval=g | 
|---|
| 100 | EOF | 
|---|
| 101 |  | 
|---|
| 102 | sed -f dmy.sed magic-mc.daemon.tpl > mmd | 
|---|
| 103 |  | 
|---|
| 104 |  | 
|---|
| 105 | if [ $MACH = "yes" ]; then | 
|---|
| 106 |  | 
|---|
| 107 | cat <<EOF >> mmd | 
|---|
| 108 | # get information about system load | 
|---|
| 109 | if ( check_cpu_load() < 3 ) { | 
|---|
| 110 | send_mail( "\n## Top output:\n\n" . \`\$TOP -b\`, 1 ); | 
|---|
| 111 | exit; | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | # make job | 
|---|
| 115 | make_job; | 
|---|
| 116 |  | 
|---|
| 117 | # say bye, execute job and leave this program | 
|---|
| 118 | exec "\$SYSDIR/job.cmds" | 
|---|
| 119 | or croak "Cannot execute job file"; | 
|---|
| 120 | EOF | 
|---|
| 121 |  | 
|---|
| 122 | else | 
|---|
| 123 |  | 
|---|
| 124 | cat <<EOF >> mmd | 
|---|
| 125 | # get information about system load | 
|---|
| 126 | check_cpu_load(); | 
|---|
| 127 |  | 
|---|
| 128 | # make job | 
|---|
| 129 | make_job; | 
|---|
| 130 |  | 
|---|
| 131 | # say bye, execute job and leave this program | 
|---|
| 132 | exec "\$SYSDIR/job.cmds" | 
|---|
| 133 | or croak "Cannot execute job file"; | 
|---|
| 134 | EOF | 
|---|
| 135 |  | 
|---|
| 136 | fi | 
|---|
| 137 |  | 
|---|
| 138 | chmod 744 ${pathexe}/mmd | 
|---|
| 139 |  | 
|---|
| 140 | echo 'MMD (MAGIC-MC.DAEMON) was generated.' | 
|---|
| 141 |  | 
|---|
| 142 | echo '' | 
|---|
| 143 |  | 
|---|
| 144 | echo 'The MAGIC-MC.DAEMON is designed to run from the crontab.' | 
|---|
| 145 |  | 
|---|
| 146 | readvalue "yes" \ | 
|---|
| 147 | "Do you want me to change your crontab (yes/no)?" crntb | 
|---|
| 148 | crntb="$value" | 
|---|
| 149 |  | 
|---|
| 150 | echo '' | 
|---|
| 151 |  | 
|---|
| 152 | echo 'OK, I will change your crontab. I will asume you are using C-shell' | 
|---|
| 153 |  | 
|---|
| 154 | if [ $crntb = "yes" ]; then | 
|---|
| 155 | crontab -l > dmy | 
|---|
| 156 | echo '0,15,30,45 * * * * '${pathexe}'/mmd -n'${niceval}' -q >& '${admdisk}'/last-crontab-out' >> dmy | 
|---|
| 157 | crontab dmy | 
|---|
| 158 | rm -f dmy | 
|---|
| 159 | fi | 
|---|
| 160 |  | 
|---|
| 161 | echo '' | 
|---|
| 162 | echo 'Preparing your administration directory (do not worry about' | 
|---|
| 163 | echo 'some messages like "[file]: No such file or directory"' | 
|---|
| 164 | echo '' | 
|---|
| 165 |  | 
|---|
| 166 | ${pathexe}/mmd -c | 
|---|
| 167 |  | 
|---|
| 168 | echo 'Done.' | 
|---|
| 169 |  | 
|---|
| 170 | cat <<EOF | 
|---|
| 171 |  | 
|---|
| 172 | MAGIC-MC.DAEMON is ready to run. | 
|---|
| 173 |  | 
|---|
| 174 | If you did not ask me to modify your crontab, | 
|---|
| 175 | you must run yourself the program, with the following | 
|---|
| 176 | command line: | 
|---|
| 177 |  | 
|---|
| 178 | $ mmd -n$niceval -q >& ${admdisk}/last-crontab-out | 
|---|
| 179 |  | 
|---|
| 180 | However, it's much better if let my do the dirty work | 
|---|
| 181 | for you. | 
|---|
| 182 |  | 
|---|
| 183 | Good luck. | 
|---|
| 184 |  | 
|---|
| 185 | In case of problems, please contact to <gonzales@hegra1.mppmu.mpg.de> | 
|---|
| 186 |  | 
|---|
| 187 | EOF | 
|---|
| 188 |  | 
|---|
| 189 |  | 
|---|
| 190 |  | 
|---|