/* */
parse arg eMail Password

Data = ""
Error = ""
Status = ""
AccountKey = ""

select
      when eMail = "update" then
           do
             '@boinc_cmd.exe --project http://milkyway.cs.rpi.edu/milkyway update'
             exit
           end
      when eMail = "detach" then
           do
             '@boinc_cmd.exe --project http://milkyway.cs.rpi.edu/milkyway detach'
             exit
           end
      when eMail = "suspend" then
           do
             '@boinc_cmd.exe --project http://milkyway.cs.rpi.edu/milkyway suspend'
             exit
           end
      when eMail = "resume" then
           do
             '@boinc_cmd.exe --project http://milkyway.cs.rpi.edu/milkyway resume'
             exit
           end
      otherwise
               do
if eMail = "" then
   do
     say "Project http://milkyway.cs.rpi.edu/milkyway:"
     say ""
     say "Options:"
     say "milkyway.cmd <Username> <Password> for project attach"
     say "milkyway.cmd update for project update"
     say "milkyway.cmd detach for project detach"
     say "milkyway.cmd suspend for project suspending"
     say "milkyway.cmd resume for project resuming"
     exit
   end
if Password = "" then
   do
     say "Project http://milkyway.cs.rpi.edu/milkyway:"
     say ""
     say "Options:"
     say "milkyway.cmd <Username> <Password> for project attach"
     say "milkyway.cmd update for project update"
     say "milkyway.cmd detach for project detach"
     say "milkyway.cmd suspend for project suspending"
     say "milkyway.cmd resume for project resuming"
     exit
   end
               end
end

'@boinc_cmd.exe --lookup_account http://milkyway.cs.rpi.edu/milkyway ' || eMail || ' ' || Password || ' | RXQUEUE'
do queued()
    Data = linein("QUEUE:")
    Status = substr(Data,1,12)
    if Status = "account key:" then
       do
         AccountKey = substr(Data,13)
         '@boinc_cmd.exe --project_attach http://milkyway.cs.rpi.edu/milkyway ' ||  AccountKey
       end
       else
           Error = Data
end

if Status = "account key:" then
   do
     say "Project http://milkyway.cs.rpi.edu/milkyway:"
     say ""
     say "successfull attach to project http://milkyway.cs.rpi.edu/milkyway!"
     say "account key is: " || AccountKey
     say "now copying OS/2 application into project directory..."
     '@copy milkyway_0.18.i386-pc-os2-emx.exe projects\milkyway.cs.rpi.edu_milkyway'
     '@copy ..\milkyway_app_info.xml projects\milkyway.cs.rpi.edu_milkyway\app_info.xml'
     say "Remember to change all occurence of <min_rpc_time> to 0.00 in client_state.xml"
     say "for immediate download of WorkUnit."
  end
  else
      do
        say "Project http://milkyway.cs.rpi.edu/milkyway:"
        say ""
        say "Unable to attach..."
        say "error: " || Error
        exit
      end
