summaryrefslogtreecommitdiff
path: root/components/binary-hooks
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2013-11-04 17:09:45 +0100
committerDaniel Baumann <mail@daniel-baumann.ch>2013-11-04 17:10:22 +0100
commit9e3863aa8fc22fe0a671b5d38431b2d311fad472 (patch)
treec9f7369160f8d9c1b98f96697f6572c724e88b6e /components/binary-hooks
parentf3fe376f61663268011d4de2b5c415c1fdd3f494 (diff)
downloadvyos-live-build-9e3863aa8fc22fe0a671b5d38431b2d311fad472.tar.gz
vyos-live-build-9e3863aa8fc22fe0a671b5d38431b2d311fad472.zip
Switching to later submodule naming scheme for python stubs.
Diffstat (limited to 'components/binary-hooks')
-rwxr-xr-xcomponents/binary-hooks108
1 files changed, 108 insertions, 0 deletions
diff --git a/components/binary-hooks b/components/binary-hooks
new file mode 100755
index 000000000..8c452adf6
--- /dev/null
+++ b/components/binary-hooks
@@ -0,0 +1,108 @@
+#!/usr/bin/python3
+
+## live-build(7) - Live System Build Components
+## Copyright (C) 2006-2013 Daniel Baumann <mail@daniel-baumann.ch>
+##
+## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+
+import argparse
+import configparser
+import glob
+import os
+import shutil
+import subprocess
+import sys
+
+
+# TODO:
+# * logfile output
+# * lockfile handling
+# * use gettext for i18n
+
+def main():
+ ## Parsing Arguments
+ arguments = argparse.ArgumentParser(
+ prog = 'lb binary-hooks',
+ usage = '%(prog)s [arguments]',
+ description = '''live-build contains the components to build a live system from a configuration directory.
+ The binary-hooks command executes hooks after the binary stage.''',
+ epilog = 'See \'man lb-binary-hooks\' for more information.',
+ formatter_class = argparse.ArgumentDefaultsHelpFormatter
+ )
+
+ arguments.add_argument('--version', help='show program\'s version number and exit', action='version', version='live-build 4')
+ arguments.add_argument('--verbose', help='set verbose option', action='store_true')
+
+ args = arguments.parse_args()
+
+ # --verbose
+ verbose = args.verbose
+
+ ## Calling binary hooks
+
+ # stagefile
+ if os.path.isfile('.build/binary-hooks'):
+ if verbose:
+ print('I: binary-hooks already done - nothing to do')
+
+ sys.exit(0)
+
+ # dependencies
+ if not os.path.isfile('.build/bootstrap'):
+ print('E: bootstrap stage missing - aborting', file=sys.stderr)
+
+ if verbose:
+ print('I: use \'lb bootstrap\' to bootstrap system')
+
+ sys.exit(1)
+
+ # hooks
+ if not glob.glob('config/hooks/*.hook') and not glob.glob('config/hooks/*.hook.binary'):
+ if verbose:
+ print ('I: no binary hooks found at config/hooks/*.hook{,.binary} - nothing to do')
+
+ sys.exit(0)
+
+ # bind mount configuration directory
+ if verbose:
+ print('I: Mounting config to binary/live-build/config')
+
+ os.makedirs('binary/live-build/config', exist_ok=True)
+
+ mount = subprocess.call('mount -o bind config binary/live-build/config', shell=True)
+ remount = subprocess.call('mount -o remount,ro,bind binary/live-build/config', shell=True)
+
+ # process hooks
+ os.makedirs('binary/live-build', exist_ok=True)
+
+ hooks = glob.glob('config/hooks/*.hook') + glob.glob('config/hooks/*.hook.binary')
+
+ for hook in hooks:
+ if verbose:
+ print('I: Copying config/hooks/*.hook.binary to binary/live-build')
+
+ shutil.copy(hook, os.path.join('binary/live-build/' + os.path.basename(hook)), follow_symlinks=True)
+
+ if verbose:
+ print('I: Executing \' ' + hook + '\'')
+
+ os.chmod(hook, 0o755)
+ exec_hook = subprocess.call('cd binary && live-build/' + os.path.basename(hook), shell=True)
+ os.remove('binary/live-build/' + os.path.basename(hook))
+
+ # unmount coniguration directory
+ umount = subprocess.call('umount binary/live-build/config', shell=True)
+
+ os.rmdir('binary/live-build/config')
+ os.rmdir('binary/live-build')
+
+ ## stagefile
+ os.makedirs('.build', exist_ok=True)
+ open('.build/binary-hooks', 'w').close()
+
+
+if __name__ == '__main__':
+ main()