86 lines
2.5 KiB
Bash
Executable File
86 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
. ./lib.sh # Include library
|
|
|
|
# Image
|
|
DISTRIB="archlinux"
|
|
ARCH=${ARCH:-"armhf"}
|
|
TARGET=${TARGET:-"rootfs-target"}
|
|
CLEAN_PATHS="/root/.bash_history /root/.history /etc/resolv.conf /etc/ssh/*_key*"
|
|
PKGS_INCLUDE=${PKGS_INCLUDE:-"cronie,curl,iptables,dhcpcd,less,man,nano,nbd,ntp,openssh,wget,vim"}
|
|
# MIRROR=${MIRROR:-"http://mirror.cloud.online.net/ubuntu-ports/"}
|
|
VERSION=${VERSION:-"latest"}
|
|
LOCALES="en_US.UTF-8,fr_FR.UTF-8"
|
|
S3_URL=s3://test-images/archlinux/
|
|
|
|
# Required
|
|
NAME=${NAME:-"rootfs-$ARCH-$DISTRIB"}
|
|
build_image() {
|
|
# TODO Mirror
|
|
sudo wget -O source.tar.gz \
|
|
http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-$VERSION.tar.gz
|
|
sudo mkdir -p "$TARGET"
|
|
sudo tar -C "$TARGET" -xzf source.tar.gz
|
|
}
|
|
|
|
patch_image() {
|
|
# prepare chroot
|
|
sudo umount $TARGET/{sys,dev,proc} || true
|
|
sudo mount -t proc proc $TARGET/proc
|
|
sudo mount -t sysfs sys $TARGET/sys
|
|
sudo mount -o bind /dev $TARGET/dev
|
|
do_in_target 'sed s/root:[^:]\+:/root:x:/ -i /etc/shadow'
|
|
sudo mkdir -p $TARGET/run/systemd/resolve
|
|
sudo cp /etc/resolv.conf $TARGET/run/systemd/resolve/resolv.conf
|
|
|
|
do_in_target 'curl https://raw.githubusercontent.com/online-labs/ocs-scripts/master/upgrade_root.bash | bash'
|
|
patch_target archlinux/patches
|
|
|
|
# TODO Get ssh keys from config
|
|
sudo mkdir -p $TARGET/root/.ssh
|
|
sudo cp -va /root/.ssh/authorized_keys $TARGET/root/.ssh
|
|
|
|
echo $LOCALES | sed 's/,/\n/' | while read loc; do
|
|
do_in_target "sed -e s/^\#${loc}/${loc}/ -i /etc/locale.gen"
|
|
done
|
|
do_in_target locale-gen
|
|
|
|
pkgs_pacman=`echo $PKGS_INCLUDE | tr ',' ' '`
|
|
do_in_target "pacman -Sy --noconfirm $pkgs_pacman"
|
|
do_in_target "systemctl enable sshd.service"
|
|
|
|
# tty settings
|
|
do_in_target "systemctl disable getty@tty1.service"
|
|
do_in_target "systemctl enable serial-getty@ttyS0.service"
|
|
|
|
# clean chroot
|
|
sudo rm -f $TARGET/run/systemd/resolve/resolv.conf
|
|
sudo umount $TARGET/{sys,dev,proc} || true
|
|
}
|
|
|
|
upgrade_image() {
|
|
sudo umount $TARGET/{sys,dev,proc} || true
|
|
sudo mount -t proc proc $TARGET/proc
|
|
sudo mount -t sysfs sys $TARGET/sys
|
|
sudo mount -o bind /dev $TARGET/dev
|
|
|
|
sudo cp /etc/resolv.conf $TARGET/run/systemd/resolve/resolv.conf
|
|
|
|
do_in_target "pacman --noconfirm -Suy"
|
|
|
|
sudo rm -f $TARGET/run/systemd/resolve/resolv.conf
|
|
|
|
sudo umount $TARGET/{sys,dev,proc} || true
|
|
}
|
|
|
|
clean_image() {
|
|
# FIXME: clean package achives
|
|
clean_target $CLEAN_PATHS
|
|
# FIXME: reload package index
|
|
}
|
|
|
|
|
|
if [ "${1}" != "--source-only" ]; then
|
|
cli $@
|
|
fi
|