mirror of
https://github.com/hassio-addons/qemu-user-static.git
synced 2025-05-03 19:41:26 +00:00
🎉 Initial repository setup
This commit is contained in:
parent
d0990877e3
commit
768c9769f2
4 changed files with 176 additions and 0 deletions
94
.circleci/config.yml
Normal file
94
.circleci/config.yml
Normal file
|
@ -0,0 +1,94 @@
|
|||
version: 2
|
||||
|
||||
jobs:
|
||||
build:
|
||||
docker:
|
||||
- image: docker:17.10.0-ce-git
|
||||
environment:
|
||||
- VERSION: "2.10.1-1"
|
||||
- PACKAGE: "https://www.rpmfind.net/linux/fedora/linux/updates/27/x86_64/Packages/q/qemu-user-static-2.10.1-1.fc27.x86_64.rpm"
|
||||
- FILES: "qemu-arm-static qemu-aarch64-static"
|
||||
steps:
|
||||
- run:
|
||||
name: Build requirements
|
||||
command: apk add --no-cache rpm tar jq curl file
|
||||
- checkout
|
||||
- run:
|
||||
name: Download & unpack qemu-user-static
|
||||
command: |
|
||||
curl -sL -o /tmp/qemu-user-static.rpm "${PACKAGE}"
|
||||
(cd /tmp && rpm2cpio /tmp/qemu-user-static.rpm | cpio -dimv)
|
||||
for file in $FILES; do
|
||||
cp "/tmp/usr/bin/${file}" build/
|
||||
done
|
||||
- setup_remote_docker
|
||||
- run:
|
||||
name: Build docker container
|
||||
command: |
|
||||
docker build \
|
||||
--tag hassioaddons/qemu-user-static:test \
|
||||
--build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
|
||||
--build-arg BUILD_REF="${CIRCLE_SHA1}" \
|
||||
qemu-user-static
|
||||
- run:
|
||||
name: Tag resulting build image
|
||||
command: |
|
||||
if [ "${CIRCLE_BRANCH}" = "master" ] && [ ! -z "${CIRCLE_TAG:-}" ];
|
||||
then
|
||||
docker tag hassioaddons/qemu-user-static:test "hassioaddons/qemu-user-static:${CIRCLE_TAG:-}"
|
||||
docker tag hassioaddons/qemu-user-static:test hassioaddons/qemu-user-static:latest
|
||||
fi
|
||||
- run:
|
||||
name: Log in to Docker Hub
|
||||
command: |
|
||||
if [ "${CIRCLE_BRANCH}" = "master" ] || [ ! -z "${CIRCLE_TAG:-}" ];
|
||||
then
|
||||
docker login -u "${DOCKER_LOGIN}" -p "${DOCKER_PASSWORD}"
|
||||
fi
|
||||
- run:
|
||||
name: Push to Dockerhub
|
||||
command: |
|
||||
if [ "${CIRCLE_BRANCH}" = "master" ]; then
|
||||
docker push hassioaddons/qemu-user-static:test
|
||||
if [ ! -z "${CIRCLE_TAG:-}" ]; then
|
||||
docker push "hassioaddons/qemu-user-static:${CIRCLE_TAG:-}"
|
||||
docker push hassioaddons/qemu-user-static:latest
|
||||
fi
|
||||
fi
|
||||
- run:
|
||||
name: Pack & release binaries on GitHub
|
||||
command: |
|
||||
if [ "${CIRCLE_BRANCH}" = "master" ] || [ ! -z "${CIRCLE_TAG:-}" ];
|
||||
then
|
||||
cd build
|
||||
for file in $FILES; do
|
||||
tar -czf "${file}.tar.gz" "${file}";
|
||||
done
|
||||
release_id=$(set -x; curl -sL \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H "Cache-Control: no-cache" \
|
||||
"https://api.github.com/repos/hassio-addons/qemu-user-static/releases" \
|
||||
| jq -r --arg version "${VERSION}" '.[] | select(.tag_name == "v"+$version).id')
|
||||
if [ -z "$release_id" ]; then
|
||||
echo "Release on GitHub not found!"
|
||||
exit 1
|
||||
fi
|
||||
for file in $FILES; do
|
||||
content_type=$(file --mime-type -b "${file}")
|
||||
curl -sL \
|
||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H "Content-Type: ${content_type}" \
|
||||
--upload-file "${file}" \
|
||||
"https://uploads.github.com/repos/hassio-addons/qemu-user-static/releases/${release_id}/assets?name=${file}" \
|
||||
| jq
|
||||
content_type=$(file --mime-type -b "${file}.tar.gz")
|
||||
curl -sL \
|
||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H "Content-Type: ${content_type}" \
|
||||
--upload-file "${file}.tar.gz" \
|
||||
"https://uploads.github.com/repos/hassio-addons/qemu-user-static/releases/${release_id}/assets?name=${file}.tar.gz" \
|
||||
| jq
|
||||
done
|
||||
fi
|
0
build/.gitkeep
Normal file
0
build/.gitkeep
Normal file
23
qemu-user-static/Dockerfile
Normal file
23
qemu-user-static/Dockerfile
Normal file
|
@ -0,0 +1,23 @@
|
|||
FROM busybox
|
||||
|
||||
# Build arugments
|
||||
ARG BUILD_DATE
|
||||
ARG BUILD_REF
|
||||
|
||||
# Copy root filesystem
|
||||
COPY rootfs /
|
||||
|
||||
# Command
|
||||
CMD ["/usr/bin/register.sh"]
|
||||
|
||||
LABEL \
|
||||
maintainer="Franck Nijhof <frenck@addons.community>" \
|
||||
org.label-schema.description="Registers qemu-*-static for all Hass.io supported processors" \
|
||||
org.label-schema.build-date=${BUILD_DATE} \
|
||||
org.label-schema.name="qemu-user-static" \
|
||||
org.label-schema.schema-version="1.0" \
|
||||
org.label-schema.url="https://addons.community" \
|
||||
org.label-schema.usage="https://github.com/hassio-addons/qemu-user-static/tree/master/README.md" \
|
||||
org.label-schema.vcs-ref=${BUILD_REF} \
|
||||
org.label-schema.vcs-url="https://github.com/hassio-addons/qemu-user-static" \
|
||||
org.label-schema.vendor="Community Hass.io Add-ons"
|
59
qemu-user-static/rootfs/usr/bin/register.sh
Executable file
59
qemu-user-static/rootfs/usr/bin/register.sh
Executable file
|
@ -0,0 +1,59 @@
|
|||
#!/bin/sh
|
||||
# shellcheck disable=SC2034
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: qemu-user-static
|
||||
# Registers qemu-*-static for all Hass.io supported processors
|
||||
# ==============================================================================
|
||||
|
||||
# List of processors to target
|
||||
qemu_target_list="aarch64 arm"
|
||||
|
||||
# Magic!
|
||||
arm_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'
|
||||
arm_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
|
||||
arm_family=arm
|
||||
aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00'
|
||||
aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
|
||||
aarch64_family=arm
|
||||
|
||||
# Detect if binfmt support is loaded into the kernel
|
||||
if [ ! -d /proc/sys/fs/binfmt_misc ]; then
|
||||
echo "No binfmt support in the kernel."
|
||||
echo " Try: '/sbin/modprobe binfmt_misc' from the host"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Mount binfmt_misc
|
||||
if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then
|
||||
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
|
||||
fi
|
||||
|
||||
# Check if we can register
|
||||
if [ ! -w "/proc/sys/fs/binfmt_misc/register" ] ; then
|
||||
echo 'ERROR: Cannot write to /proc/sys/fs/binfmt_misc/register' 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Enable qemu for target CPU's
|
||||
for target in $qemu_target_list; do
|
||||
magic=$(eval echo "\$${target}_magic")
|
||||
mask=$(eval echo "\$${target}_mask")
|
||||
family=$(eval echo "\$${target}_family")
|
||||
|
||||
if [ "$magic" = "" ] || [ "$mask" = "" ] || [ "$family" = "" ] ; then
|
||||
echo "INTERNAL ERROR: unknown cpu $target" 1>&2
|
||||
continue
|
||||
fi
|
||||
|
||||
# Enable QEMU for this CPU
|
||||
if [ -f "/proc/sys/fs/binfmt_misc/qemu-${target}" ]; then
|
||||
# shellcheck disable=SC2039
|
||||
echo "-1" > "/proc/sys/fs/binfmt_misc/qemu-${target}"
|
||||
fi
|
||||
|
||||
# Register
|
||||
qemu="/usr/bin/qemu-${target}-static"
|
||||
echo "Setting ${qemu} as binfmt interpreter for ${target} (${family})"
|
||||
echo ":qemu-${target}:M::${magic}:${mask}:/usr/bin/qemu-${target}-static:" \
|
||||
> /proc/sys/fs/binfmt_misc/register
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue