Initial commit

pull/2/head
Dustin 2022-06-22 17:06:58 -05:00
commit 50d2f3459b
34 changed files with 2106 additions and 0 deletions

14
.editorconfig Normal file
View File

@ -0,0 +1,14 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
[*.sh]
indent_style = space
indent_size = 4
[Jenkinsfile]
indent_style = space
indent_size = 4

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/_build

0
Config.in Normal file
View File

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
BUILDROOT_SRC ?= ~/src/buildroot
.PHONY: all initramfs rootfs
all: initramfs rootfs
rootfs: _build/rootfs/.config
$(MAKE) -C _build/rootfs
initramfs: _build/initramfs/.config
$(MAKE) -C _build/initramfs
_build/rootfs/.config: configs/metricspi_defconfig
$(MAKE) -C $(BUILDROOT_SRC) O=${PWD}/_build/rootfs BR2_EXTERNAL=${PWD} metricspi_defconfig
_build/initramfs/.config: configs/metricspi_initramfs_defconfig
$(MAKE) -C $(BUILDROOT_SRC) O=${PWD}/_build/initramfs BR2_EXTERNAL=${PWD} metricspi_initramfs_defconfig

1
cmdline.txt Normal file
View File

@ -0,0 +1 @@
audit=0 panic=5 console=ttyAMA0

32
config.txt Normal file
View File

@ -0,0 +1,32 @@
# Please note that this is only a sample, we recommend you to change it to fit
# your needs.
# You should override this file using BR2_PACKAGE_RPI_FIRMWARE_CONFIG_FILE.
# See http://buildroot.org/manual.html#rootfs-custom
# and http://elinux.org/RPiconfig for a description of config.txt syntax
start_file=start4.elf
fixup_file=fixup4.dat
kernel=Image
# To use an external initramfs file
initramfs initramfs.img.lz4
# Disable overscan assuming the display supports displaying the full resolution
# If the text shown on the screen disappears off the edge, comment this out
disable_overscan=1
# fixes rpi (3B, 3B+, 3A+, 4B and Zero W) ttyAMA0 serial console
#dtoverlay=miniuart-bt
dtoverlay=disable-bt
# enable RTC
dtparam=i2c_vc=on
dtoverlay=i2c-rtc,pcf85063a,i2c_csi_dsi
# enable dwc2 USB controller (USB 2.0)
dtoverlay=dwc2,dr_mode=host
# enable 64bits support
arm_64bit=1

View File

@ -0,0 +1,87 @@
BR2_aarch64=y
BR2_cortex_a72=y
BR2_ARM_FPU_VFPV4=y
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_10=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_TARGET_GENERIC_HOSTNAME="localhost"
BR2_INIT_SYSTEMD=y
BR2_ROOTFS_DEVICE_TABLE="system/device_table.txt $(BR2_EXTERNAL_metricspi_PATH)/rootfs/device_table.txt"
# BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW is not set
BR2_SYSTEM_DEFAULT_PATH="/bin:/sbin:/usr/bin:/usr/sbin"
BR2_ROOTFS_USERS_TABLES="$(BR2_EXTERNAL_metricspi_PATH)/rootfs/users"
BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_metricspi_PATH)/rootfs/overlay"
BR2_ROOTFS_POST_FAKEROOT_SCRIPT="$(BR2_EXTERNAL_metricspi_PATH)/rootfs/post-fakeroot.sh"
BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_metricspi_PATH)/rootfs/post-image.sh"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,0b54dbda3cca2beb51e236a25738784e90853b64)/linux-0b54dbda3cca2beb51e236a25738784e90853b64.tar.gz"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_metricspi_PATH)/linux.config"
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="broadcom/bcm2711-rpi-cm4"
BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
# BR2_PACKAGE_BUSYBOX is not set
BR2_PACKAGE_BTRFS_PROGS=y
BR2_PACKAGE_DOSFSTOOLS=y
BR2_PACKAGE_DOSFSTOOLS_FSCK_FAT=y
BR2_PACKAGE_E2FSPROGS=y
BR2_PACKAGE_RPI_FIRMWARE=y
BR2_PACKAGE_RPI_FIRMWARE_VARIANT_PI4=y
BR2_PACKAGE_RPI_FIRMWARE_CONFIG_FILE="$(BR2_EXTERNAL_metricspi_PATH)/config.txt"
BR2_PACKAGE_PYTHON3=y
BR2_PACKAGE_PYTHON3_ZLIB=y
BR2_PACKAGE_CA_CERTIFICATES=y
BR2_PACKAGE_LIBCURL=y
BR2_PACKAGE_LIBCURL_CURL=y
# BR2_PACKAGE_LIBCURL_PROXY_SUPPORT is not set
# BR2_PACKAGE_LIBCURL_EXTRA_PROTOCOLS_FEATURES is not set
BR2_PACKAGE_COLLECTD=y
# BR2_PACKAGE_COLLECTD_LOGFILE is not set
BR2_PACKAGE_COLLECTD_CHRONY=y
BR2_PACKAGE_COLLECTD_CONNTRACK=y
BR2_PACKAGE_COLLECTD_CONTEXTSWITCH=y
BR2_PACKAGE_COLLECTD_CPU=y
BR2_PACKAGE_COLLECTD_CPUFREQ=y
BR2_PACKAGE_COLLECTD_CPUSLEEP=y
BR2_PACKAGE_COLLECTD_DF=y
BR2_PACKAGE_COLLECTD_DISK=y
BR2_PACKAGE_COLLECTD_ENTROPY=y
BR2_PACKAGE_COLLECTD_ETHSTAT=y
BR2_PACKAGE_COLLECTD_FHCOUNT=y
BR2_PACKAGE_COLLECTD_FILECOUNT=y
BR2_PACKAGE_COLLECTD_FSCACHE=y
BR2_PACKAGE_COLLECTD_HUGEPAGES=y
BR2_PACKAGE_COLLECTD_INTERFACE=y
BR2_PACKAGE_COLLECTD_IPC=y
BR2_PACKAGE_COLLECTD_IPTABLES=y
BR2_PACKAGE_COLLECTD_LOAD=y
BR2_PACKAGE_COLLECTD_MEMORY=y
BR2_PACKAGE_COLLECTD_NETLINK=y
BR2_PACKAGE_COLLECTD_PROCESSES=y
BR2_PACKAGE_COLLECTD_SENSORS=y
BR2_PACKAGE_COLLECTD_SWAP=y
BR2_PACKAGE_COLLECTD_TCPCONNS=y
BR2_PACKAGE_COLLECTD_THERMAL=y
BR2_PACKAGE_COLLECTD_UPTIME=y
BR2_PACKAGE_COLLECTD_USERS=y
BR2_PACKAGE_COLLECTD_VMEM=y
BR2_PACKAGE_COLLECTD_WRITEPROMETHEUS=y
BR2_PACKAGE_CHRONY=y
BR2_PACKAGE_DHCPCD=y
BR2_PACKAGE_IPROUTE2=y
BR2_PACKAGE_OPENSSH=y
# BR2_PACKAGE_OPENSSH_CLIENT is not set
BR2_PACKAGE_SUDO=y
BR2_PACKAGE_COREUTILS=y
# BR2_PACKAGE_SYSTEMD_PSTORE is not set
# BR2_PACKAGE_SYSTEMD_NETWORKD is not set
# BR2_PACKAGE_SYSTEMD_RESOLVED is not set
# BR2_PACKAGE_SYSTEMD_TIMESYNCD is not set
BR2_PACKAGE_UTIL_LINUX_HWCLOCK=y
BR2_PACKAGE_UTIL_LINUX_LOGIN=y
BR2_PACKAGE_UTIL_LINUX_MOUNTPOINT=y
BR2_PACKAGE_UTIL_LINUX_SULOGIN=y
BR2_TARGET_ROOTFS_SQUASHFS=y
BR2_TARGET_ROOTFS_SQUASHFS4_XZ=y
# BR2_TARGET_ROOTFS_TAR is not set

View File

@ -0,0 +1,14 @@
BR2_aarch64=y
BR2_cortex_a72=y
BR2_ARM_FPU_VFPV4=y
BR2_TOOLCHAIN_BUILDROOT_MUSL=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_INIT_NONE=y
# BR2_TARGET_ENABLE_ROOT_LOGIN is not set
# BR2_TARGET_GENERIC_GETTY is not set
# BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW is not set
BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_metricspi_PATH)/initramfs/overlay"
# BR2_PACKAGE_IFUPDOWN_SCRIPTS is not set
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_CPIO_LZ4=y
# BR2_TARGET_ROOTFS_TAR is not set

2
external.desc Normal file
View File

@ -0,0 +1,2 @@
name: metricspi
desc: Victoria Metrics appliance

0
external.mk Normal file
View File

28
initramfs/overlay/init Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
# vim: set sw=4 ts=4 sts=4 et :
bail() {
exec /bin/sh < /dev/console > /dev/console 2> /dev/console
}
# XXX Why doesn't LABEL= work here?
root=/dev/nvme0n1p2
mkdir -p /boot /dev /run /sysroot || bail
mount -o size=20%,nr_inodes=819200,mode=755,inode64 -t tmpfs tmpfs /run || bail
mount -t devtmpfs devtmpfs /dev || bail
mount -t proc proc /proc || bail
mount -o subvol=boot -t btrfs ${root} /boot || bail
mount -o ro,loop -t squashfs /boot/rootfs.squashfs /sysroot || bail
mkdir -p /run/etc || bail
mount -o subvol=etc -t btrfs ${root} /run/etc || bail
mount -o lowerdir=/sysroot/etc,upperdir=/run/etc/rw,workdir=/run/etc/.work \
-t overlay overlay /sysroot/etc || bail
mount --move /boot /sysroot/boot || bail
mount --move /run /sysroot/run || bail
exec switch_root /sysroot /lib/systemd/systemd || bail

1566
linux.config Normal file

File diff suppressed because it is too large Load Diff

13
nsswitch.conf Normal file
View File

@ -0,0 +1,13 @@
# /etc/nsswitch.conf
passwd: files systemd
group: files [SUCCESS=merge] systemd
shadow: files systemd
hosts: files myhostname dns
networks: files dns
protocols: files
services: files
ethers: files
rpc: files

1
rootfs/device_table.txt Normal file
View File

@ -0,0 +1 @@
/boot d 755 0 0 - - - - -

View File

@ -0,0 +1,2 @@
sourcedir /run/chrony-dhcp
makestep 0.1 10

View File

@ -0,0 +1 @@
DAEMON_ARGS=-w

View File

@ -0,0 +1,56 @@
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.
# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel
# Inform the DHCP server of our hostname for DDNS.
hostname
hostname_short
# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid
# Persist interface configuration when dhcpcd exits.
persistent
# vendorclassid is set to blank to avoid sending the default of
# dhcpcd-<version>:<os>:<machine>:<platform>
vendorclassid
# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu
# Request a hostname from the network
option host_name
# Most distributions have NTP support.
option ntp_servers
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit
option log_servers
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private
denyinterfaces dummy* veth* docker*
env ntp_restart_cmd=chronyc reload sources
env NTP_CONF=/run/chrony-dhcp/dhcpcd.conf

3
rootfs/overlay/etc/fstab Normal file
View File

@ -0,0 +1,3 @@
tmpfs /root tmpfs size=1M,mode=550 0 0
LABEL=RPIBOOT /boot/efi vfat defaults 0 0
LABEL=metricspi /var btrfs subvol=var 0 0

View File

@ -0,0 +1,116 @@
# $OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/bin:/sbin:/usr/bin:/usr/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedPrincipalsFile none
AuthorizedKeysCommand /usr/libexec/ssh-authorized-keys %u %t
AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
#PermitEmptyPasswords no
# Change to no to disable s/key passwords
KbdInteractiveAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# override default of no subsystems
Subsystem sftp /usr/libexec/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server

View File

@ -0,0 +1 @@
jenkins ALL = (ALL) NOPASSWD: ALL

View File

@ -0,0 +1,31 @@
enable chrony-wait.service
enable dhcpcd.service
enable dbus.socket
enable dbus-broker.service
enable sshd.service
enable chronyd.service
enable chrony.service
enable auditd.service
enable restorecond.service
enable rsyslog.*
enable syslog-ng.*
enable sysklogd.*
enable firewalld.service
enable lm_sensors.service
enable mcelog.*
enable smartd.service
enable rngd.service
enable fstrim.timer
enable logrotate.timer

View File

@ -0,0 +1 @@
disable *

View File

@ -0,0 +1,47 @@
[Unit]
Description=Wait for chrony to synchronize system clock
Documentation=man:chronyc(1)
After=chrony.service chronyd.service
After=network-online.target
Before=time-sync.target
Wants=time-sync.target
Wants=network-online.target
[Service]
Type=oneshot
# Wait for chronyd to update the clock and the remaining
# correction to be less than 0.1 seconds
ExecStart=/usr/bin/chronyc -h 127.0.0.1,::1 waitsync 0 0.1 0.0 1
TimeoutStartSec=5m
RemainAfterExit=yes
StandardOutput=null
CapabilityBoundingSet=
DevicePolicy=closed
DynamicUser=yes
IPAddressAllow=localhost
IPAddressDeny=any
LockPersonality=yes
MemoryDenyWriteExecute=yes
PrivateDevices=yes
PrivateUsers=yes
ProcSubset=pid
ProtectClock=yes
ProtectControlGroups=yes
ProtectHome=yes
ProtectHostname=yes
ProtectKernelLogs=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
ProtectProc=invisible
ProtectSystem=strict
RestrictAddressFamilies=AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallFilter=~@privileged @resources
UMask=0777
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,7 @@
[Unit]
# If collectd starts before eth0 is "UP," it will fail to bind to the TCP
# socket for Prometheus:
#
# write_prometheus plugin: Opening a listening socket for [::]:9103 failed.
After=network-online.target
Wants=network-online.target

View File

@ -0,0 +1,12 @@
[Unit]
Description=Copy /var contents to writable storage
DefaultDependencies=no
After=local-fs.target
Before=sysinit.target
Before=systemd-update-done.service
ConditionPathIsMountPoint=/var
ConditionNeedsUpdate=/var
[Service]
Type=oneshot
ExecStart=/usr/libexec/copy-var.sh

View File

@ -0,0 +1,2 @@
[Unit]
Before=network-online.target

View File

@ -0,0 +1,2 @@
[Service]
PIDFile=/run/dhcpcd/pid

View File

@ -0,0 +1 @@
../copy-var.service

View File

@ -0,0 +1 @@
d /run/chrony-dhcp 0755 root root

View File

@ -0,0 +1,27 @@
#!/bin/sh
set -e
cleanup() {
if [ -n "${tmpdir}" ] && [ -d "${tmpdir}" ] && [ / != "${tmpdir}" ]; then
if mountpoint -q "${tmpdir}"; then
umount "${tmpdir}"
fi
rm -rf "${tmpdir}"
fi
unset tmpdir
}
if ! mountpoint -q /var; then
exit 0
fi
tmpdir=$(TMPDIR=/run mktemp -d)
trap cleanup INT QUIT TERM EXIT
mount -o bind / "${tmpdir}"
cp -a "${tmpdir}"/var/. /var/
if [ -x "$(command -v selinuxenabled)" ] && selinuxenabled; then
restorecon -RF /var
fi

View File

@ -0,0 +1,6 @@
#!/bin/sh
USER="${1}"
KEYTYPE="${2}"
curl -gs http://sshkeys.pyrocufflink.blue/"${USER}"/"${KEYTYPE}".pub

8
rootfs/post-fakeroot.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
systemd-hwdb --root="${TARGET_DIR}" --usr --strict update
# Even with --usr, systemd-hwdb seems to always create hwdb.bin in
# /etc/udev. Perhaps this is a bug when specifying --root.
if [ -f "${TARGET_DIR}"/etc/udev/hwdb.bin ]; then
mv "${TARGET_DIR}"/etc/udev/hwdb.bin "${TARGET_DIR}"/usr/lib/udev/
fi

5
rootfs/post-image.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
# shellcheck disable=SC2154
cp -v "${BR2_EXTERNAL_metricspi_PATH}"/cmdline.txt \
"${BINARIES_DIR}"/rpi-firmware/cmdline.txt

1
rootfs/users Normal file
View File

@ -0,0 +1 @@
jenkins 3000018 jenkins 3000017 * /home/jenkins /bin/sh - Jenkins