mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
Feature/multi platform (#1866)
* wip * wip * wip * wip * wip * wip * remove debian dir * lazy env and git hash * remove env and git hash on clean * don't leave project dir * use docker for native builds * start9 rust * correctly mount registry * remove systemd config * switch to /usr/bin * disable sound for now * wip * change disk list * multi-arch images * multi-arch system images * default aarch64 * edition 2021 * dynamic wifi interface name * use wifi interface from config * bugfixes * add beep based sound * wip * wip * wip * separate out raspberry pi specific files * fixes * use new initramfs always * switch journald conf to sed script * fixes * fix permissions * talking about kernel modules not scripts * fix * fix * switch to MBR * install to /usr/lib * fixes * fixes * fixes * fixes * add media config to cfg path * fixes * fixes * fixes * raspi image fixes * fix test * fix workflow * sync boot partition * gahhhhh
This commit is contained in:
5
build/raspberry-pi/config.yaml
Normal file
5
build/raspberry-pi/config.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
os-partitions:
|
||||
boot: /dev/mmcblk0p1
|
||||
root: /dev/mmcblk0p2
|
||||
ethernet-interface: eth0
|
||||
wifi-interface: wlan0
|
||||
16
build/raspberry-pi/init-with-sound.sh
Executable file
16
build/raspberry-pi/init-with-sound.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
function flatline {
|
||||
echo -n "0" > /sys/class/pwm/pwmchip0/export
|
||||
sleep 0.5
|
||||
echo -n "2272727" > /sys/class/pwm/pwmchip0/pwm0/period
|
||||
echo -n "1136364" > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
|
||||
echo -n "1" > /sys/class/pwm/pwmchip0/pwm0/enable
|
||||
}
|
||||
|
||||
initialization.sh
|
||||
STATUS=$?
|
||||
if [ $STATUS -ne 0 ]; then
|
||||
flatline
|
||||
exit $STATUS
|
||||
fi
|
||||
12
build/raspberry-pi/initialization.service
Normal file
12
build/raspberry-pi/initialization.service
Normal file
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Boot process for system initialization.
|
||||
After=network-online.target systemd-time-wait-sync.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/init-with-sound.sh
|
||||
RemainAfterExit=true
|
||||
StandardOutput=append:/var/log/initialization.log
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
60
build/raspberry-pi/initialization.sh
Executable file
60
build/raspberry-pi/initialization.sh
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# introduce start9 username and embassy as default password
|
||||
if ! awk -F: '{ print $1 }' /etc/passwd | grep start9
|
||||
then
|
||||
usermod -l start9 -d /home/start9 -m pi
|
||||
groupmod --new-name start9 pi
|
||||
echo start9:embassy | chpasswd
|
||||
fi
|
||||
|
||||
START=$(date +%s)
|
||||
while ! ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null; do
|
||||
>&2 echo "Waiting for internet connection..."
|
||||
sleep 1
|
||||
if [ "$[$START + 60]" -lt $(date +%s) ]; then
|
||||
>&2 echo "Timed out waiting for internet connection..."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo "Connected to network"
|
||||
|
||||
# Convert all repos to use https:// before apt update
|
||||
sed -i "s/http:/https:/g" /etc/apt/sources.list /etc/apt/sources.list.d/*.list
|
||||
|
||||
. /usr/lib/embassy/scripts/add-apt-sources
|
||||
|
||||
apt-get update
|
||||
apt-get upgrade -y
|
||||
apt-get install -y $(cat /usr/lib/embassy/depends)
|
||||
apt-get remove --purge -y $(cat /usr/lib/embassy/conflicts) beep
|
||||
apt-get autoremove -y
|
||||
|
||||
systemctl stop tor
|
||||
|
||||
. /usr/lib/embassy/scripts/postinst
|
||||
|
||||
systemctl enable embassyd.service embassy-init.service
|
||||
|
||||
sed -i 's/^/usb-storage.quirks=152d:0562:u,14cd:121c:u,0781:cfcb:u /g' /boot/cmdline.txt
|
||||
|
||||
# making that *sudo docker stats* command fulfil its purpose by displaying all metrics
|
||||
sed -i 's/rootwait quiet.*/rootwait cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory quiet/g' /boot/cmdline.txt
|
||||
|
||||
systemctl disable nc-broadcast.service
|
||||
systemctl disable initialization.service
|
||||
|
||||
update-initramfs -c -k "$(uname -r)"
|
||||
|
||||
sed -i /boot/config.txt -e "/initramfs.*/d"
|
||||
echo initramfs "initrd.img-$(uname -r)" >> /boot/config.txt
|
||||
|
||||
sed -i /boot/cmdline.txt -e "s/^/boot=embassy /"
|
||||
|
||||
passwd -l start9
|
||||
|
||||
sync
|
||||
|
||||
reboot
|
||||
|
||||
18
build/raspberry-pi/make-image.sh
Executable file
18
build/raspberry-pi/make-image.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
function partition_for () {
|
||||
if [[ "$1" =~ [0-9]+$ ]]; then
|
||||
echo "$1p$2"
|
||||
else
|
||||
echo "$1$2"
|
||||
fi
|
||||
}
|
||||
|
||||
cp raspios.img embassyos-raspi.img
|
||||
export OUTPUT_DEVICE=$(sudo losetup --show -fP embassyos-raspi.img)
|
||||
./build/raspberry-pi/write-image.sh
|
||||
sudo e2fsck -f -y `partition_for ${OUTPUT_DEVICE} 2`
|
||||
sudo resize2fs -M `partition_for ${OUTPUT_DEVICE} 2`
|
||||
sudo losetup -d $OUTPUT_DEVICE
|
||||
13
build/raspberry-pi/nc-broadcast.service
Normal file
13
build/raspberry-pi/nc-broadcast.service
Normal file
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=Writes initialization logs to network
|
||||
Requires=initialization.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
ExecStart=/usr/local/bin/nc-broadcast --input=/var/log/initialization.log --tee 0.0.0.0:8080
|
||||
RemainAfterExit=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
105
build/raspberry-pi/rip-image.sh
Executable file
105
build/raspberry-pi/rip-image.sh
Executable file
@@ -0,0 +1,105 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
function mktmpfifo () {
|
||||
TMP_PATH=$(mktemp)
|
||||
rm $TMP_PATH
|
||||
mkfifo $TMP_PATH
|
||||
echo $TMP_PATH
|
||||
}
|
||||
|
||||
if ! which pv > /dev/null; then
|
||||
>&2 echo 'This script would like to use `pv` to show a progress indicator, but it is not installed.'
|
||||
if which apt-get > /dev/null; then
|
||||
read -p "Install? [y/N]" -n 1 -r
|
||||
echo
|
||||
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
|
||||
sudo apt-get install pv
|
||||
fi
|
||||
elif which pacman > /dev/null; then
|
||||
read -p "Install? [y/N]" -n 1 -r
|
||||
echo
|
||||
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
|
||||
sudo pacman -S pv
|
||||
fi
|
||||
elif which brew > /dev/null; then
|
||||
read -p "Install? [y/N]" -n 1 -r
|
||||
echo
|
||||
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
|
||||
brew install pv
|
||||
fi
|
||||
else
|
||||
>&2 echo 'This script does not recognize what package manager you have available on your system.'
|
||||
>&2 echo 'Please go install the utility manually if you want progress reporting.'
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
>&2 echo 'OSX not supported'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! test -e /dev/disk/by-label/green; then
|
||||
>&2 echo '`green` partition not found'
|
||||
exit 1
|
||||
fi
|
||||
export SOURCE_PARTITION=$(readlink -f /dev/disk/by-label/green)
|
||||
|
||||
if [[ "$SOURCE_PARTITION" =~ ^/dev/loop ]]; then
|
||||
>&2 echo 'You are currently ripping from a loop device.'
|
||||
>&2 echo 'This is probably a mistake, and usually means you failed to detach a .img file.'
|
||||
read -p "Continue anyway? [y/N]" -n 1 -r
|
||||
echo
|
||||
if ! [[ "$REPLY" =~ ^[Yy]$ ]]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
sudo e2fsck -f ${SOURCE_PARTITION}
|
||||
sudo resize2fs -M ${SOURCE_PARTITION}
|
||||
export BLOCK_INFO=$(sudo dumpe2fs ${SOURCE_PARTITION})
|
||||
export BLOCK_COUNT=$(echo "$BLOCK_INFO" | grep "Block count:" | sed 's/Block count:\s\+//g')
|
||||
export BLOCK_SIZE=$(echo "$BLOCK_INFO" | grep "Block size:" | sed 's/Block size:\s\+//g')
|
||||
export FS_SIZE=$[$BLOCK_COUNT*$BLOCK_SIZE]
|
||||
|
||||
echo "Ripping $FS_SIZE bytes from $SOURCE_PARTITION"
|
||||
if which pv > /dev/null; then
|
||||
sudo cat ${SOURCE_PARTITION} | head -c $FS_SIZE | pv -s $FS_SIZE | sudo dd of=update.img bs=1M iflag=fullblock oflag=direct conv=fsync 2>/dev/null
|
||||
else
|
||||
sudo cat ${SOURCE_PARTITION} | head -c $FS_SIZE | sudo dd of=update.img bs=1M iflag=fullblock oflag=direct conv=fsync
|
||||
fi
|
||||
echo Verifying...
|
||||
export INPUT_HASH=$(mktemp)
|
||||
export OUTPUT_HASH=$(mktemp)
|
||||
if which pv > /dev/null; then
|
||||
export PV_IN=$(mktmpfifo)
|
||||
fi
|
||||
sudo cat ${SOURCE_PARTITION} | head -c $FS_SIZE | tee -a $PV_IN | sha256sum > $INPUT_HASH &
|
||||
export INPUT_CHILD=$!
|
||||
sudo cat update.img | head -c $FS_SIZE | tee -a $PV_IN | sha256sum > $OUTPUT_HASH &
|
||||
export OUTPUT_CHILD=$!
|
||||
if which pv > /dev/null; then
|
||||
pv -s $[$FS_SIZE*2] < $PV_IN > /dev/null &
|
||||
fi
|
||||
wait $INPUT_CHILD $OUTPUT_CHILD
|
||||
if which pv > /dev/null; then
|
||||
rm $PV_IN
|
||||
fi
|
||||
if ! [[ "$(cat $INPUT_HASH)" == "$(cat $OUTPUT_HASH)" ]]; then
|
||||
rm $INPUT_HASH $OUTPUT_HASH
|
||||
>&2 echo Verification Failed
|
||||
exit 1
|
||||
fi
|
||||
rm $INPUT_HASH $OUTPUT_HASH
|
||||
echo "Verification Succeeded"
|
||||
|
||||
sudo e2label update.img red
|
||||
echo "Image Relabeled to \"red\""
|
||||
|
||||
echo "Compressing..."
|
||||
if which pv > /dev/null; then
|
||||
cat update.img | pv -s $FS_SIZE | gzip > update.img.gz
|
||||
else
|
||||
cat update.img | gzip > update.img.gz
|
||||
fi
|
||||
55
build/raspberry-pi/write-image.sh
Executable file
55
build/raspberry-pi/write-image.sh
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
function partition_for () {
|
||||
if [[ "$1" =~ [0-9]+$ ]]; then
|
||||
echo "$1p$2"
|
||||
else
|
||||
echo "$1$2"
|
||||
fi
|
||||
}
|
||||
|
||||
# Mount the boot partition and config
|
||||
mkdir -p /tmp/eos-mnt
|
||||
sudo mount `partition_for ${OUTPUT_DEVICE} 1` /tmp/eos-mnt
|
||||
|
||||
cat /tmp/eos-mnt/config.txt | grep -v "dtoverlay=" | sudo tee /tmp/eos-mnt/config.txt.tmp > /dev/null
|
||||
echo "dtoverlay=pwm-2chan,disable-bt" | sudo tee -a /tmp/eos-mnt/config.txt.tmp > /dev/null
|
||||
echo "gpu_mem=16" | sudo tee -a /tmp/eos-mnt/config.txt.tmp > /dev/null
|
||||
sudo mv /tmp/eos-mnt/config.txt.tmp /tmp/eos-mnt/config.txt
|
||||
sudo touch /tmp/eos-mnt/ssh
|
||||
|
||||
sudo umount /tmp/eos-mnt
|
||||
|
||||
sudo mount `partition_for ${OUTPUT_DEVICE} 2` /tmp/eos-mnt
|
||||
|
||||
sudo mkdir /tmp/eos-mnt/media/embassy/
|
||||
sudo make install ARCH=aarch64 DESTDIR=/tmp/eos-mnt
|
||||
sudo sed -i 's/raspberrypi/embassy/g' /tmp/eos-mnt/etc/hostname
|
||||
sudo sed -i 's/raspberrypi/embassy/g' /tmp/eos-mnt/etc/hosts
|
||||
sudo cp cargo-deps/aarch64-unknown-linux-gnu/release/nc-broadcast /tmp/eos-mnt/usr/local/bin
|
||||
sudo cp backend/*.service /tmp/eos-mnt/etc/systemd/system/
|
||||
sudo mkdir -p /tmp/eos-mnt/etc/embassy
|
||||
sudo cp build/raspberry-pi/config.yaml /tmp/eos-mnt/etc/embassy/config.yaml
|
||||
|
||||
# Make the .ssh directory for UID 1000 user
|
||||
sudo mkdir -p /tmp/eos-mnt/home/$(awk -v val=1000 -F ":" '$3==val{print $1}' /tmp/eos-mnt/etc/passwd)/.ssh
|
||||
sudo mv /tmp/eos-mnt/etc/sudoers.d/010_pi-nopasswd /tmp/eos-mnt/etc/sudoers.d/010_start9-nopasswd
|
||||
sudo sed -i 's/pi/start9/g' /tmp/eos-mnt/etc/sudoers.d/010_start9-nopasswd
|
||||
sudo sed -i 's/ pi / start9 /g' /tmp/eos-mnt/etc/systemd/system/autologin@.service
|
||||
|
||||
if [[ "$ENVIRONMENT" =~ (^|-)dev($|-) ]]; then
|
||||
cat ./build/raspberry-pi/initialization.sh | grep -v "passwd -l start9" | sudo tee /tmp/eos-mnt/usr/local/bin/initialization.sh > /dev/null
|
||||
sudo chmod +x /tmp/eos-mnt/usr/local/bin/initialization.sh
|
||||
else
|
||||
sudo cp ./build/raspberry-pi/initialization.sh /tmp/eos-mnt/usr/local/bin
|
||||
fi
|
||||
sudo cp ./build/raspberry-pi/init-with-sound.sh /tmp/eos-mnt/usr/local/bin
|
||||
|
||||
sudo cp ./build/raspberry-pi/initialization.service /tmp/eos-mnt/etc/systemd/system/initialization.service
|
||||
sudo ln -s /etc/systemd/system/initialization.service /tmp/eos-mnt/etc/systemd/system/multi-user.target.wants/initialization.service
|
||||
sudo cp ./build/raspberry-pi/nc-broadcast.service /tmp/eos-mnt/etc/systemd/system/nc-broadcast.service
|
||||
sudo ln -s /etc/systemd/system/nc-broadcast.service /tmp/eos-mnt/etc/systemd/system/multi-user.target.wants/nc-broadcast.service
|
||||
|
||||
sudo umount /tmp/eos-mnt
|
||||
Reference in New Issue
Block a user