forked from Ethereal-Machines/Ray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set-initial-hostname
executable file
·44 lines (29 loc) · 1.1 KB
/
set-initial-hostname
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
import os
import sys
import argparse
parser = argparse.ArgumentParser(prog="set-initial-hostname")
parser.add_argument(
"-c",
"--config",
action="store",
dest="config",
help="Specify the astrobox config file.")
args = parser.parse_args()
basedir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(basedir, "src"))
sys.path.insert(1, os.path.join(basedir, "src", "ext"))
from octoprint.settings import settings
_settings = settings(init=True, basedir=None, configfile=args.config)
defaultHostnameFile = "%s/default-hostname" % os.path.dirname(
_settings._configfile)
if not os.path.exists(defaultHostnameFile):
import random
from astroprint.variant import variantManager
from astroprint.network.debian import DebianNetworkManager
rmdId = random.randint(0, 9999)
defaultHostname = '%s-%04d' % (variantManager().data['networkName'], rmdId)
with open(defaultHostnameFile, 'w') as f:
f.write(defaultHostname)
DebianNetworkManager().setHostname(defaultHostname)
print "hostname set to %s" % defaultHostname