source: live-build/trunk/fuentes/scripts/build/lb_source_hdd @ 900

Last change on this file since 900 was 900, checked in by kbut, 4 years ago

add original source

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#!/bin/sh
2
3## live-build(7) - System Build Scripts
4## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
5##
6## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7## This is free software, and you are welcome to redistribute it
8## under certain conditions; see COPYING for details.
9
10
11set -e
12
13# Including common functions
14( . "${LIVE_BUILD}/scripts/build.sh" > /dev/null 2>&1 || true ) || . /usr/lib/live/build.sh
15
16# Setting static variables
17DESCRIPTION="$(Echo 'build source image')"
18HELP=""
19USAGE="${PROGRAM} [--force]"
20
21Arguments "${@}"
22
23# Reading configuration files
24Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
25Set_defaults
26
27if [ "${LB_SOURCE}" != "true" ]
28then
29        exit 0
30fi
31
32if ! In_list hdd "${LB_SOURCE_IMAGES}"
33then
34        exit 0
35fi
36
37Echo_message "Begin building source hdd image..."
38
39# Requiring stage file
40Require_stagefile .build/config .build/source_debian
41
42# Checking stage file
43Check_stagefile .build/source_hdd
44
45# Checking lock file
46Check_lockfile .lock
47
48# Creating lock file
49Create_lockfile .lock
50
51# Checking depends
52Check_package chroot/sbin/mkdosfs dosfstools
53Check_package chroot/sbin/parted parted
54
55# Installing depends
56Install_package
57
58# Remove old source
59if [ -f source.img ]
60then
61        rm -f source.img
62fi
63
64# Everything which comes here needs to be cleaned up,
65DU_DIM="$(du -ms source | cut -f1)"
66REAL_DIM="$(Calculate_partition_size ${DU_DIM} ${LB_BINARY_FILESYSTEM})"
67dd if=/dev/zero of=source.img bs=1024k count=0 seek=${REAL_DIM}
68FREELO="$(${LB_LOSETUP} -f)"
69if [ ! -b chroot/${FREELO} ]
70then
71        MAKEDEV="true"
72
73        mv chroot/dev chroot/dev.tmp
74        find /dev | cpio -dmpu chroot
75fi
76
77case "${LB_BINARY_FILESYSTEM}" in
78        ext2|ext3|ext4)
79                PARTITION_TYPE="ext2"
80                ;;
81
82        fat16|fat32)
83                PARTITION_TYPE="${LB_BINARY_FILESYSTEM}"
84                ;;
85
86        ntfs)
87                PARTITION_TYPE="NTFS"
88                ;;
89
90        *)
91                Echo_error "Unsupported binary filesystem %s" "${LB_BINARY_FILESYSTEM}"
92                exit 1
93                ;;
94esac
95
96Echo_warning "!!! The following error/warning messages can be ignored !!!"
97Losetup $FREELO source.img 0
98Chroot chroot "parted -s ${FREELO} mklabel msdos" || true
99Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
100Lodetach ${FREELO}
101
102Losetup $FREELO source.img 1
103
104case "${LB_BINARY_FILESYSTEM}" in
105        ext2|ext3|ext4)
106                MKFS="${LB_BINARY_FILESYSTEM}"
107                MKFS_OPTIONS="-L ${LB_HDD_LABEL} -m 0"
108                ;;
109
110        fat16)
111                MKFS="vfat"
112                MKFS_OPTIONS="-F 16 -n ${LB_HDD_LABEL}"
113                ;;
114
115        fat32)
116                MKFS="vfat"
117                MKFS_OPTIONS="-F 32 -n ${LB_HDD_LABEL}"
118                ;;
119
120        ntfs)
121                MKFS="ntfs"
122                MKFS_OPTIONS="-L ${LB_HDD_LABEL}"
123                ;;
124esac
125
126Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
127
128mkdir -p source.tmp
129${LB_ROOT_COMMAND} mount ${FREELO} source.tmp
130cp -r source/* source.tmp
131${LB_ROOT_COMMAND} umount source.tmp
132rmdir source.tmp
133Lodetach ${FREELO}
134Echo_warning "!!! The above error/warning messages can be ignored !!!"
135
136FREELO="$(${LB_LOSETUP} -f)"
137Losetup "$FREELO" source.img 0
138Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
139Lodetach ${FREELO}
140
141if [ -n "${MAKEDEV}" ]
142then
143        rm -rf chroot/dev
144        mv chroot/dev.tmp chroot/dev
145fi
146
147# Removing depends
148Remove_package
149
150# Creating stage file
151Create_stagefile .build/source_hdd
Note: See TracBrowser for help on using the repository browser.