74904968cd9609d9fab7b8e42bf89c6b911fc491
[plcrt.git] / cron.d / syncadmins.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5
6 #NOTE: I'm so sorry for this.
7 try:
8         # if this file deos not exist, then we will jump to the exception and use
9         # the local PLCSH without passing any additional arguments.
10         os.stat("/etc/planetlab/master.py")
11         sys.path.append("/etc/planetlab")
12         import master
13
14         # Use the values given to us in the /etc/planetlab/master.py file taken from
15         # the master PLC and use them to construct the proper arguments to plcsh so
16         # that we can get a user list from managing, CoPLC
17         user=master.PLC_ROOT_USER
18         passwd=master.PLC_ROOT_PASSWORD
19         url = "https://" + master.PLC_API_HOST + ":" \
20                         + master.PLC_API_PORT + master.PLC_API_PATH
21
22         plcsh_args = "--user=%s --password=%s --url=%s %s" % (user, passwd, url, " ".join(sys.argv[1:]))
23 except:
24         plcsh_args = "%s" % " ".join(sys.argv[1:])
25
26 dir = "/usr/share/plcrt"
27 os.system("chmod 755 %s/getpersons.py" % dir)
28 os.system("%s/getpersons.py %s -- admin | %s/adduserstort.pl priv -" % ( dir, plcsh_args, dir) )