-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path25ec2-userdata
More file actions
executable file
·41 lines (30 loc) · 877 Bytes
/
25ec2-userdata
File metadata and controls
executable file
·41 lines (30 loc) · 877 Bytes
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
#!/usr/bin/python
# Author: Alon Swartz <alon@turnkeylinux.org>
import os
import sys
if '_TURNKEY_INIT' in os.environ:
sys.exit(0)
import tempfile
import executil
import ec2metadata
class TempFile(file):
def __init__(self, prefix='tmp', suffix=''):
fd, path = tempfile.mkstemp(suffix, prefix)
os.close(fd)
self.path = path
self.pid = os.getpid()
file.__init__(self, path, "w")
def __del__(self):
if self.pid == os.getpid():
os.remove(self.path)
def main():
userdata = ec2metadata.get('user-data')
if userdata and userdata.startswith("#!"):
fh = TempFile(prefix="ec2userdata")
fh.writelines(userdata)
fh.close()
os.chmod(fh.path, 0750)
executil.system(fh.path)
print "# executed ec2 user-data script"
if __name__ == "__main__":
main()