#!/usr/bin/env python

# THIS FILE IS PART OF THE CYLC SUITE ENGINE.
# Copyright (C) 2008-2018 NIWA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""cylc [task] remote-init UUID RUND

(This command is for internal use.)
Install suite service files on a task remote (i.e. a [owner@]host):
* ".service/contact"
* ".service/passphrase"
* ".service/ssl.cert"

Content of items to install from a tar file read from STDIN.

Return 0 on success or if initialisation not required. Return 1 on failure.

Print SuiteSrvFilesManager.REMOTE_INIT_NOT_REQUIRED if initialisation not
required (e.g. remote has shared file system with suite host).

Print SuiteSrvFilesManager.REMOTE_INIT_DONE on success.

"""


from cylc.remote import remrun


if __name__ == '__main__' and not remrun():
    from cylc.option_parsers import CylcOptionParser as COP
    from cylc.task_remote_cmd import remote_init
    parser = COP(__doc__, argdoc=[
        ('UUID', 'UUID of current suite running process'),
        ('RUND', 'The run directory of the suite')])
    uuid_str, rund = parser.parse_args()[1]
    remote_init(uuid_str, rund)
