Rewriting source_hooks in python.
This commit is contained in:
parent
d042538e28
commit
db331a3c5a
|
@ -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>
|
## Copyright (C) 2006-2013 Daniel Baumann <mail@daniel-baumann.ch>
|
||||||
##
|
##
|
||||||
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
||||||
|
@ -8,71 +8,101 @@
|
||||||
## under certain conditions; see COPYING for details.
|
## 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
|
# TODO:
|
||||||
DESCRIPTION="$(Echo 'execute hooks in source')"
|
# * logfile output
|
||||||
HELP=""
|
# * lockfile handling
|
||||||
USAGE="${PROGRAM} [--force]"
|
# * 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
|
arguments.add_argument('--verbose', help='set verbose option', action='store_true')
|
||||||
Read_conffiles config/all config/common config/bootstrap config/chroot config/source config/source
|
|
||||||
Set_defaults
|
|
||||||
|
|
||||||
Echo_message "Begin executing hooks..."
|
args = arguments.parse_args()
|
||||||
|
|
||||||
# Requiring stage file
|
# --verbose
|
||||||
Require_stagefile .build/config .build/bootstrap
|
verbose = args.verbose
|
||||||
|
|
||||||
# Checking stage file
|
## Executing hooks
|
||||||
Check_stagefile .build/source_hooks
|
|
||||||
|
|
||||||
# Checking lock file
|
# stagefile
|
||||||
Check_lockfile .lock
|
if os.path.isfile('.build/source_hooks'):
|
||||||
|
if verbose:
|
||||||
|
print('I: source_hooks already done - nothing to do')
|
||||||
|
|
||||||
# Creating lock file
|
sys.exit(0)
|
||||||
Create_lockfile .lock
|
|
||||||
|
|
||||||
## Processing distribution hooks
|
# dependencies
|
||||||
|
if not os.path.isfile('.build/source'):
|
||||||
|
print('E: source stage missing - aborting', file=sys.stderr)
|
||||||
|
|
||||||
# Running hooks
|
if verbose:
|
||||||
for _HOOK in ${LB_BINARY_HOOKS}
|
print('I: use \'lb source\' to source system')
|
||||||
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
|
|
||||||
|
|
||||||
## Processing local hooks
|
sys.exit(1)
|
||||||
|
|
||||||
if Find_files config/hooks/*.source
|
# hooks
|
||||||
then
|
if not glob.glob('config/hooks/*.hook') and not glob.glob('config/hooks/*.hook.source'):
|
||||||
for HOOK in config/hooks/*.source
|
if verbose:
|
||||||
do
|
print ('I: no source hooks found at config/hooks/*.hook{,.source} - nothing to do')
|
||||||
# Making hook executable
|
|
||||||
if [ ! -x "${HOOK}" ]
|
|
||||||
then
|
|
||||||
chmod +x "${HOOK}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Executing hook
|
sys.exit(0)
|
||||||
./"${HOOK}" || { Echo_error "${HOOK} failed (exit non-zero). You should check for errors."; exit 1 ;}
|
|
||||||
done
|
|
||||||
|
|
||||||
# Creating stage file
|
# bind mount configuration directory
|
||||||
Create_stagefile .build/source_hooks
|
if verbose:
|
||||||
fi
|
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()
|
||||||
|
|
Loading…
Reference in New Issue