-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Suszyński Krzysztof
committed
Aug 9, 2017
1 parent
6b55f24
commit 7aa6c19
Showing
14 changed files
with
102 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from abc import ABCMeta, abstractmethod | ||
|
||
from six import with_metaclass | ||
from typing import Sequence | ||
|
||
from puppeter.domain.model.configurer import Configurer | ||
|
||
|
||
class ScriptPostProcessor(with_metaclass(ABCMeta)): | ||
@abstractmethod | ||
def postprocess(self, commands): | ||
# type: (Sequence[str]) -> Sequence[str] | ||
pass | ||
|
||
|
||
class ScriptLibrariesConfigurer(with_metaclass(ABCMeta, Configurer)): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from puppeter import container | ||
from puppeter.domain.gateway.answers import AnswersGateway | ||
from puppeter.domain.gateway.fqdn import FqdnSetterGateway | ||
from puppeter.domain.gateway.script import ScriptPostProcessor, ScriptLibrariesConfigurer | ||
from puppeter.persistence.gateway.answers import YamlAnswersGateway | ||
from puppeter.persistence.gateway.fqdn import FqdnSetterGatewayImpl | ||
|
||
from puppeter.persistence.gateway.script import BashScriptPostProcessor, BashScriptLibrariesConfigurer | ||
|
||
container.bind(AnswersGateway, YamlAnswersGateway) | ||
container.bind(FqdnSetterGateway, FqdnSetterGatewayImpl) | ||
container.bind(ScriptPostProcessor, BashScriptPostProcessor) | ||
container.bind(ScriptLibrariesConfigurer, BashScriptLibrariesConfigurer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
set +x | ||
function reload_shell { | ||
set +e | ||
local files='~/.bash_profile ~/.bash_login ~/.profile' | ||
if [ -f /etc/profile ]; then | ||
. /etc/profile | ||
fi | ||
for file in ${files}; do | ||
if [ -f ${file} ]; then | ||
. ${file} | ||
break | ||
fi | ||
done | ||
set -e | ||
} | ||
set -x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import re | ||
|
||
from puppeter.domain.gateway.script import ScriptPostProcessor, ScriptLibrariesConfigurer | ||
from puppeter.domain.model.ordered import Order | ||
|
||
|
||
class BashScriptPostProcessor(ScriptPostProcessor): | ||
|
||
SHEBANG_REGEX = re.compile('^#!(.*)\n', re.MULTILINE) | ||
|
||
def postprocess(self, commands): | ||
ln = "\n" | ||
header = ['#!/usr/bin/env bash', 'set -ex', ''] | ||
stripped = self.__strip_shebang(ln.join(commands)).split(ln) | ||
return header + stripped | ||
|
||
@staticmethod | ||
def __strip_shebang(script): | ||
return re.sub(BashScriptPostProcessor.SHEBANG_REGEX, '', script) | ||
|
||
|
||
@Order(-1000) | ||
class BashScriptLibrariesConfigurer(ScriptLibrariesConfigurer): | ||
def produce_commands(self): | ||
return self._collector()\ | ||
.collect_from_file('Bash script libraries', 'bash-libraries.sh')\ | ||
.lines() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env bash | ||
hostname '@{hostname}' | ||
puppet resource host '@{fqdn}' ensure=present host_aliases='@{hostname}' ip=127.0.0.1 comment='FQDN' | ||
su - $(whoami) | ||
set -ex | ||
hostname '@{hostname}' | ||
reload_shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters