summaryrefslogtreecommitdiff
path: root/chunks/busybox.morph
blob: ebc448182bf1e357febc7541da26b9a09a40c953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: busybox
kind: chunk

configure-commands:
# Busybox's default config has everything enabled.
- make defconfig

- sed -e 's|.*UDHCPC_DEFAULT_SCRIPT.*|CONFIG_UDHCPC_DEFAULT_SCRIPT="'"$PREFIX"/share/udhcpc/default.script'"|' -i .config
- sed -e 's|.*IFUPDOWN_IFSTATE_PATH.*|CONFIG_IFUPDOWN_IFSTATE_PATH="/run/ifstate"|' -i .config

# Avoid dividing applets between $PREFIX/[s]bin and $PREFIX/usr/[s]bin.
- '[ "$PREFIX" = /usr ] || sed -e ''s/.*INSTALL_NO_USR.*/CONFIG_INSTALL_NO_USR=y/'' -i .config'

# We have GAWK, but in GENIVI baseline we want to get rid of it
# - sed -e 's/CONFIG_AWK=y.*/# CONFIG_AWK is not set/' -i .config

# Depends on stuff that was removed since eglibc 2.14.
- sed -e 's/CONFIG_INETD=y.*/# CONFIG_INETD is not set/' -i .config

# Busybox Patch is incompatible enough with GNU Patch that it can't be
# used for GNULib projects built from Git.
- sed -e 's/CONFIG_PATCH=y.*/# CONFIG_PATCH is not set/' -i .config

# None of this is needed because we have kmod; and it actually breaks the
# Linux build because depmod isn't compatible enough with util-linux's.
- sed -e 's/CONFIG_DEPMOD=y.*/# CONFIG_DEPMOD is not set/' -i .config
- sed -e 's/CONFIG_INSMOD=y.*/# CONFIG_INSMOD is not set/' -i .config
- sed -e 's/CONFIG_MODPROBE=y.*/# CONFIG_MODPROBE is not set/' -i .config
- sed -e 's/CONFIG_MODPROBE_SMALL=y.*/# CONFIG_MODPROBE_SMALL is not set/' -i .config
- sed -e 's/CONFIG_LSMOD=y.*/# CONFIG_LSMOD is not set/' -i .config
- sed -e 's/CONFIG_RMMOD=y.*/# CONFIG_RMMOD is not set/' -i .config

# General features that we don't need.
- sed -e 's/CONFIG_FEATURE_MOUNT_CIFS=y.*/# CONFIG_FEATURE_MOUNT_CIFS is not set/' -i .config
- sed -e 's/CONFIG_FEATURE_EXTRA_QUIET=y.*/# CONFIG_FEATURE_EXTRA_QUIET is not set/' -i .config
- sed -e 's/CONFIG_FEATURE_INIT_COREDUMPS=y.*/# CONFIG_FEATURE_INIT_COREDUMPS is not set/' -i .config
- sed -e 's/CONFIG_FEATURE_INIT_SCTTY=y.*/# CONFIG_FEATURE_INIT_SCTTY is not set/' -i .config
- sed -e 's/CONFIG_FEATURE_INIT_SYSLOG=y.*/# CONFIG_FEATURE_INIT_SYSLOG is not set/' -i .config
- sed -e 's/CONFIG_FEATURE_INITRD=y.*/# CONFIG_FEATURE_INITRD is not set/' -i .config
- sed -e 's/CONFIG_FEATURE_MINIX2=y.*/# CONFIG_FEATURE_MINIX2 is not set/' -i .config
- sed -e 's/CONFIG_FSCK_MINIX=y.*/# CONFIG_FSCK_MINIX is not set/' -i .config
- sed -e 's/CONFIG_LOSETUP=y.*/# CONFIG_LOSETUP is not set/' -i .config
- sed -e 's/CONFIG_LSUSB=y.*/# CONFIG_LSUSB is not set/' -i .config
- sed -e 's/CONFIG_LZMA=y.*/# CONFIG_LZMA is not set/' -i .config
- sed -e 's/CONFIG_MKFS_EXT2=y.*/# CONFIG_MKFS_EXT2 is not set/' -i .config
- sed -e 's/CONFIG_MKFS_MINIX=y.*/# CONFIG_MKFS_MINIX is not set/' -i .config
- sed -e 's/CONFIG_STRINGS=y.*/# CONFIG_STRINGS is not set/' -i .config
- sed -e 's/CONFIG_UNLZMA=y.*/# CONFIG_UNLZMA is not set/' -i .config
- sed -e 's/CONFIG_UNXZ=y.*/# CONFIG_UNXZ is not set/' -i .config
- sed -e 's/CONFIG_XZ=y.*/# CONFIG_XZ is not set/' -i .config

# Now turn on some little bits we do need
- sed -e 's/# CONFIG_BBCONFIG is not set/CONFIG_BBCONFIG=y/' -i .config
- sed -e 's/# CONFIG_FEATURE_COMPRESS_BBCONFIG is not set/CONFIG_FEATURE_COMPRESS_BBCONFIG=y/' -i .config
- sed -e 's/# CONFIG_FEATURE_MOUNT_HELPERS is not set/CONFIG_FEATURE_MOUNT_HELPERS=y/' -i .config


build-commands:
- make

install-commands:
- |
  set -e
  if [ "$PREFIX" = /usr ]; then PREFIX=; fi
  make CONFIG_PREFIX="$DESTDIR$PREFIX" install
  chmod 6755 "$DESTDIR$PREFIX"/bin/busybox
- |
  install -D -m 644 /proc/self/fd/0 "$DESTDIR$PREFIX/lib/systemd/system/crond.service" <<'EOF'
  [Unit]
  Description=Cron Service
  
  [Service]
  ExecStart=/usr/sbin/crond -f
  Restart=always
  EOF

- mkdir -p "$DESTDIR/var/spool/cron/crontabs"

# Install custom udev rule to run ifup for every network device detected
- |
  install -D -m 644 /proc/self/fd/0 "$DESTDIR/lib/udev/rules.d/99-baserock.rule" <<'EOF'
  ACTION=="remove", GOTO="baserock_end"
  # run ifup for every network device detected
  SUBSYSTEM=="net", KERNEL!="lo", ENV{SYSTEMD_WANTS}="ifup@%k.service"
  
  LABEL="baserock_end"
  EOF
- |
  install -D -m 644 /proc/self/fd/0 "$DESTDIR$PREFIX/lib/systemd/system/ifup@.service" <<'EOF'
  [Unit]
  Description=ifup for %I
  Before=network.target
  
  [Service]
  Type=oneshot
  ExecStart=/sbin/ifup %I
  ExecStop=/sbin/ifdown %I
  RemainAfterExit=true
  EOF

# Set up DHCP
- mkdir -p "$DESTDIR$PREFIX"/share/udhcpc
- cp examples/udhcp/simple.script "$DESTDIR$PREFIX"/share/udhcpc/default.script

# Set up NTP
- |
  install -D /proc/self/fd/0 "$DESTDIR$PREFIX/sbin" <<'EOF'
  #!/bin/sh
  #
  # Invoke the Busybox ntpd with servers listed in /etc/ntpd.conf, if it
  # exists. The servers should be listed one per line, with the first
  # word in the line being "server". Any lines that don't start with
  # "server" as the first word are ignored. The server name should be
  # the second word. Anything else on the line is ignored.
  #
  # If the config file does not exist, no default servers are used.
  
  set -eu
  
  parse_servers()
  {
      awk '$1 == "server" { for (i=2; i <= NF; ++i) print "-p", $i }' "$1"
  }
  
  if [ -e /etc/ntpd.conf ]
  then
      exec ntpd $(parse_servers /etc/ntpd.conf) "$@"
  else
      exec ntpd "$@"
  fi
  EOF
- |
  install -D -m 644 /proc/self/fd/0 "$DESTDIR$PREFIX/lib/systemd/system/ntpd-boot.service" <<'EOF'
  [Unit]
  Description=Set clock at boot with NTP
  Before=network.target
  Before=ntpd.service
  
  [Service]
  Type=oneshot
  ExecStart=/usr/sbin/run-ntpd-with-config -n -q
  Restart=on-failure
  RestartSec=15
  EOF
- |
  install -D -m 644 /proc/self/fd/0 "$DESTDIR$PREFIX/lib/systemd/system/ntpd.service" <<'EOF'
  [Unit]
  Description=Keep clock synchronised with NTP
  Before=network.target
  After=ntpd-boot.service
  
  [Service]
  Type=simple
  ExecStart=/usr/sbin/run-ntpd-with-config -n
  Restart=on-failure
  RestartSec=15
  EOF
- install -d "$DESTDIR/etc"
- |
  cat << EOF > "$DESTDIR/etc/ntpd.conf"
  server 0.pool.ntp.org
  server 1.pool.ntp.org
  server 2.pool.ntp.org
  server 3.pool.ntp.org
  EOF

# Set up man environment variables
- |
  cat << EOF > "$DESTDIR/etc/profile"
  # Set default pager to less
  export MANPAGER='less -R'
  EOF
- |
  cat << EOF > "$DESTDIR/etc/man.conf"
  # This file is used by man to provide a manpath for those without one by
  # examining their PATH environment variable.
  #
  # Lines beginning with `#' are comments and are ignored. Any combination of
  # tabs or spaces may be used as `whitespace' separators.

  MANDATORY_MANPATH                       /usr/man
  MANDATORY_MANPATH                       /usr/share/man
  MANDATORY_MANPATH                       /usr/local/share/man
  EOF

# Install systemd units
- mkdir -p "$DESTDIR$PREFIX/lib/systemd/system/multi-user.target.wants"
- |
  for f in crond.service ntpd.service ntpd-boot.service; do
      ln -s "../$f" "$DESTDIR$PREFIX/lib/systemd/system/multi-user.target.wants/"
  done