Browse Source

Add two files

bh1rio 1 year ago
parent
commit
17b9bea262
No account linked to committer's email
2 changed files with 218 additions and 0 deletions
  1. 92
    0
      mkimage-arch-pacman.conf
  2. 126
    0
      mkimage-arch.sh

+ 92
- 0
mkimage-arch-pacman.conf View File

@@ -0,0 +1,92 @@
1
+#
2
+# /etc/pacman.conf
3
+#
4
+# See the pacman.conf(5) manpage for option and repository directives
5
+
6
+#
7
+# GENERAL OPTIONS
8
+#
9
+[options]
10
+# The following paths are commented out with their default values listed.
11
+# If you wish to use different paths, uncomment and update the paths.
12
+#RootDir     = /
13
+#DBPath      = /var/lib/pacman/
14
+#CacheDir    = /var/cache/pacman/pkg/
15
+#LogFile     = /var/log/pacman.log
16
+#GPGDir      = /etc/pacman.d/gnupg/
17
+HoldPkg     = pacman glibc
18
+#XferCommand = /usr/bin/curl -C - -f %u > %o
19
+#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
20
+#CleanMethod = KeepInstalled
21
+#UseDelta    = 0.7
22
+Architecture = auto
23
+
24
+# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup
25
+#IgnorePkg   =
26
+#IgnoreGroup =
27
+
28
+#NoUpgrade   =
29
+#NoExtract   =
30
+
31
+# Misc options
32
+#UseSyslog
33
+#Color
34
+#TotalDownload
35
+# We cannot check disk space from within a chroot environment
36
+#CheckSpace
37
+#VerbosePkgLists
38
+
39
+# By default, pacman accepts packages signed by keys that its local keyring
40
+# trusts (see pacman-key and its man page), as well as unsigned packages.
41
+SigLevel    = Required DatabaseOptional
42
+LocalFileSigLevel = Optional
43
+#RemoteFileSigLevel = Required
44
+
45
+# NOTE: You must run `pacman-key --init` before first using pacman; the local
46
+# keyring can then be populated with the keys of all official Arch Linux
47
+# packagers with `pacman-key --populate archlinux`.
48
+
49
+#
50
+# REPOSITORIES
51
+#   - can be defined here or included from another file
52
+#   - pacman will search repositories in the order defined here
53
+#   - local/custom mirrors can be added here or in separate files
54
+#   - repositories listed first will take precedence when packages
55
+#     have identical names, regardless of version number
56
+#   - URLs will have $repo replaced by the name of the current repo
57
+#   - URLs will have $arch replaced by the name of the architecture
58
+#
59
+# Repository entries are of the format:
60
+#       [repo-name]
61
+#       Server = ServerName
62
+#       Include = IncludePath
63
+#
64
+# The header [repo-name] is crucial - it must be present and
65
+# uncommented to enable the repo.
66
+#
67
+
68
+# The testing repositories are disabled by default. To enable, uncomment the
69
+# repo name header and Include lines. You can add preferred servers immediately
70
+# after the header, and they will be used before the default mirrors.
71
+
72
+#[testing]
73
+#Include = /etc/pacman.d/mirrorlist
74
+
75
+[core]
76
+Include = /etc/pacman.d/mirrorlist
77
+
78
+[extra]
79
+Include = /etc/pacman.d/mirrorlist
80
+
81
+#[community-testing]
82
+#Include = /etc/pacman.d/mirrorlist
83
+
84
+[community]
85
+Include = /etc/pacman.d/mirrorlist
86
+
87
+# An example of a custom package repository.  See the pacman manpage for
88
+# tips on creating your own repositories.
89
+#[custom]
90
+#SigLevel = Optional TrustAll
91
+#Server = file:///home/custompkgs
92
+

+ 126
- 0
mkimage-arch.sh View File

@@ -0,0 +1,126 @@
1
+#!/usr/bin/env bash
2
+# Generate a minimal filesystem for archlinux and load it into the local
3
+# docker as "archlinux"
4
+# requires root
5
+set -e
6
+
7
+hash pacstrap &>/dev/null || {
8
+	echo "Could not find pacstrap. Run pacman -S arch-install-scripts"
9
+	exit 1
10
+}
11
+
12
+hash expect &>/dev/null || {
13
+	echo "Could not find expect. Run pacman -S expect"
14
+	exit 1
15
+}
16
+
17
+
18
+export LANG="C.UTF-8"
19
+
20
+ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-archlinux-XXXXXXXXXX)
21
+chmod 755 $ROOTFS
22
+
23
+# packages to ignore for space savings
24
+PKGIGNORE=(
25
+    cryptsetup
26
+    device-mapper
27
+    dhcpcd
28
+    iproute2
29
+    jfsutils
30
+    linux
31
+    lvm2
32
+    man-db
33
+    man-pages
34
+    mdadm
35
+    nano
36
+    netctl
37
+    openresolv
38
+    pciutils
39
+    pcmciautils
40
+    reiserfsprogs
41
+    s-nail
42
+    systemd-sysvcompat
43
+    usbutils
44
+    vi
45
+    xfsprogs
46
+)
47
+IFS=','
48
+PKGIGNORE="${PKGIGNORE[*]}"
49
+unset IFS
50
+
51
+arch="$(uname -m)"
52
+case "$arch" in
53
+	armv*)
54
+		if pacman -Q archlinuxarm-keyring >/dev/null 2>&1; then
55
+			pacman-key --init
56
+			pacman-key --populate archlinuxarm
57
+		else
58
+			echo "Could not find archlinuxarm-keyring. Please, install it and run pacman-key --populate archlinuxarm"
59
+			exit 1
60
+		fi
61
+		PACMAN_CONF=$(mktemp ${TMPDIR:-/var/tmp}/pacman-conf-archlinux-XXXXXXXXX)
62
+		version="$(echo $arch | cut -c 5)"
63
+		sed "s/Architecture = armv/Architecture = armv${version}h/g" './mkimage-archarm-pacman.conf' > "${PACMAN_CONF}"
64
+		PACMAN_MIRRORLIST='Server = http://mirror.archlinuxarm.org/$arch/$repo'
65
+		PACMAN_EXTRA_PKGS='archlinuxarm-keyring'
66
+		EXPECT_TIMEOUT=1800 # Most armv* based devices can be very slow (e.g. RPiv1)
67
+		ARCH_KEYRING=archlinuxarm
68
+		DOCKER_IMAGE_NAME="armv${version}h/archlinux"
69
+		;;
70
+	*)
71
+		PACMAN_CONF='./mkimage-arch-pacman.conf'
72
+		PACMAN_MIRRORLIST='Server = https://jpn.mirror.archlinux32.org/$arch/$repo'
73
+		PACMAN_EXTRA_PKGS=''
74
+		EXPECT_TIMEOUT=60
75
+		ARCH_KEYRING=archlinux
76
+		DOCKER_IMAGE_NAME=archlinux
77
+		;;
78
+esac
79
+
80
+export PACMAN_MIRRORLIST
81
+
82
+expect <<EOF
83
+	set send_slow {1 .1}
84
+	proc send {ignore arg} {
85
+		sleep .1
86
+		exp_send -s -- \$arg
87
+	}
88
+	set timeout $EXPECT_TIMEOUT
89
+
90
+	spawn pacstrap -C $PACMAN_CONF -c -d -G -i $ROOTFS base haveged $PACMAN_EXTRA_PKGS --ignore $PKGIGNORE
91
+	expect {
92
+		-exact "anyway? \[Y/n\] " { send -- "n\r"; exp_continue }
93
+		-exact "(default=all): " { send -- "\r"; exp_continue }
94
+		-exact "installation? \[Y/n\]" { send -- "y\r"; exp_continue }
95
+		-exact "delete it? \[Y/n\]" { send -- "y\r"; exp_continue }
96
+	}
97
+EOF
98
+
99
+arch-chroot $ROOTFS /bin/sh -c 'rm -r /usr/share/man/*'
100
+arch-chroot $ROOTFS /bin/sh -c "haveged -w 1024; pacman-key --init; pkill haveged; pacman -Rs --noconfirm haveged; pacman-key --populate $ARCH_KEYRING; pkill gpg-agent"
101
+arch-chroot $ROOTFS /bin/sh -c "ln -s /usr/share/zoneinfo/UTC /etc/localtime"
102
+echo 'en_US.UTF-8 UTF-8' > $ROOTFS/etc/locale.gen
103
+arch-chroot $ROOTFS locale-gen
104
+arch-chroot $ROOTFS /bin/sh -c 'echo $PACMAN_MIRRORLIST > /etc/pacman.d/mirrorlist'
105
+
106
+# udev doesn't work in containers, rebuild /dev
107
+DEV=$ROOTFS/dev
108
+rm -rf $DEV
109
+mkdir -p $DEV
110
+mknod -m 666 $DEV/null c 1 3
111
+mknod -m 666 $DEV/zero c 1 5
112
+mknod -m 666 $DEV/random c 1 8
113
+mknod -m 666 $DEV/urandom c 1 9
114
+mkdir -m 755 $DEV/pts
115
+mkdir -m 1777 $DEV/shm
116
+mknod -m 666 $DEV/tty c 5 0
117
+mknod -m 600 $DEV/console c 5 1
118
+mknod -m 666 $DEV/tty0 c 4 0
119
+mknod -m 666 $DEV/full c 1 7
120
+mknod -m 600 $DEV/initctl p
121
+mknod -m 666 $DEV/ptmx c 5 2
122
+ln -sf /proc/self/fd $DEV/fd
123
+
124
+tar --numeric-owner --xattrs --acls -C $ROOTFS -c . | docker import - $DOCKER_IMAGE_NAME
125
+docker run --rm -t $DOCKER_IMAGE_NAME echo Success.
126
+rm -rf $ROOTFS