summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2013-11-04 06:43:40 +0100
committerDaniel Baumann <mail@daniel-baumann.ch>2013-11-04 06:43:40 +0100
commitdb331a3c5a287ed9a0a07c1156f3ccc03cf93f6b (patch)
treea42f817a73c28435eab6d8cf6354de0ba644d151 /scripts
parentd042538e28f5e00ee4ed544c4763ebc46fed4983 (diff)
downloadvyos-live-build-db331a3c5a287ed9a0a07c1156f3ccc03cf93f6b.tar.gz
vyos-live-build-db331a3c5a287ed9a0a07c1156f3ccc03cf93f6b.zip
Rewriting source_hooks in python.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build/source_hooks140
1 files changed, 85 insertions, 55 deletions
diff --git a/scripts/build/source_hooks b/scripts/build/source_hooks
index 3f3ef1939..d414c424e 100755
--- a/scripts/build/source_hooks
+++ b/scripts/build/source_hooks
@@ -1,6 +1,6 @@
-#!/bin/sh
+#!/usr/bin/python3
-## live-build(7) - System Build Scripts
+## 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.
@@ -8,71 +8,101 @@
## under certain conditions; see COPYING for details.
-set -e
+import argparse
+import configparser
+import glob
+import os
+import shutil
+import subprocess
+import sys
-# Including common functions
-[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
-# Setting static variables
-DESCRIPTION="$(Echo 'execute hooks in source')"
-HELP=""
-USAGE="${PROGRAM} [--force]"
+# TODO:
+# * logfile output
+# * lockfile handling
+# * use gettext for i18n
-Arguments "${@}"
+def main():
+ ## Parsing Arguments
+ arguments = argparse.ArgumentParser(
+ prog = 'lb source_hooks',
+ usage = '%(prog)s [arguments]',
+ description = '''live-build contains the components to build a live system from a configuration directory.
+ The source_hooks command executes hooks after the source stage.''',
+ epilog = 'See \'man lb_source_hooks\' for more information.',
+ version = 'live-build 4',
+ formatter_class = argparse.ArgumentDefaultsHelpFormatter
+ )
-# Reading configuration files
-Read_conffiles config/all config/common config/bootstrap config/chroot config/source config/source
-Set_defaults
+ arguments.add_argument('--verbose', help='set verbose option', action='store_true')
-Echo_message "Begin executing hooks..."
+ args = arguments.parse_args()
-# Requiring stage file
-Require_stagefile .build/config .build/bootstrap
+ # --verbose
+ verbose = args.verbose
-# Checking stage file
-Check_stagefile .build/source_hooks
+ ## Executing hooks
-# Checking lock file
-Check_lockfile .lock
+ # stagefile
+ if os.path.isfile('.build/source_hooks'):
+ if verbose:
+ print('I: source_hooks already done - nothing to do')
-# Creating lock file
-Create_lockfile .lock
+ sys.exit(0)
-## Processing distribution hooks
+ # dependencies
+ if not os.path.isfile('.build/source'):
+ print('E: source stage missing - aborting', file=sys.stderr)
-# Running hooks
-for _HOOK in ${LB_BINARY_HOOKS}
-do
- for LOCATION in "${LIVE_BUILD}/hooks" /usr/share/live/build/hooks
- do
- for FILE in "${LOCATION}"/????-"${_HOOK}".source
- do
- if [ -e "${FILE}" ]
- then
- cd source
- "${FILE}" || { Echo_error "${_HOOK} failed (exit non-zero). You should check for errors."; exit 1 ;}
- cd "${OLDPWD}"
- fi
- done
- done
-done
+ if verbose:
+ print('I: use \'lb source\' to source system')
-## Processing local hooks
+ sys.exit(1)
-if Find_files config/hooks/*.source
-then
- for HOOK in config/hooks/*.source
- do
- # Making hook executable
- if [ ! -x "${HOOK}" ]
- then
- chmod +x "${HOOK}"
- fi
+ # hooks
+ if not glob.glob('config/hooks/*.hook') and not glob.glob('config/hooks/*.hook.source'):
+ if verbose:
+ print ('I: no source hooks found at config/hooks/*.hook{,.source} - nothing to do')
- # Executing hook
- ./"${HOOK}" || { Echo_error "${HOOK} failed (exit non-zero). You should check for errors."; exit 1 ;}
- done
+ sys.exit(0)
- # Creating stage file
- Create_stagefile .build/source_hooks
-fi
+ # bind mount configuration directory
+ if verbose:
+ print('I: Mounting config to source/live-build/config')
+
+ os.makedirs('source/live-build/config', exist_ok=True)
+
+ mount = subprocess.call('mount -o bind config source/live-build/config', shell=True)
+ remount = subprocess.call('mount -o remount,ro,bind source/live-build/config', shell=True)
+
+ # process hooks
+ os.makedirs('source/live-build', exist_ok=True)
+
+ hooks = glob.glob('config/hooks/*.hook') + glob.glob('config/hooks/*.hook.source')
+
+ for hook in hooks:
+ if verbose:
+ print('I: Copying config/hooks/*.hook.source to source/live-build')
+
+ os.link(hook, os.path.join('source/live-build/' + os.path.basename(hook)), follow_symlinks=True)
+
+ if verbose:
+ print('I: Executing \' ' + hook + '\'')
+
+ os.chmod(hook, 0o755)
+ exec_hook = subprocess.call('cd source && live-build/' + os.path.basename(hook), shell=True)
+ os.remove('source/live-build/' + os.path.basename(hook))
+
+ # unmount coniguration directory
+ umount = subprocess.call('umount source/live-build/config', shell=True)
+
+ os.rmdir('source/live-build/config')
+ os.rmdir('source/live-build')
+
+ ## stagefile
+ os.makedirs('.build', exist_ok=True)
+ open('.build/source_hooks', 'w').close()
+
+
+if __name__ == '__main__':
+ main()