Commit 3ec1de18 by Oliver Pinter

share: smbfs

parent 5a5785dc
...@@ -20,6 +20,11 @@ then ...@@ -20,6 +20,11 @@ then
git clone https://github.com/HardenedBSD/freebsd-ports.git /usr/ports git clone https://github.com/HardenedBSD/freebsd-ports.git /usr/ports
fi fi
if [ ! -d /store ]
then
mkdir -p /store
fi
if [ ! -d /root/agent ] if [ ! -d /root/agent ]
then then
cd /root cd /root
......
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from os import mkdir, environ, chdir from os import mkdir, environ, chdir, chmod
import platform import platform
from shutil import copy, rmtree, move from shutil import copy, rmtree, move
import subprocess import subprocess
...@@ -13,6 +13,7 @@ working_directory = sys.path[0] ...@@ -13,6 +13,7 @@ working_directory = sys.path[0]
try: try:
# load virtio console driver, the device is /dev/ttyV0.1 # load virtio console driver, the device is /dev/ttyV0.1
subprocess.call(('/sbin/kldload', '-n', 'virtio_console')) subprocess.call(('/sbin/kldload', '-n', 'virtio_console'))
subprocess.call(('/sbin/kldload', '-n', 'smbfs'))
chdir(working_directory) chdir(working_directory)
subprocess.call(('/usr/local/bin/pip', 'install', '-r', 'requirements.txt')) subprocess.call(('/usr/local/bin/pip', 'install', '-r', 'requirements.txt'))
copy("/root/agent/misc/vm_renewal", "/usr/local/bin/") copy("/root/agent/misc/vm_renewal", "/usr/local/bin/")
...@@ -46,9 +47,15 @@ AUTHORIZED_KEYS = join(SSH_DIR, 'authorized_keys') ...@@ -46,9 +47,15 @@ AUTHORIZED_KEYS = join(SSH_DIR, 'authorized_keys')
STORE_DIR = '/store' STORE_DIR = '/store'
mount_template_linux = ( mount_template_freebsd = (
'//%(host)s/%(username)s %(dir)s cifs username=%(username)s' '//CLOUD/%(username)s %(dir)s smbfs '
',password=%(password)s,iocharset=utf8,uid=cloud 0 0\n') 'rw,-N,-ucloud,-U%(username)s 0 0\n')
NSMBRC = '/etc/nsmb.conf'
nsmbrc_template_freebsd = (
'[CLOUD:%(username)s]\n'
'addr=%(host)s\n'
'password=%(password)s\n')
class Context(BaseContext): class Context(BaseContext):
...@@ -116,11 +123,15 @@ class Context(BaseContext): ...@@ -116,11 +123,15 @@ class Context(BaseContext):
mkdir(STORE_DIR) mkdir(STORE_DIR)
# TODO # TODO
for line in fileinput.input('/etc/fstab', inplace=True): for line in fileinput.input('/etc/fstab', inplace=True):
if not (line.startswith('//') and ' cifs ' in line): if not (line.startswith('//') and ' smbfs ' in line):
print line.rstrip() print line.rstrip()
with open(NSMBRC, 'w') as f:
chmod(NSMBRC, 0600)
f.write(nsmbrc_template_freebsd % data)
with open('/etc/fstab', 'a') as f: with open('/etc/fstab', 'a') as f:
f.write(mount_template_linux % data) f.write(mount_template_freebsd % data)
subprocess.call('/sbin/mount -a', shell=True) subprocess.call('/sbin/mount -a', shell=True)
...@@ -184,7 +195,8 @@ class Context(BaseContext): ...@@ -184,7 +195,8 @@ class Context(BaseContext):
'/home/cloud/.ssh' '/home/cloud/.ssh'
'/root/.lesshst' '/root/.lesshst'
'/root/.history' '/root/.history'
'/root/.viminfo'] '/root/.viminfo'
'/etc/nsmb.conf']
+ glob('/etc/ssh/ssh_host_*')) + glob('/etc/ssh/ssh_host_*'))
for f in filelist: for f in filelist:
rmtree(f, ignore_errors=True) rmtree(f, ignore_errors=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment