3
# Copyright (C) 2012 Canonical Ltd.
4
# Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
5
# Copyright (C) 2012 Yahoo! Inc.
7
# Author: Scott Moser <scott.moser@canonical.com>
8
# Author: Juerg Haefliger <juerg.haefliger@hp.com>
9
# Author: Joshua Harlow <harlowja@yahoo-inc.com>
11
# This program is free software: you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License version 3, as
13
# published by the Free Software Foundation.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License
21
# along with this program. If not, see <http://www.gnu.org/licenses/>.
25
from cloudinit import handlers
26
from cloudinit import log as logging
27
from cloudinit import util
29
from cloudinit.settings import (PER_ALWAYS)
31
LOG = logging.getLogger(__name__)
35
class ShellScriptPartHandler(handlers.Handler):
36
def __init__(self, paths, **_kwargs):
37
handlers.Handler.__init__(self, PER_ALWAYS)
38
self.script_dir = paths.get_ipath_cur('scripts')
39
if 'script_path' in _kwargs:
40
self.script_dir = paths.get_ipath_cur(_kwargs['script_path'])
44
handlers.type_from_starts_with(SHELL_PREFIX),
47
def handle_part(self, data, ctype, filename, payload, frequency):
48
if ctype in handlers.CONTENT_SIGNALS:
49
# TODO(harlowja): maybe delete existing things here
52
filename = util.clean_filename(filename)
53
payload = util.dos2unix(payload)
54
path = os.path.join(self.script_dir, filename)
55
util.write_file(path, payload, 0o700)