source: trunk/debian/rootfs/debian.mk @ 873

Last change on this file since 873 was 873, checked in by amain, 3 years ago

rootfs: fix debian packages apt source url

File size: 10.3 KB
Line 
1# DebWrt - Debian on Embedded devices
2#
3# Copyright (C) 2010,2016 Johan van Zoomeren <amain@debwrt.net>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18QEMU_BIN=/usr/bin/qemu-$(ROOTFS_DEBIAN_ARCH)
19QEMU_BIN_STATIC=$(QEMU_BIN)-static
20QEMU_INTERPRETER=$(shell cat /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH) 2>/dev/null | grep interpreter | awk '{print $$2}')
21
22ROOTFS_DEBIAN_INCLUDE_PACKAGES:=$(call qstrip,$(CONFIG_ROOTFS_DEBIAN_INCLUDE_PACKAGES))
23ROOTFS_DEBIAN_QEMU_2ND_STAGE:=$(call qstrip, $(CONFIG_ROOTFS_DEBIAN_QEMU_2ND_STAGE))
24DEBWRT_EXTRA_ROOTFS_FILES_DIR:=$(TOPDIR)/debian/rootfs/files
25MODULES_VERSION=$(shell echo `basename $(DEBWRT_MODULES_ARCHIVE) 2>/dev/null` | awk -F '-' '{print $$6}')
26ROOTFS_DEBIAN_INCLUDE_PACKAGES_DEBIAN_VERSION:=$(wildcard debian/rootfs/include_packages.list.$(ROOTFS_DEBIAN_RELEASE))
27
28include  $(TOPDIR)/debian/rootfs/debootstrap.mk
29include  $(TOPDIR)/debian/rootfs/packages.mk
30
31define qemu-prepare
32        @if [ ! -x $(QEMU_BIN_STATIC) ]; then echo "E: can't find qemu ($(QEMU_BIN_STATIC))"; fi
33        @if [ ! -e /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH) ]; then echo "E: can't find binfmt_misc qemu-$(ROOTFS_DEBIAN_ARCH) ( /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH)).\nE: install qemu-user-static, or\nE: disable second stage with qemu with menuconfig (ROOTFS_DEBIAN_QEMU_2ND_STAGE)."; fi
34        @if [ ! -x $(QEMU_BIN_STATIC) -o ! -e /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH) ]; then echo "E: abort - qemu not available in chroot"; exit 1; fi
35        @if [ ! -e $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER) ]; then sudo cp $(QEMU_BIN_STATIC) $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER); fi
36        @if ! sudo chroot $(ROOTFS_BUILD_DIR) /bin/ls >/dev/null; then echo "E: qemu can't execute binaries for $(ROOTFS_DEBIAN_ARCH)"; echo "E: abort"; exit 1; fi
37        @if ! (mount | grep -q $(ROOTFS_BUILD_DIR)/proc); then sudo chroot $(ROOTFS_BUILD_DIR) mount -t proc none /proc; fi
38        @if ! (mount | grep -q $(ROOTFS_BUILD_DIR)/sys ); then sudo chroot $(ROOTFS_BUILD_DIR) mount -t sysfs none /sys; fi
39endef
40
41define qemu-cleanup
42        @if (mount | grep -q $(ROOTFS_BUILD_DIR)/proc); then sudo umount $(ROOTFS_BUILD_DIR)/proc; fi
43        @if (mount | grep -q $(ROOTFS_BUILD_DIR)/sys ); then sudo umount $(ROOTFS_BUILD_DIR)/sys ; fi
44        @sudo rm -f $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
45endef
46
47define rootfs-package-list
48$(shell echo "$(DEBWRT_ROOTFS_PKGLST_DEPS)" \
49         | tr ' ' '\n' \
50         >$(TMP_DIR)/include_packages_list.debwrt-package-deps; \
51        grep -hv -e '^#' -v -e '^$$'  \
52                 $(ROOTFS_DEBIAN_INCLUDE_PACKAGES) \
53                 $(ROOTFS_DEBIAN_INCLUDE_PACKAGES_DEBIAN_VERSION) \
54                 $(TMP_DIR)/include_packages_list.debwrt-package-deps \
55          | sort -u | tr '\n' ',' | sed 's/,$$//')
56endef
57
58chr:
59        $(call qemu-prepare)
60        @sudo bash -c "echo "debwrt-$(ROOTFS_DEBIAN_ARCH)" > $(ROOTFS_BUILD_DIR)/etc/debian_chroot"
61        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt
62        @sudo bash -c "cat /etc/resolv.conf | grep nameserver >$(ROOTFS_BUILD_DIR)/etc/resolv.conf"
63        @sudo chroot $(ROOTFS_BUILD_DIR)
64        @sudo rm -f $(ROOTFS_BUILD_DIR)/etc/debian_chroot
65        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt $(ROOTFS_BUILD_DIR)/etc/resolv.conf
66        $(call qemu-cleanup)
67
68debian/rootfs: | debian/rootfs/prepare-debwrt-packages \
69                 debian/rootfs/bootstrap               \
70                 debian/rootfs/copy-debwrt-packages    \
71                 debian/rootfs/unpack                  \
72                 debian/rootfs/files-install           \
73                 debian/rootfs/post-setup              \
74                 debian/rootfs/post-setup-emulated     \
75                 debian/rootfs/install-debwrt-packages \
76                 debian/rootfs/verify                  \
77                 debian/rootfs/save
78        @echo "I: Root filesystem $(ROOTFS_DEBIAN_RELEASE) $(ROOTFS_DEBIAN_ARCH) prepared in $(ROOTFS_BUILD_DIR) and archived in $(ROOTFS_INSTALL_DIR)/$(ROOTFS_TAR_BZ2)."
79        @echo "I:"
80        @echo "I: Install the image to USB-Disk/USB-Stick/SD-Card (make sure it is already mounted at /media/DEBWRT_ROOTFS)"
81        @echo "I: - make debian/rootfs/install"
82        @echo "I:"
83        @echo "I: Enter the change root(with qemu) and perform additional post install steps:"
84        @echo "I: - make chr"
85        @echo "I: - apt-get update # example statement ;-) - networking works!"
86        touch $@
87
88debian/rootfs/install: debian/rootfs
89        if [ -d /media/DEBWRT_ROOT ]; then \
90                sudo rm -rf /media/DEBWRT_ROOT/*; \
91                sudo bash -c "tar cf - -C $(ROOTFS_BUILD_DIR) . | tar xf - -C /media/DEBWRT_ROOT"; \
92        fi
93        #touch $@
94
95debian/rootfs/verify:
96        @if [ -f $(ROOTFS_BUILD_DIR)/debootstrap/debootstrap.log ]; then \
97                echo "E: Second stage install was not completed successfully" ;\
98                echo "E: Please check debootstrap.log to inspect the situation:" ;\
99                echo "E:    make chr" ;\
100                echo "E:    vi /debootstrap/debootstrap.log" ;\
101                exit 1 ;\
102        fi
103        touch $@
104
105debian/rootfs/save:
106        mkdir -p $(ROOTFS_INSTALL_DIR)
107        sudo bash -c "tar cjf $(ROOTFS_INSTALL_DIR)/$(ROOTFS_TAR_BZ2) -C $(ROOTFS_BUILD_DIR) ."
108        sudo chown $(USER) $(ROOTFS_INSTALL_DIR)/$(ROOTFS_TAR_BZ2)
109        sudo chmod 644 $(ROOTFS_INSTALL_DIR)/$(ROOTFS_TAR_BZ2)
110
111debian/rootfs/files-install: debian/rootfs/bootstrap
112        if [ ! -f $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian -a -e $(ROOTFS_BUILD_DIR)/etc/init.d/rcS ]; then \
113                sudo mv -v $(ROOTFS_BUILD_DIR)/etc/init.d/rcS $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian; \
114        fi
115        if [ ! -p $(ROOTFS_BUILD_DIR)/dev/initctl ]; then  \
116                sudo mkdir -p $(ROOTFS_BUILD_DIR)/dev;         \
117                sudo mkfifo   $(ROOTFS_BUILD_DIR)/dev/initctl; \
118        fi
119        @echo "Installing generic files (all):"
120        sudo bash -c "tar cf - --exclude=".svn" -C $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/all . | tar -xovf - -C $(ROOTFS_BUILD_DIR)"
121        @echo "Installing all targets files:"
122        sudo mkdir -p $(ROOTFS_BUILD_DIR)/target
123        sudo bash -c "tar cf - --exclude=".svn" --exclude ./all -C $(DEBWRT_EXTRA_ROOTFS_FILES_DIR) . | tar -xovf - -C $(ROOTFS_BUILD_DIR)/target"
124        sudo chmod 600 $(ROOTFS_BUILD_DIR)/etc/ssh/ssh_host_rsa_key
125        sudo chmod 600 $(ROOTFS_BUILD_DIR)/etc/ssh/ssh_host_dsa_key
126        sudo cat $(ROOTFS_BUILD_DIR)/etc/securetty \
127                $(TOPDIR)/debian/rootfs/securetty.tail \
128                >> $(TOPDIR)/securetty.temp
129        sudo mv $(TOPDIR)/securetty.temp $(ROOTFS_BUILD_DIR)/etc/securetty
130        touch $@
131
132# Fow now: Include debwrt-packages dependencies staticly. This
133#          list(DEBWRT_ROOTFS_PKGLST_DEPS) is managed in debian/package/debian.mk.
134debian/rootfs/bootstrap: | debian/rootfs/debootstrap-install \
135                           debian/rootfs/clean-rootfs-dir \
136                           debian/rootfs/prepare-debwrt-packages
137        mkdir -p $(ROOTFS_BUILD_DIR)
138ifeq ($(ROOTFS_DEBIAN_QEMU_2ND_STAGE),y)
139        # Debootstrap and automated qemu based 2nd stage install
140        sudo qemu-debootstrap --arch=$(ROOTFS_DEBIAN_ARCH)\
141                              --include=$(call rootfs-package-list),$(call debwrt-package-deps-list) \
142                              $(ROOTFS_DEBIAN_RELEASE) \
143                              $(ROOTFS_BUILD_DIR) \
144                              $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)
145else
146        # Use debootstrap to ony extract selected packages
147        sudo debootstrap --arch=$(ROOTFS_DEBIAN_ARCH)\
148                         --foreign \
149                         --include=$(call rootfs-package-list) \
150                         $(ROOTFS_DEBIAN_RELEASE) \
151                         $(ROOTFS_BUILD_DIR) \
152                         $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)
153endif
154        # complete ROOTFS/dev/ with additional device files
155        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v consoleonly"
156        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v sda"
157        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v ttyS0"
158        touch $@
159
160ifeq ($(ROOTFS_DEBIAN_QEMU_2ND_STAGE),y)
161debian/rootfs/unpack: debian/rootfs/bootstrap
162        # no action
163else
164debian/rootfs/unpack: debian/rootfs/bootstrap
165        # extract packages, to allow second stage to take place on physical
166        # machine, while being able to boot the machine with most important
167        # binaries in place.
168        find $(ROOTFS_BUILD_DIR) -name "*.deb" | while read deb; do \
169                n=`basename $$deb`; \
170                echo -n "I: Extracting $${n}..."; \
171                sudo bash -c "dpkg --extract "$$deb" $(ROOTFS_BUILD_DIR)" ; \
172                echo "done"; \
173        done
174        touch $@
175endif
176
177debian/rootfs/clean-rootfs-dir:
178        mkdir -p $(BUILD_DIR_BASE)
179        sudo rm -rf $(ROOTFS_BUILD_DIR)
180        touch $@
181
182debian/rootfs/post-setup: debian/rootfs/bootstrap
183        sudo mkdir -p $(ROOTFS_BUILD_DIR)/etc/apt
184        sudo bash -c "echo -e \"# For low memory (<64M) system, which have a hard time running apt-get update,\n# DebWrt provides a Debian mirror containing a, still very large, subset (~13.000) of all\n# Debian packages.\ndeb http://debian.debwrt.net/ $(ROOTFS_DEBIAN_RELEASE) main\" > $(ROOTFS_BUILD_DIR)/etc/apt/sources.list"
185        sudo bash -c "echo \"deb http://packages.debwrt.net/debwrt $(ROOTFS_DEBIAN_RELEASE)-debwrt-stable main\" >> $(ROOTFS_BUILD_DIR)/etc/apt/sources.list"
186        sudo bash -c "echo \"$(DEBWRTVERSION)\" >$(ROOTFS_BUILD_DIR)/etc/debwrt_version"
187        sudo bash -c "echo \"$(ROOTFS_DEBIAN_RELEASE)\" >$(ROOTFS_BUILD_DIR)/etc/debwrt_debian_release"
188        touch $@
189
190ifeq ($(ROOTFS_DEBIAN_QEMU_2ND_STAGE),y)
191debian/rootfs/post-setup-emulated: debian/rootfs/bootstrap
192        $(call qemu-prepare)
193        sudo chroot $(ROOTFS_BUILD_DIR) /usr/sbin/PostInstall && sudo rm -f $(ROOTFS_BUILD_DIR)/usr/sbin/PostInstall
194        wget -qO - "http://buildd.debwrt.net:8066/mini_buildd/api?command=getkey&output=plain" | sudo chroot $(ROOTFS_BUILD_DIR) apt-key add -
195        wget -qO - "http://debian.debwrt.net/apt/conf/debwrt-debian-mirror-public-gpg.key" | sudo chroot $(ROOTFS_BUILD_DIR) apt-key add -
196        $(call qemu-cleanup)
197else
198debian/rootfs/post-setup-emulated: debian/rootfs/bootstrap
199        @echo "I: Qemu 2nd stage install disabled. Second stage needs now to be performend on the target device itself."
200        @echo "I: Qemu 2nd stage install can be enabled using menuconfig (ROOTFS_DEBIAN_QEMU_2ND_STAGE)."
201endif
202        touch $@
203
204debian/rootfs/clean:
205        sudo rm -rf $(ROOTFS_BUILD_DIR)
206        rm -f debian/rootfs/bootstrap
207        rm -f debian/rootfs/install
208        rm -f debian/rootfs/files-install
209
Note: See TracBrowser for help on using the repository browser.