forked from msrd0/mkalpiimg
48 lines
861 B
Rust
48 lines
861 B
Rust
|
use super::{run_chroot, Image};
|
||
|
use std::fs;
|
||
|
|
||
|
pub fn init_first_boot(img: &Image) -> anyhow::Result<()> {
|
||
|
eprintln!("Preparing first boot script ...");
|
||
|
|
||
|
fs::write(
|
||
|
img.root.0.join("usr").join("local").join("bin").join("first-boot"),
|
||
|
r#"#!/bin/sh
|
||
|
set -xe
|
||
|
|
||
|
cat <<PARTED | sudo parted ---pretend-input-tty /dev/mmcblk0
|
||
|
unit %
|
||
|
resizepart 2
|
||
|
Yes
|
||
|
100%
|
||
|
PARTED
|
||
|
|
||
|
partprobe
|
||
|
resize2fs /dev/mmcblk0p2
|
||
|
|
||
|
rc-update add zram-init boot
|
||
|
|
||
|
rc-update del first-boot
|
||
|
rm /etc/init.d/first-boot /usr/local/bin/first-boot
|
||
|
|
||
|
reboot
|
||
|
"#
|
||
|
)?;
|
||
|
fs::write(
|
||
|
img.root.0.join("etc").join("init.d").join("first-boot"),
|
||
|
r#"#!/sbin/openrc-run
|
||
|
command="/usr/local/bin/first-boot"
|
||
|
command_background=false
|
||
|
depend() {
|
||
|
after modules
|
||
|
need localmount
|
||
|
}"#
|
||
|
)?;
|
||
|
run_chroot(
|
||
|
img,
|
||
|
"root",
|
||
|
"chmod +x /etc/init.d/first-boot /usr/local/bin/first-boot; rc-update add first-boot"
|
||
|
)?;
|
||
|
|
||
|
Ok(())
|
||
|
}
|