@@ -0,0 +1,2608 @@
+#! /usr/bin/env python%0A#%0A# Copyright (c) 2017 Jean Guyomarc'h%0A#%0A# Permission is hereby granted, free of charge, to any person obtaining a copy%0A# of this software and associated documentation files (the %22Software%22), to deal%0A# in the Software without restriction, including without limitation the rights%0A# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A# copies of the Software, and to permit persons to whom the Software is%0A# furnished to do so, subject to the following conditions:%0A#%0A# The above copyright notice and this permission notice shall be included in%0A# all copies or substantial portions of the Software.%0A#%0A# THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN%0A# THE SOFTWARE.%0A%0Aimport argparse%0Aimport subprocess%0Aimport sys%0A%0Adef getopts(argv):%0A    parser = argparse.ArgumentParser(description='Rootfs generator')%0A    parser.add_argument(%0A        '--mkfs', type=str, default='ext3',%0A        help='Type of filesystem to be generated. This option is passed to mkfs'%0A    )%0A    parser.add_argument(%0A        '--ok', action='store_true',%0A       help='Use this option to confirm the commands to be run'%0A    )%0A    parser.add_argument(%0A        'rootfs_dir', type=str,%0A        help='Path to the directory containing the rootfs'%0A    )%0A    parser.add_argument(%0A        'output', type=str,%0A        help='Path to the filesystem block to be created'%0A    )%0A    parser.add_argument(%0A        'size', type=int,%0A        help='Size (in MB) of the output filesystem'%0A    )%0A    return parser.parse_args(argv%5B1:%5D)%0A%0Adef main(argv):%0A    args = getopts(argv)%0A%0A    cmds = %5B%5D%0A    cmds.append(%22dd if=/dev/zero of=%7B%7D bs=1M count=%7B%7D iflag=fullblock%22.format(%0A        args.output, args.size%0A    ))%0A    cmds.append(%22sync%22)%0A    cmds.append(%22mkfs.%7B%7D -d %7B%7D %7B%7D%22.format(%0A        args.mkfs, args.rootfs_dir, args.output%0A    ))%0A%0A%0A    if args.ok:%0A        for cmd in cmds:%0A            print(%22Running %7B%7D%22.format(cmd))%0A            subprocess.check_call(cmd.split(' '))%0A    else:%0A        print(%22The following commands are planned to be run:%5Cn%22)%0A        for cmd in cmds:%0A            print(%22  %7B%7D%22.format(cmd))%0A        print(%22%5CnRe-run with the --ok option to run them.%22)%0A%0Aif __name__ == %22__main__%22:%0A    main(sys.argv)%0A

add helper to generate rootfs partitions