Skip to content

Commit

Permalink
Add Ubuntu image support using export BASE_DISTRO=ubuntu in config ph…
Browse files Browse the repository at this point in the history
  • Loading branch information
guysoft committed Jan 13, 2020
1 parent eddb08f commit fb4b810
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 23 deletions.
28 changes: 16 additions & 12 deletions src/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ function die () {
}

function fixLd(){
sed -i 's@/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so@\#/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so@' etc/ld.so.preload
sed -i 's@/usr/lib/arm-linux-gnueabihf/libarmmem.so@\#/usr/lib/arm-linux-gnueabihf/libarmmem.so@' etc/ld.so.preload
if [ -f etc/ld.so.preload ]; then
sed -i 's@/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so@\#/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so@' etc/ld.so.preload
sed -i 's@/usr/lib/arm-linux-gnueabihf/libarmmem.so@\#/usr/lib/arm-linux-gnueabihf/libarmmem.so@' etc/ld.so.preload

# Debian Buster/ Raspbian 2019-06-20
sed -i 's@/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so@#/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so@' etc/ld.so.preload
# Debian Buster/ Raspbian 2019-06-20
sed -i 's@/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so@#/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so@' etc/ld.so.preload
fi
}

function restoreLd(){
sed -i 's@\#/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so@/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so@' etc/ld.so.preload
sed -i 's@\#/usr/lib/arm-linux-gnueabihf/libarmmem.so@/usr/lib/arm-linux-gnueabihf/libarmmem.so@' etc/ld.so.preload
if [ -f etc/ld.so.preload ]; then
sed -i 's@\#/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so@/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so@' etc/ld.so.preload
sed -i 's@\#/usr/lib/arm-linux-gnueabihf/libarmmem.so@/usr/lib/arm-linux-gnueabihf/libarmmem.so@' etc/ld.so.preload

# Debian Buster/ Raspbian 2019-06-20
sed -i 's@#/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so@/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so@' etc/ld.so.preload
# Debian Buster/ Raspbian 2019-06-20
sed -i 's@#/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so@/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so@' etc/ld.so.preload
fi
}

function pause() {
Expand All @@ -42,12 +46,12 @@ function echo_green() {
function gitclone(){
# call like this: gitclone OCTOPI_OCTOPRINT_REPO someDirectory -- this will do:
#
# sudo -u pi git clone -b $OCTOPI_OCTOPRINT_REPO_BRANCH --depth $OCTOPI_OCTOPRINT_REPO_DEPTH $OCTOPI_OCTOPRINT_REPO_BUILD someDirectory
# sudo -u "${BASE_USER}" git clone -b $OCTOPI_OCTOPRINT_REPO_BRANCH --depth $OCTOPI_OCTOPRINT_REPO_DEPTH $OCTOPI_OCTOPRINT_REPO_BUILD someDirectory
#
# and if $OCTOPI_OCTOPRINT_REPO_BUILD != $OCTOPI_OCTOPRINT_REPO_SHIP also:
#
# pushd someDirectory
# sudo -u pi git remote set-url origin $OCTOPI_OCTOPRINT_REPO_SHIP
# sudo -u "${BASE_USER}" git remote set-url origin $OCTOPI_OCTOPRINT_REPO_SHIP
# popd
#
# if second parameter is not provided last URL segment of the BUILD repo URL
Expand Down Expand Up @@ -103,12 +107,12 @@ function gitclone(){
repo_dir=$(echo ${repo_dir} | sed 's%^.*/\([^/]*\)\(\.git\)?$%\1%g')
fi

sudo -u pi git clone $clone_params "$build_repo" "$repo_dir"
sudo -u "${BASE_USER}" git clone $clone_params "$build_repo" "$repo_dir"

if [ "$build_repo" != "$ship_repo" ]
then
pushd "$repo_dir"
sudo -u pi git remote set-url origin "$ship_repo"
sudo -u "${BASE_USER}" git remote set-url origin "$ship_repo"
popd
fi
}
Expand Down
11 changes: 8 additions & 3 deletions src/custompios
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ function execute_chroot_script() {

# In docker, these extra commands are required to enable this black-magic
if [ -f /.dockerenv ] && [ "$(arch)" != "armv7l" ] && [ "$(arch)" != "aarch64" ] ; then
update-binfmts --enable qemu-arm
if [ "$BASE_ARCH" == "armv7l" ]; then
update-binfmts --enable qemu-arm
elif [ "$BASE_ARCH" == "aarch64" ] || [ "$BASE_ARCH" == "arm64" ]; then
update-binfmts --enable qemu-aarch64
fi
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc || true
fi
#move filesystem files
Expand All @@ -22,11 +26,12 @@ function execute_chroot_script() {
fi

#black magic of qemu-arm-static
cp `which qemu-arm-static` usr/bin
# cp `which qemu-arm-static` usr/bin

This comment has been minimized.

Copy link
@asdf1nit

asdf1nit Apr 23, 2020

Contributor

Prior to this commit I have no issues building on my x64 debian machine. This and following commits which check for the arch break building for me. The only file that I have to change using the most recent repository is this file so I think it has to do with the way that your checking for the arch and loading the qemu-arm-static elf.

Just adding this line produces this

++ which qemu-aarch64-static
+ cp /usr/bin/qemu-aarch64-static usr/bin/qemu-arm-static
+ cp /home/jonathan/Documents/Guysoft/CustomPiOS/src/modules/base/start_chroot_script chroot_script
+ chmod 755 chroot_script
+ cp /home/jonathan/Documents/Guysoft/CustomPiOS/src/common.sh common.sh
+ chmod 755 common.sh
+ '[' -f /.dockerenv ']'
+ chroot . /bin/bash /chroot_script
/bin/bash: Invalid ELF image for this architecture
++++ echo_red 'build failed, unmounting image...'
++++ echo -e -n '\e[91m'
++++ echo build failed, unmounting image...
build failed, unmounting image...
++++ echo -e -n '\e[0m'

Further handling around added in subsequent commits produce a different error because the system is incorrectly identified as an arm system.

+ echo 'Building on ARM device a armv7l/aarch64/arm64 system, not using qemu'
Building on ARM device a armv7l/aarch64/arm64 system, not using qemu
+ chroot . /bin/bash /chroot_script
chroot: failed to run command '/bin/bash': No such file or directory
++++ echo_red 'build failed, unmounting image...'
++++ echo -e -n '\e[91m'
++++ echo build failed, unmounting image...
build failed, unmounting image...
++++ echo -e -n '\e[0m'

If you can point me to where you're getting the $BASE_ARCH I'll go over this and try to get a fix worked out.

cp `which qemu-aarch64-static` usr/bin/qemu-arm-static

cp $2 chroot_script
chmod 755 chroot_script
cp ${CUSTOM_PI_OS_PATH}/common.sh common.sh
cp "${CUSTOM_PI_OS_PATH}"/common.sh common.sh
chmod 755 common.sh

if [ -f /.dockerenv ] && [ "$(arch)" != "armv7l" ] && [ "$(arch)" != "aarch64" ] ; then
Expand Down
19 changes: 18 additions & 1 deletion src/modules/base/config
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ BASE_VERSION=1.4.0
[ -n "$BASE_IMAGE_PATH" ] || BASE_IMAGE_PATH=${DIST_PATH}/image
[ -n "$BASE_IMAGE_RASPBIAN" ] || BASE_IMAGE_RASPBIAN=yes

[ -n "$BASE_ZIP_IMG" ] || BASE_ZIP_IMG=`ls -t $BASE_IMAGE_PATH/*-raspbian*.zip | head -n 1`
# Distro
[ -n "$BASE_DISTRO" ] || BASE_DISTRO=raspbian

if [ "${BASE_DISTRO}" == "ubuntu" ]; then
# Default image ubuntu
[ -n "$BASE_ZIP_IMG" ] || BASE_ZIP_IMG=`ls -t $BASE_IMAGE_PATH/ubuntu-*.xz | head -n 1`
# Default user ubuntu
[ -n "$BASE_USER" ] || BASE_USER=ubuntu
else
# Default image raspbian
[ -n "$BASE_ZIP_IMG" ] || BASE_ZIP_IMG=`ls -t $BASE_IMAGE_PATH/*-raspbian*.zip | head -n 1`
# Default user raspbian
[ -n "$BASE_USER" ] || BASE_USER=pi
fi

[ -n "$BASE_WORKSPACE" ] || BASE_WORKSPACE=${DIST_PATH}/workspace$WORKSPACE_POSTFIX
# [ -n "$BASE_CHROOT_SCRIPT_PATH" ] || BASE_CHROOT_SCRIPT_PATH=$BASE_SCRIPT_PATH/chroot_script
Expand Down Expand Up @@ -58,3 +71,7 @@ BASE_VERSION=1.4.0

#Keyboard
[ -n "$BASE_CONFIG_KEYBOARD" ] || BASE_CONFIG_KEYBOARD=default

# Arch for now either armv7l, arm64 or aarch64
[ -n "$BASE_ARCH" ] || BASE_ARCH=armv7l

8 changes: 6 additions & 2 deletions src/modules/base/end_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if [ -n "$BASE_PYPI_INDEX" ]
then
rm -r /root/.pip
rm -r /root/.pydistutils.cfg
rm -r /home/pi/.pip/pip.conf
rm -r /home/pi/.pydistutils.cfg
rm -r /home/"${BASE_USER}"/.pip/pip.conf
rm -r /home/"${BASE_USER}"/.pydistutils.cfg
fi

#reach device by name
Expand All @@ -29,3 +29,7 @@ fi

echo "$BASE_OVERRIDE_HOSTNAME" > /etc/hostname
sed -i -e "s@${FILE_HOST_NAME}@$BASE_OVERRIDE_HOSTNAME@g" /etc/hosts

#cleanup
apt-get clean
apt-get autoremove -y
33 changes: 28 additions & 5 deletions src/modules/base/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ export LC_ALL=C
source /common.sh
install_cleanup_trap

if [ "${BASE_DISTRO}" == "ubuntu" ]; then
unpack /filesystem/ubuntu /root root

mv /etc/resolv.conf /etc/resolv.conf.orig || true
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
echo "nameserver 1.1.1.1" >> /etc/resolv.conf

apt-get update
apt-get install -y net-tools wireless-tools dhcpcd5
if [ $( is_in_apt policykit-1 ) -eq 1 ]; then
apt-get -y install policykit-1
fi

# prevent any installed services from automatically starting
echo exit 101 > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
systemctl enable dhcpcd.service

#Undo prevent any installed services from automatically starting
rm -r /usr/sbin/policy-rc.d || true
fi

if [ -n "$BASE_APT_PROXY" ]
then
echo "Acquire::http { Proxy \"http://$BASE_APT_PROXY\"; };" > /etc/apt/apt.conf.d/02octopi_build_proxy
Expand All @@ -26,13 +49,13 @@ then
echo -e "$pip_index_config" > /root/.pip/pip.conf
echo -e "$easyinstall_index_config" > /root/.pydistutils.cfg

mkdir -p /home/pi/.pip
sudo -u pi echo -e "$pip_index_config" > /home/pi/.pip/pip.conf
sudo -u pi echo -e "$easyinstall_index_config" > /home/pi/.pydistutils.cfg
mkdir -p /home/"${BASE_USER}"/.pip
sudo -u "${BASE_USER}" echo -e "$pip_index_config" > /home/pi/.pip/pip.conf
sudo -u "${BASE_USER}" echo -e "$easyinstall_index_config" > /home/pi/.pydistutils.cfg

echo "Configured pypi index url $BASE_PYPI_INDEX"
cat /home/pi/.pip/pip.conf
cat /home/pi/.pydistutils.cfg
cat /home/"${BASE_USER}"/.pip/pip.conf
cat /home/"${BASE_USER}"/.pydistutils.cfg
fi

if [ "$BASE_SSH_ENABLE" == "yes" ]
Expand Down
5 changes: 5 additions & 0 deletions src/modules/network/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ DIST_NETWORK_FILE=/boot/${DIST_NAME,,}-wpa-supplicant.txt

# allow configuring multiple wifi networks via /boot/DIST_NAME-wpa-supplicant.txt
mv /boot/custompios-wpa-supplicant.txt ${DIST_NETWORK_FILE}
touch /etc/wpa_supplicant/wpa_supplicant.conf
cat /etc/wpa_supplicant/wpa_supplicant.conf >> ${DIST_NETWORK_FILE} # append distributed conf to our own
rm -f /etc/wpa_supplicant/wpa_supplicant.conf # remove distributed conf
ln -s ${DIST_NETWORK_FILE} /etc/wpa_supplicant/wpa_supplicant.conf # create symlink
Expand All @@ -26,6 +27,10 @@ ln -s ${DIST_NETWORK_FILE} /etc/wpa_supplicant/wpa_supplicant.conf # create sy
[ -f /etc/ifplugd/action.d/ifupdown ] && mv /etc/ifplugd/action.d/ifupdown /etc/ifplugd/action.d/ifupdown.original
[ -f /etc/wpa_supplicant/ifupdown.sh ] && ln -s /etc/wpa_supplicant/ifupdown.sh /etc/ifplugd/action.d/ifupdown

if [ ! -f "/etc/rc.local" ];then
echo 'exit 0' >> /etc/rc.local
fi

# prevent ntp updates from failing due to some Rpi3 weirdness, see also "Fix SSH" further below
sed -i 's@exit 0@@' /etc/rc.local
echo '/sbin/iptables -t mangle -I POSTROUTING 1 -o wlan0 -p udp --dport 123 -j TOS --set-tos 0x00' >> /etc/rc.local
Expand Down

0 comments on commit fb4b810

Please sign in to comment.