diff --git a/.github/workflows/build-bootstrap.yaml b/.github/workflows/build-bootstrap.yaml new file mode 100644 index 0000000..f7f1d78 --- /dev/null +++ b/.github/workflows/build-bootstrap.yaml @@ -0,0 +1,45 @@ +name: Build bootstrap +on: [workflow_dispatch] +jobs: + build: + runs-on: ubuntu-latest + steps: + # - name: Fix permissions + # run: sudo chown -R $USER:$USER /home/runner/work/android-linux-bootstrap + - name: Checkout the code + uses: actions/checkout@v3 + with: + submodules: true + - name: Install Depends + run: android-linux-bootstrap/install.sh + - name: Build Alpine + run: | + cd android-linux-bootstrap/scripts + + ./alpine-bootstraps.sh + + - name: Alpine Linux Release + uses: marvinpinto/action-automatic-releases@latest + with: + repo_token: ${{ secrets.TOKEN_GITHUB }} + automatic_release_tag: "latest-alpine" + prerelease: false + title: "Alpine" + files: | + ./scripts/build/*.zip + + - name: Build Ubuntu + run: | + cd android-linux-bootstrap/scripts + ./ubuntu-bootstraps.sh + + - name: Ubuntu Linux Release + uses: marvinpinto/action-automatic-releases@latest + with: + repo_token: ${{ secrets.TOKEN_GITHUB }} + automatic_release_tag: "latest-ubuntu" + prerelease: false + title: "Ubuntu" + files: | + ./scripts/build/*.zip + \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..788d624 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*/build/ + +*.iso +*.tar.gz +alpine-shell/checkra1n +*.md + +external/proot/build +external/minitar/build diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cd79636 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "external/proot"] +path = external/proot +url = https://github.com/feelfreelinux/build-proot-android +[submodule "external/minitar"] +path = external/minitar +url = https://github.com/green-green-avk/build-libarchive-minitar-android diff --git a/alpine-shell/.gitignore b/alpine-shell/.gitignore new file mode 100644 index 0000000..5947342 --- /dev/null +++ b/alpine-shell/.gitignore @@ -0,0 +1,9 @@ + +iso/ +alpine_rootfs/ +*.iso + +*.gz + +build/ +checkra1n \ No newline at end of file diff --git a/alpine-shell/build.sh b/alpine-shell/build.sh new file mode 100755 index 0000000..435cc1d --- /dev/null +++ b/alpine-shell/build.sh @@ -0,0 +1,138 @@ +#!/bin/bash +# +# checkn1x build script +# https://asineth.me/checkn1x +# + +mkdir -p build +cd build + +export rootfs_folder=rootfs +export name_iso="custom-linux" +export alpine_version="3.19.0" + +mkdir -p $rootfs_folder + +mkdir -p iso/boot/grub + +rm -rf ./$name_iso.iso +rm -rf iso/boot/initramfs.xz + +if [ -d "$rootfs_folder/bin" ] +then + echo "Skip Extract Alpine Miniroot" +else + if [ -f "../alpine-minirootfs-$alpine_version-x86_64.tar.gz" ] + then + echo "Extract Alpien Miniroot" + tar -xzf ../alpine-minirootfs-$alpine_version-x86_64.tar.gz -C ./$rootfs_folder + else + echo "Download Alpine Root" + wget https://dl-cdn.alpinelinux.org/alpine/edge/releases/x86_64/alpine-minirootfs-$alpine_version-x86_64.tar.gz + echo "Extract Alpien Miniroot" + tar -xzf ../alpine-minirootfs-$alpine_version-x86_64.tar.gz -C ./$rootfs_folder + fi +fi + + +umount -v $rootfs_folder/dev >/dev/null 2>&1 +umount -v $rootfs_folder/sys >/dev/null 2>&1 +umount -v $rootfs_folder/proc >/dev/null 2>&1 + + +mount -vo bind /dev $rootfs_folder/dev +mount -vt sysfs sysfs $rootfs_folder/sys +mount -vt proc proc $rootfs_folder/proc + +echo "nameserver 8.8.8.8 \n\ +nameserver 8.8.4.4" > $rootfs_folder/etc/resolv.conf + +echo "Add Repo" +cat << ! > $rootfs_folder/etc/apk/repositories +https://dl-cdn.alpinelinux.org/alpine/v3.19/main +https://dl-cdn.alpinelinux.org/alpine/v3.19/community +https://dl-cdn.alpinelinux.org/alpine/edge/testing +! + +echo "Add Install Package Core" +cat << ! | chroot $rootfs_folder /usr/bin/env PATH=/usr/bin:/bin:/usr/sbin:/sbin /bin/sh +apk update +apk upgrade +apk add alpine-base ncurses-terminfo-base udev usbmuxd libusbmuxd-progs openssh-client sshpass usbutils +apk add --no-scripts linux-lts linux-firmware-none +rc-update add bootmisc +rc-update add hwdrivers +rc-update add udev +rc-update add udev-trigger +rc-update add udev-settle +! + + +# # kernel modules +# cat << ! > $rootfs_folder/etc/mkinitfs/features.d/azkadev.modules +# kernel/drivers/usb/host +# kernel/drivers/hid/usbhid +# kernel/drivers/hid/hid-generic.ko +# kernel/drivers/hid/hid-cherry.ko +# kernel/drivers/hid/hid-apple.ko +# kernel/net/ipv4 +# ! + +# chroot $rootfs_folder /usr/bin/env PATH=/usr/bin:/bin:/usr/sbin:/sbin \ +# /sbin/mkinitfs -F "azkadev" -k -t /tmp -q $(ls $rootfs_folder/lib/modules) + +# rm -rfv $rootfs_folder/lib/modules +# mv -v $rootfs_folder/tmp/lib/modules $rootfs_folder/lib +# find $rootfs_folder/lib/modules/* -type f -name "*.ko" | xargs -n1 -P`nproc` -- strip -v --strip-unneeded +# find $rootfs_folder/lib/modules/* -type f -name "*.ko" | xargs -n1 -P`nproc` -- xz --x86 -v9eT0 +# sudo depmod -b $rootfs_folder $(ls $rootfs_folder/lib/modules) + + +echo "Umount" +umount -v $rootfs_folder/dev >/dev/null 2>&1 +umount -v $rootfs_folder/sys >/dev/null 2>&1 +umount -v $rootfs_folder/proc >/dev/null 2>&1 + + +# kernel modules +cat << ! > $rootfs_folder/etc/inittab +# /etc/inittab +::sysinit:/sbin/openrc sysinit +::wait:/sbin/openrc default +tty1::respawn:/bin/login -f root +tty2::respawn:/bin/login -f root +tty3::respawn:/bin/login -f root +tty4::respawn:/bin/login -f root +tty5::respawn:/bin/login -f root +::ctrlaltdel:/sbin/reboot -f +# Stuff to do before rebooting +::shutdown:/sbin/openrc shutdown +! + + +ln -sv sbin/init $rootfs_folder/init +ln -sv ../../etc/terminfo $rootfs_folder/usr/share/terminfo # fix ncurses + +cp -av $rootfs_folder/boot/vmlinuz-lts iso/boot/vmlinuz +cat << ! > iso/boot/grub/grub.cfg +insmod all_video +echo 'Custom Alpine Linux' +linux /boot/vmlinuz quiet loglevel=3 +initrd /boot/initramfs.xz +boot +! + +# initramfs +pushd $rootfs_folder +rm -rfv boot/* +rm -rfv tmp/* +rm -rfv var/cache/* +find . | cpio -oH newc | xz -C crc32 --x86 -vz9eT0 > ../iso/boot/initramfs.xz +popd + +# iso creation +grub-mkrescue -o "./$name_iso.iso" iso --compress=xz + +# sudo chroot alpine_rootfs /usr/bin/env PATH=/usr/bin:/bin:/usr/sbin:/sbin /bin/sh +echo "Test Script: sudo qemu-system-x86_64 -cpu host -smp cores=4 -enable-kvm -m 4G -cdrom build/$name_iso.iso" +qemu-system-x86_64 -cpu host -smp cores=4 -enable-kvm -m 4G -cdrom ./$name_iso.iso \ No newline at end of file diff --git a/alpine-shell/clean.sh b/alpine-shell/clean.sh new file mode 100755 index 0000000..c8e4f36 --- /dev/null +++ b/alpine-shell/clean.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# checkn1x build script +# https://asineth.me/checkn1x +# + +echo "Umount" +umount -v $rootfs_folder/dev >/dev/null 2>&1 +umount -v $rootfs_folder/sys >/dev/null 2>&1 +umount -v $rootfs_folder/proc >/dev/null 2>&1 + +rm -rf build \ No newline at end of file diff --git a/alpine-shell/icon_dark.png b/alpine-shell/icon_dark.png new file mode 100755 index 0000000..43c26f9 Binary files /dev/null and b/alpine-shell/icon_dark.png differ diff --git a/alpine-shell/icon_light.png b/alpine-shell/icon_light.png new file mode 100755 index 0000000..9565752 Binary files /dev/null and b/alpine-shell/icon_light.png differ diff --git a/android-linux-bootstrap/.gitignore b/android-linux-bootstrap/.gitignore new file mode 100644 index 0000000..8fb365c --- /dev/null +++ b/android-linux-bootstrap/.gitignore @@ -0,0 +1 @@ +scripts/build \ No newline at end of file diff --git a/android-linux-bootstrap/build.sh b/android-linux-bootstrap/build.sh new file mode 100755 index 0000000..286a3ce --- /dev/null +++ b/android-linux-bootstrap/build.sh @@ -0,0 +1,7 @@ +# /bin/sh + +cd scripts/ + + +./alpine-bootstraps.sh +./ubuntu-bootstraps.sh \ No newline at end of file diff --git a/android-linux-bootstrap/install.sh b/android-linux-bootstrap/install.sh new file mode 100755 index 0000000..c4da922 --- /dev/null +++ b/android-linux-bootstrap/install.sh @@ -0,0 +1,67 @@ +# /bin/sh +echo "started install Dependencies" + +export DEBIAN_FRONTEND=noninteractive + +export ANDROID_SDK="$HOME/Android/Sdk" +export ANDROID_SDK_ROOT="$HOME/Android/Sdk" +export ANDROID_HOME="$HOME/Android/Sdk" +export PATH="$ANDROID_HOME/cmdline-tools/latest/bin/:$PATH" +export PATH="$ANDROID_HOME/cmdline-tools/latest/:$PATH" +export PATH="$ANDROID_HOME/emulator/:$PATH" +export PATH="$ANDROID_HOME/platform-tools/:$PATH" +export PATH="$ANDROID_SDK:$PATH" +export PATH="$PATH:$HOME/development/flutter/bin" + +echo "export ANDROID_SDK=$HOME/Android/Sdk" >> ~/.bashrc +echo "export ANDROID_SDK_ROOT=$HOME/Android/Sdk" >> ~/.bashrc +echo "export ANDROID_HOME=$HOME/Android/Sdk" >> ~/.bashrc +echo "export PATH=$ANDROID_HOME/cmdline-tools/latest/bin/:$PATH" >> ~/.bashrc +echo "export PATH=$ANDROID_HOME/cmdline-tools/latest/:$PATH" >> ~/.bashrc +echo "export PATH=$ANDROID_HOME/emulator/:$PATH" >> ~/.bashrc +echo "export PATH=$ANDROID_HOME/platform-tools/:$PATH" >> ~/.bashrc +echo "export PATH=$ANDROID_SDK:$PATH" >> ~/.bashrc +echo "export PATH=$PATH:$HOME/development/flutter/bin" >> ~/.bashrc +mkdir "$HOME/development/" + +source ~/.bashrc + +sudo apt-get update + +sudo apt-get install -y --no-install-recommends \ + wget \ + curl \ + make \ + git \ + zlib1g-dev \ + libssl-dev \ + gperf \ + cmake \ + clang \ + libc++-dev \ + libc++abi-dev \ + php-cli \ + g++ \ + ninja-build \ + pkg-config \ + libgtk-3-dev \ + liblzma-dev \ + xz-utils \ + unzip \ + xvfb \ + openjdk-11-jdk + +mkdir -p $HOME/Android/Sdk/cmdline-tools +wget -q https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip -O /tmp/tools.zip +unzip -q /tmp/tools.zip -d $HOME/Android/Sdk/cmdline-tools +sudo cp -rf $HOME/Android/Sdk/cmdline-tools/cmdline-tools $HOME/Android/Sdk/cmdline-tools/latest +echo "export PATH=$PATH:$HOME/Android/Sdk/cmdline-tools/latest/bin" >> ~/.bashrc + +yes "y" | sdkmanager +yes "y" | sdkmanager --update +yes "y" | sdkmanager "platform-tools" +yes "y" | sdkmanager "platforms;android-30" +yes "y" | sdkmanager "patcher;v4" +yes "y" | sdkmanager "build-tools;30.0.2" +yes "y" | sdkmanager "ndk;21.3.6528147" +yes "y" | sdkmanager --licenses diff --git a/android-linux-bootstrap/scripts/add-user.sh b/android-linux-bootstrap/scripts/add-user.sh new file mode 100755 index 0000000..f889181 --- /dev/null +++ b/android-linux-bootstrap/scripts/add-user.sh @@ -0,0 +1,7 @@ +#!/system/bin/sh +# generate user files in the bootstrap + +mkdir -p bootstrap/home/$1 +echo "$1:x:$USER_ID:$USER_ID:guest:/home/$1:/bin/sh" >> bootstrap/etc/passwd +echo "$1 ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$1 +chmod 0440 /etc/sudoers.d/$1 \ No newline at end of file diff --git a/android-linux-bootstrap/scripts/alpine-bootstraps.sh b/android-linux-bootstrap/scripts/alpine-bootstraps.sh new file mode 100755 index 0000000..49eba48 --- /dev/null +++ b/android-linux-bootstrap/scripts/alpine-bootstraps.sh @@ -0,0 +1,84 @@ +#!/bin/bash +set -e + +echo "Creating bootstrap for all archs" +# get the current path of the script +SCRIPTS_PATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$SCRIPTS_PATH" +echo "Building proot..." +cd ../../external/proot/ + +./build.sh + +echo "Building minitar..." +cd ../minitar +./build.sh + +cd $SCRIPTS_PATH +mkdir -p build +cd build +rm -rf * +cp ../ioctlHook.c . +../build-ioctl-hook.sh + +cp -r ../../../external/proot/build/* . + +build_bootstrap () { + echo "Packing bootstrap for arch $1" + + case $1 in + aarch64) + PROOT_ARCH="aarch64" + ANDROID_ARCH="arm64-v8a" + MUSL_ARCH="aarch64-linux-musl" + ;; + armhf) + PROOT_ARCH="armv7a" + ANDROID_ARCH="armeabi-v7a" + MUSL_ARCH="arm-linux-musleabihf" + ;; + x86_64) + PROOT_ARCH="x86_64" + ANDROID_ARCH="x86_64" + MUSL_ARCH="x86_64-linux-musl" + ;; + x86) + PROOT_ARCH="i686" + ANDROID_ARCH="x86" + MUSL_ARCH="i686-linux-musl" + ;; + *) + echo "Invalid arch" + ;; + esac + cd root-$PROOT_ARCH + cp ../../../../external/minitar/build/libs/$ANDROID_ARCH/minitar root/bin/minitar + + # separate binaries for platforms < android 5 not supporting 64bit + if [[ "$1" == "armhf" || "$1" == "i386" ]]; then + cp -r ../root-${PROOT_ARCH}-pre5/root root-pre5 + cp root/bin/minitar root-pre5/bin/minitar + fi + + + ALPINE_RELEASE="3.19" + ALPINE_VER="$ALPINE_RELEASE.1" + ALPINE_URL_DOWNLOAD="http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_RELEASE/releases/$1/alpine-minirootfs-$ALPINE_VER-$1.tar.gz" + echo "Downloading Alpine $ALPINE_RELEASE ($ALPINE_VER)" + echo "Downloading Alpine $ALPINE_URL_DOWNLOAD" + curl --fail -o rootfs.tar.xz -L $ALPINE_URL_DOWNLOAD + cp ../../run-bootstrap.sh . + cp ../../install-bootstrap.sh . + cp ../../fake_proc_stat . + cp ../../add-user.sh . + cp ../build-ioctl/ioctlHook-${MUSL_ARCH}.so ioctlHook.so + zip -r alpine-$PROOT_ARCH.zip root ioctlHook.so root-pre5 fake_proc_stat rootfs.tar.xz run-bootstrap.sh install-bootstrap.sh add-user.sh + mv alpine-$PROOT_ARCH.zip ../ + echo "Packed bootstrap $1" + cd .. +} + +build_bootstrap aarch64 +build_bootstrap armhf +build_bootstrap x86_64 +build_bootstrap x86 diff --git a/android-linux-bootstrap/scripts/build-ioctl-hook.sh b/android-linux-bootstrap/scripts/build-ioctl-hook.sh new file mode 100755 index 0000000..d3e91c0 --- /dev/null +++ b/android-linux-bootstrap/scripts/build-ioctl-hook.sh @@ -0,0 +1,25 @@ +#!/bin/bash +mkdir build-ioctl +cd build-ioctl + +echo "Building ioctl hook with musl cross platform toolchain" + +MUSL_AARCH64="aarch64-linux-musl" +MUSL_ARMV7="arm-linux-musleabihf" +MUSL_I686="i686-linux-musl" +MUSL_X86_64="x86_64-linux-musl" + +cross_compile() { + curl -O "https://musl.cc/$1-cross.tgz" + tar xzf "$1-cross.tgz" + GCC_PATH=./$1-cross/bin/$1-gcc + $GCC_PATH -fPIC -c -o ioctlHook.o ioctlHook.c + $GCC_PATH -shared -o ioctlHook-$1.so ioctlHook.o -ldl +} + +cp ../ioctlHook.c ioctlHook.c + +cross_compile $MUSL_AARCH64 +cross_compile $MUSL_I686 +cross_compile $MUSL_ARMV7 +cross_compile $MUSL_X86_64 diff --git a/android-linux-bootstrap/scripts/fake_proc_stat b/android-linux-bootstrap/scripts/fake_proc_stat new file mode 100644 index 0000000..b4abe9d --- /dev/null +++ b/android-linux-bootstrap/scripts/fake_proc_stat @@ -0,0 +1,10 @@ +cpu 528909 2279885 770423 16623705 25398 200416 48153 0 0 974 +cpu0 253914 1186503 381515 15533575 24381 151640 29523 0 0 612 +cpu1 274994 1093381 388908 1090129 1016 48775 18630 0 0 361 +intr 161467182 9 268723 0 0 0 0 0 0 1 40792 0 0 49954629 0 0 0 1530237 0 0 0 0 0 0 246 0 0 32645 925859 21 0 6678682 5105596 6341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +ctxt 329643364 +btime 1533904404 +processes 843869 +procs_running 4 +procs_blocked 0 +softirq 92008636 1036267 42271284 9342 1043544 756601 12 1122154 28147383 0 17622049 diff --git a/android-linux-bootstrap/scripts/generate-bootstraps.sh b/android-linux-bootstrap/scripts/generate-bootstraps.sh new file mode 100755 index 0000000..ce58a78 --- /dev/null +++ b/android-linux-bootstrap/scripts/generate-bootstraps.sh @@ -0,0 +1,82 @@ +#!/bin/bash +set -e + +echo "Creating bootstrap for all archs" +# get the current path of the script +SCRIPTS_PATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$SCRIPTS_PATH" +echo "Building proot..." +cd ../../external/proot/ + +./build.sh + +echo "Building minitar..." +cd ../minitar +./build.sh + +cd $SCRIPTS_PATH +mkdir -p build +cd build +rm -rf * +cp ../ioctlHook.c . +../build-ioctl-hook.sh + +cp -r ../../../external/proot/build/* . + +build_bootstrap () { + echo "Packing bootstrap for arch $1" + + case $1 in + aarch64) + PROOT_ARCH="aarch64" + ANDROID_ARCH="arm64-v8a" + MUSL_ARCH="aarch64-linux-musl" + ;; + armhf) + PROOT_ARCH="armv7a" + ANDROID_ARCH="armeabi-v7a" + MUSL_ARCH="arm-linux-musleabihf" + ;; + x86_64) + PROOT_ARCH="x86_64" + ANDROID_ARCH="x86_64" + MUSL_ARCH="x86_64-linux-musl" + ;; + x86) + PROOT_ARCH="i686" + ANDROID_ARCH="x86" + MUSL_ARCH="i686-linux-musl" + ;; + *) + echo "Invalid arch" + ;; + esac + cd root-$PROOT_ARCH + cp ../../../../external/minitar/build/libs/$ANDROID_ARCH/minitar root/bin/minitar + + # separate binaries for platforms < android 5 not supporting 64bit + if [[ "$1" == "armhf" || "$1" == "i386" ]]; then + cp -r ../root-${PROOT_ARCH}-pre5/root root-pre5 + cp root/bin/minitar root-pre5/bin/minitar + fi + + + ALPINE_RELEASE="3.19" + ALPINE_VER="$ALPINE_RELEASE.1" + echo "Downloading Alpine $ALPINE_RELEASE ($ALPINE_VER)" + curl --fail -o rootfs.tar.xz -L "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_RELEASE/releases/$1/alpine-minirootfs-$ALPINE_VER-$1.tar.gz" + cp ../../run-bootstrap.sh . + cp ../../install-bootstrap.sh . + cp ../../fake_proc_stat . + cp ../../add-user.sh . + cp ../build-ioctl/ioctlHook-${MUSL_ARCH}.so ioctlHook.so + zip -r bootstrap-$PROOT_ARCH.zip root ioctlHook.so root-pre5 fake_proc_stat rootfs.tar.xz run-bootstrap.sh install-bootstrap.sh add-user.sh + mv bootstrap-$PROOT_ARCH.zip ../ + echo "Packed bootstrap $1" + cd .. +} + +build_bootstrap aarch64 +build_bootstrap armhf +build_bootstrap x86_64 +build_bootstrap x86 diff --git a/android-linux-bootstrap/scripts/install-bootstrap.sh b/android-linux-bootstrap/scripts/install-bootstrap.sh new file mode 100755 index 0000000..6181808 --- /dev/null +++ b/android-linux-bootstrap/scripts/install-bootstrap.sh @@ -0,0 +1,15 @@ +#!/system/bin/sh + +chmod -R 777 ../ +chmod -R +rx ../ +# unpack alpine bootstrap +mkdir bootstrap +cd bootstrap +cat ../rootfs.tar.xz | ../root/bin/minitar +cd .. + +# include resolv.conf +echo "nameserver 8.8.8.8 \n \ +nameserver 8.8.4.4" > bootstrap/etc/resolv.conf + +echo "bootstrap ready, run with run-bootstrap.sh" diff --git a/android-linux-bootstrap/scripts/ioctlHook.c b/android-linux-bootstrap/scripts/ioctlHook.c new file mode 100644 index 0000000..12fd682 --- /dev/null +++ b/android-linux-bootstrap/scripts/ioctlHook.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +# + +int g_obvio=0; +#define DPRINTF(format, args...) if (!g_obvio) { g_obvio=1; fprintf(stderr, format, ## args); g_obvio=0; } + +#ifndef RTLD_NEXT +#define RTLD_NEXT ((void *)-1l) +#endif + +#define REAL_LIBC RTLD_NEXT +#define request_t int +#define TIOCMBIS 0x5416 + +static char fifoPath[] = "/home/octoprint/eventPipe"; +static char eventJsonStart[] = "{\"eventType\": \""; +static char eventJsonEnd[] = "\"}\n"; + + +int writeEventToPipe(char* event, int len) { + int eventFifoFd = open(fifoPath, O_WRONLY); + write(eventFifoFd, eventJsonStart, sizeof(eventJsonStart)-1); + write(eventFifoFd, event, len); + write(eventFifoFd, eventJsonEnd, sizeof(eventJsonEnd)-1); + close(eventFifoFd); +} + +int ioctl(int fd, int request, ...) +{ + static int (*funcIoctl)(int, request_t, void *) = NULL; + va_list args; + void *argp; + + if (!funcIoctl) + funcIoctl = (int (*)(int, request_t, void *))dlsym(REAL_LIBC, "ioctl"); + va_start(args, request); + argp = va_arg(args, void *); + va_end(args); + + if (request == TIOCMBIS) + { + writeEventToPipe("rtsDts", 6); + return 0; + } + + if (request == 0x802c542a || request == 0x402C542B) + { + writeEventToPipe("customBaud", 10); + return 0; + } + //DPRINTF ("HOOK: ioctl (fd=%d, request=%p, argp=%p [%02X])\n", fd, request, argp); + return funcIoctl(fd, request, argp); +} + +int flock(int fd, int operation) { + // DPRINTF ("HOOK: flock (fd=%d, operation=%p)\n", fd, operation); + return 0; +} diff --git a/android-linux-bootstrap/scripts/run-bootstrap.sh b/android-linux-bootstrap/scripts/run-bootstrap.sh new file mode 100755 index 0000000..9565385 --- /dev/null +++ b/android-linux-bootstrap/scripts/run-bootstrap.sh @@ -0,0 +1,36 @@ +#!/system/bin/sh +# Minimal proot run script + +if [ -z "$1" ] || [ -z "$2" ]; then + echo "Usage: " + exit 1 +fi + +BASE_DIR="$PWD" + +export PROOT_TMP_DIR="$BASE_DIR/tmp" +export PROOT_L2S_DIR="$BASE_DIR/bootstrap/.proot.meta" + +mkdir -p "$PROOT_TMP_DIR" +mkdir -p "$PROOT_L2S_DIR" + +if [ "$1" = "root" ]; then + PATH='/sbin:/usr/sbin:/bin:/usr/bin' + USER='root' + HOME='/root' + OP="-0" +else + OP="" + USER="$1" + PATH='/sbin:/usr/sbin:/bin:/usr/bin' + HOME="/home/$USER" +fi + + +unset TMPDIR +unset LD_LIBRARY_PATH +export PATH +export USER +export HOME +shift +./root/bin/proot -r bootstrap $OP -b /dev -b /proc -b /sys -b /system -b /vendor -b /storage -b ${PWD}/fake_proc_stat:/proc/stat $EXTRA_BIND --link2symlink -p -L -w $HOME "$@" diff --git a/android-linux-bootstrap/scripts/ubuntu-bootstraps.sh b/android-linux-bootstrap/scripts/ubuntu-bootstraps.sh new file mode 100755 index 0000000..3cd7378 --- /dev/null +++ b/android-linux-bootstrap/scripts/ubuntu-bootstraps.sh @@ -0,0 +1,81 @@ +#!/bin/bash +set -e + +echo "Creating bootstrap for all archs" +# get the current path of the script +SCRIPTS_PATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$SCRIPTS_PATH" +echo "Building proot..." +cd ../../external/proot/ + +./build.sh + +echo "Building minitar..." +cd ../minitar +./build.sh + +cd $SCRIPTS_PATH +mkdir -p build +cd build +rm -rf * +cp ../ioctlHook.c . +../build-ioctl-hook.sh + +cp -r ../../../external/proot/build/* . + +build_bootstrap () { + echo "Packing bootstrap for arch $1" + + case $1 in + aarch64) + PROOT_ARCH="aarch64" + ANDROID_ARCH="arm64-v8a" + MUSL_ARCH="aarch64-linux-musl" + ;; + armhf) + PROOT_ARCH="armv7a" + ANDROID_ARCH="armeabi-v7a" + MUSL_ARCH="arm-linux-musleabihf" + ;; + x86_64) + PROOT_ARCH="x86_64" + ANDROID_ARCH="x86_64" + MUSL_ARCH="x86_64-linux-musl" + ;; + x86) + PROOT_ARCH="i686" + ANDROID_ARCH="x86" + MUSL_ARCH="i686-linux-musl" + ;; + *) + echo "Invalid arch" + ;; + esac + cd root-$PROOT_ARCH + cp ../../../../external/minitar/build/libs/$ANDROID_ARCH/minitar root/bin/minitar + + # separate binaries for platforms < android 5 not supporting 64bit + if [[ "$1" == "armhf" || "$1" == "i386" ]]; then + cp -r ../root-${PROOT_ARCH}-pre5/root root-pre5 + cp root/bin/minitar root-pre5/bin/minitar + fi + + + UBUNTU_RELEASE="23.10" + echo "Downloading UBUNTU $UBUNTU_RELEASE" + curl --fail -o rootfs.tar.xz -L "https://cdimage.ubuntu.com/ubuntu-base/releases/$UBUNTU_RELEASE/release/ubuntu-base-$UBUNTU_RELEASE-base-arm64.tar.gz" + cp ../../run-bootstrap.sh . + cp ../../install-bootstrap.sh . + cp ../../fake_proc_stat . + cp ../../add-user.sh . + cp ../build-ioctl/ioctlHook-${MUSL_ARCH}.so ioctlHook.so + zip -r ubuntu-$PROOT_ARCH.zip root ioctlHook.so root-pre5 fake_proc_stat rootfs.tar.xz run-bootstrap.sh install-bootstrap.sh add-user.sh + mv ubuntu-$PROOT_ARCH.zip ../ + echo "Packed bootstrap $1" + cd .. +} + +build_bootstrap aarch64 +# build_bootstrap armhf +# build_bootstrap x86_64 +# build_bootstrap x86 diff --git a/external/minitar/.gitignore b/external/minitar/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/external/minitar/.gitignore @@ -0,0 +1 @@ +/build diff --git a/external/minitar/Android.mk b/external/minitar/Android.mk new file mode 100644 index 0000000..4b097a9 --- /dev/null +++ b/external/minitar/Android.mk @@ -0,0 +1,203 @@ +# +# Copyright (C) 2014 Trevor Drake +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + + +# A bit of a non-standard LOCAL_PATH declaration here +# The Android.mk lives below the top source directory +# but LOCAL_PATH needs to point to the top of the module +# source tree to maintain the integrity of the intermediates +# directories +LOCAL_PATH := $(TARGET_SRC_DIR) + + +libarchive_target_config := $(realpath $(call my-dir))/android-min.h + +libarchive_src_files := libarchive/archive_acl.c \ + libarchive/archive_blake2s_ref.c \ + libarchive/archive_blake2sp_ref.c \ + libarchive/archive_check_magic.c \ + libarchive/archive_cmdline.c \ + libarchive/archive_cryptor.c \ + libarchive/archive_digest.c \ + libarchive/archive_entry.c \ + libarchive/archive_entry_copy_stat.c \ + libarchive/archive_entry_link_resolver.c \ + libarchive/archive_entry_sparse.c \ + libarchive/archive_entry_stat.c \ + libarchive/archive_entry_strmode.c \ + libarchive/archive_entry_xattr.c \ + libarchive/archive_getdate.c \ + libarchive/archive_hmac.c \ + libarchive/archive_match.c \ + libarchive/archive_options.c \ + libarchive/archive_pack_dev.c \ + libarchive/archive_pathmatch.c \ + libarchive/archive_ppmd8.c \ + libarchive/archive_ppmd7.c \ + libarchive/archive_random.c \ + libarchive/archive_rb.c \ + libarchive/archive_read.c \ + libarchive/archive_read_add_passphrase.c \ + libarchive/archive_read_append_filter.c \ + libarchive/archive_read_data_into_fd.c \ + libarchive/archive_read_disk_entry_from_file.c \ + libarchive/archive_read_disk_posix.c \ + libarchive/archive_read_disk_set_standard_lookup.c \ + libarchive/archive_read_extract.c \ + libarchive/archive_read_extract2.c \ + libarchive/archive_read_open_fd.c \ + libarchive/archive_read_open_file.c \ + libarchive/archive_read_open_filename.c \ + libarchive/archive_read_open_memory.c \ + libarchive/archive_read_set_format.c \ + libarchive/archive_read_set_options.c \ + libarchive/archive_read_support_filter_all.c \ + libarchive/archive_read_support_filter_bzip2.c \ + libarchive/archive_read_support_filter_by_code.c \ + libarchive/archive_read_support_filter_compress.c \ + libarchive/archive_read_support_filter_gzip.c \ + libarchive/archive_read_support_filter_grzip.c \ + libarchive/archive_read_support_filter_lrzip.c \ + libarchive/archive_read_support_filter_lz4.c \ + libarchive/archive_read_support_filter_lzop.c \ + libarchive/archive_read_support_filter_none.c \ + libarchive/archive_read_support_filter_program.c \ + libarchive/archive_read_support_filter_rpm.c \ + libarchive/archive_read_support_filter_uu.c \ + libarchive/archive_read_support_filter_xz.c \ + libarchive/archive_read_support_filter_zstd.c \ + libarchive/archive_read_support_format_7zip.c \ + libarchive/archive_read_support_format_all.c \ + libarchive/archive_read_support_format_ar.c \ + libarchive/archive_read_support_format_by_code.c \ + libarchive/archive_read_support_format_cab.c \ + libarchive/archive_read_support_format_cpio.c \ + libarchive/archive_read_support_format_empty.c \ + libarchive/archive_read_support_format_iso9660.c \ + libarchive/archive_read_support_format_lha.c \ + libarchive/archive_read_support_format_mtree.c \ + libarchive/archive_read_support_format_rar.c \ + libarchive/archive_read_support_format_rar5.c \ + libarchive/archive_read_support_format_raw.c \ + libarchive/archive_read_support_format_tar.c \ + libarchive/archive_read_support_format_warc.c \ + libarchive/archive_read_support_format_xar.c \ + libarchive/archive_read_support_format_zip.c \ + libarchive/archive_string.c \ + libarchive/archive_string_sprintf.c \ + libarchive/archive_util.c \ + libarchive/archive_version_details.c \ + libarchive/archive_virtual.c \ + libarchive/archive_write.c \ + libarchive/archive_write_disk_posix.c \ + libarchive/archive_write_disk_set_standard_lookup.c \ + libarchive/archive_write_open_fd.c \ + libarchive/archive_write_open_file.c \ + libarchive/archive_write_open_filename.c \ + libarchive/archive_write_open_memory.c \ + libarchive/archive_write_add_filter.c \ + libarchive/archive_write_add_filter_b64encode.c \ + libarchive/archive_write_add_filter_by_name.c \ + libarchive/archive_write_add_filter_bzip2.c \ + libarchive/archive_write_add_filter_compress.c \ + libarchive/archive_write_add_filter_grzip.c \ + libarchive/archive_write_add_filter_gzip.c \ + libarchive/archive_write_add_filter_lrzip.c \ + libarchive/archive_write_add_filter_lz4.c \ + libarchive/archive_write_add_filter_lzop.c \ + libarchive/archive_write_add_filter_none.c \ + libarchive/archive_write_add_filter_program.c \ + libarchive/archive_write_add_filter_uuencode.c \ + libarchive/archive_write_add_filter_xz.c \ + libarchive/archive_write_add_filter_zstd.c \ + libarchive/archive_write_set_format.c \ + libarchive/archive_write_set_format_7zip.c \ + libarchive/archive_write_set_format_ar.c \ + libarchive/archive_write_set_format_by_name.c \ + libarchive/archive_write_set_format_cpio.c \ + libarchive/archive_write_set_format_cpio_newc.c \ + libarchive/archive_write_set_format_filter_by_ext.c \ + libarchive/archive_write_set_format_gnutar.c \ + libarchive/archive_write_set_format_iso9660.c \ + libarchive/archive_write_set_format_mtree.c \ + libarchive/archive_write_set_format_pax.c \ + libarchive/archive_write_set_format_raw.c \ + libarchive/archive_write_set_format_shar.c \ + libarchive/archive_write_set_format_ustar.c \ + libarchive/archive_write_set_format_v7tar.c \ + libarchive/archive_write_set_format_warc.c \ + libarchive/archive_write_set_format_xar.c \ + libarchive/archive_write_set_format_zip.c \ + libarchive/archive_write_set_options.c \ + libarchive/archive_write_set_passphrase.c \ + libarchive/filter_fork_posix.c \ + libarchive/xxhash.c + +libarchive_fe_src_files := libarchive_fe/err.c \ + libarchive_fe/line_reader.c \ + libarchive_fe/passphrase.c + + +minitar_src_files := ../../minitar/minitar.c + + +minitar_config := $(call my-dir)/minitar-config.h + + +include $(CLEAR_VARS) +LOCAL_MODULE := libbz2 +LOCAL_SRC_FILES := $(realpath $(TARGET_SRC_DIR)/../../bzip2/build/obj/local/$(TARGET_ARCH_ABI)/libbz2.a) +LOCAL_EXPORT_C_INCLUDES := $(realpath $(TARGET_SRC_DIR)/../../bzip2/build/include) +include $(PREBUILT_STATIC_LIBRARY) + + +include $(CLEAR_VARS) +LOCAL_MODULE := liblzma +LOCAL_SRC_FILES := $(realpath $(TARGET_SRC_DIR)/../../lzma/build/obj/local/$(TARGET_ARCH_ABI)/liblzma.a) +LOCAL_EXPORT_C_INCLUDES := $(realpath $(TARGET_SRC_DIR)/../../lzma/build/include) +include $(PREBUILT_STATIC_LIBRARY) + + +include $(CLEAR_VARS) +LOCAL_MODULE := libarchive +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := $(libarchive_src_files) +LOCAL_CFLAGS := -DPLATFORM_CONFIG_H=\"$(libarchive_target_config)\" +LOCAL_C_INCLUDES := $(LOCAL_PATH)/contrib/android/include +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/libarchive +LOCAL_STATIC_LIBRARIES := libbz2 liblzma +include $(BUILD_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libarchive_fe +LOCAL_MODULE_TAGS := optional +LOCAL_CFLAGS := -DPLATFORM_CONFIG_H=\"$(libarchive_target_config)\" +LOCAL_SRC_FILES := $(libarchive_fe_src_files) +LOCAL_C_INCLUDES := $(LOCAL_PATH)/contrib/android/include +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/libarchive_fe +include $(BUILD_STATIC_LIBRARY) + + +include $(CLEAR_VARS) +LOCAL_MODULE := minitar +LOCAL_MODULE_TAGS := optional +LOCAL_CFLAGS := -DBSDTAR_VERSION_STRING=ARCHIVE_VERSION_ONLY_STRING -DPLATFORM_CONFIG_H=\"$(libarchive_target_config)\" -include $(minitar_config) +LOCAL_LDLIBS := -lz +LOCAL_STATIC_LIBRARIES := libarchive libarchive_fe libbz2 liblzma +LOCAL_SRC_FILES := $(minitar_src_files) +LOCAL_C_INCLUDES := $(LOCAL_PATH)/libarchive $(LOCAL_PATH)/libarchive_fe $(LOCAL_PATH)/contrib/android/include +include $(BUILD_EXECUTABLE) diff --git a/external/minitar/App-all.mk b/external/minitar/App-all.mk new file mode 100644 index 0000000..affb94f --- /dev/null +++ b/external/minitar/App-all.mk @@ -0,0 +1,3 @@ +APP_ABI := all +APP_PLATFORM := android-14 +APP_BUILD_SCRIPT := ./Android.mk diff --git a/external/minitar/LICENSE b/external/minitar/LICENSE new file mode 100644 index 0000000..9b05694 --- /dev/null +++ b/external/minitar/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 green-green-avk + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/external/minitar/android-min.h b/external/minitar/android-min.h new file mode 100644 index 0000000..992ddb3 --- /dev/null +++ b/external/minitar/android-min.h @@ -0,0 +1,194 @@ +/*- + * Copyright (c) 2014 Trevor Drake + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ARCHIVE_PLATFORM_H_ANDROID_INCLUDED +#define ARCHIVE_PLATFORM_H_ANDROID_INCLUDED + +#include +#ifdef __ANDROID_API__ +#if __ANDROID_API__ > 20 +#define HAVE_FSTATVFS 1 +#define HAVE_STATVFS 1 +#define HAVE_TIMEGM 1 +#define HAVE_SYS_XATTR_H 1 +#define HAVE_LINUX_FIEMAP_H 1 +#define HAVE_SYS_STATVFS_H 1 +#endif +#endif + +#define HAVE_CHOWN 1 +#define HAVE_CHROOT 1 +#define HAVE_CTIME_R 1 +#define HAVE_CTYPE_H 1 +#define HAVE_DECL_EXTATTR_NAMESPACE_USER 0 +#define HAVE_DECL_INTMAX_MIN 1 +#define HAVE_DECL_INTMAX_MAX 1 +#define HAVE_DECL_INT64_MAX 1 +#define HAVE_DECL_INT64_MIN 1 +#define HAVE_DECL_SIZE_MAX 1 +#define HAVE_DECL_SSIZE_MAX 1 +#define HAVE_DECL_STRERROR_R 1 +#define HAVE_DECL_UINTMAX_MAX 1 +#define HAVE_DECL_UINT32_MAX 1 +#define HAVE_DECL_UINT64_MAX 1 +#define HAVE_DECL_INT32_MIN 1 +#define HAVE_DECL_INT32_MAX 1 +#define HAVE_DIRENT_H 1 +#define HAVE_DIRFD 1 +#define HAVE_DLFCN_H 1 +#define HAVE_EILSEQ 1 +#define HAVE_ERRNO_H 1 +#define HAVE_FCHDIR 1 +#define HAVE_FCHMOD 1 +#define HAVE_FCHOWN 1 +#define HAVE_FCNTL 1 +#define HAVE_FCNTL_H 1 +#define HAVE_FDOPENDIR 1 +#define HAVE_FGETXATTR 1 +#define HAVE_FLISTXATTR 1 +#define HAVE_FORK 1 +#define HAVE_FSEEKO 1 +#define HAVE_FSETXATTR 1 +#define HAVE_FSTAT 1 +#define HAVE_FSTATAT 1 +#define HAVE_FSTATFS 1 +#define HAVE_FTRUNCATE 1 +#define HAVE_GETEUID 1 +#define HAVE_GETPID 1 +#define HAVE_GETPWNAM_R 1 +#define HAVE_GETPWUID_R 1 +#define HAVE_GETXATTR 1 +#define HAVE_GMTIME_R 1 +#define HAVE_GRP_H 1 +#define HAVE_INTMAX_T 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_LCHOWN 1 +#define HAVE_LGETXATTR 1 +#define HAVE_LIBLZMA 1 +#define HAVE_LIBZ 1 +#define HAVE_LIMITS_H 1 +#define HAVE_LINK 1 +#define HAVE_LINUX_FS_H 1 +#define HAVE_LINUX_MAGIC_H 1 +#define HAVE_LINUX_TYPES_H 1 +#define HAVE_LISTXATTR 1 +#define HAVE_LLISTXATTR 1 +#define HAVE_LOCALE_H 1 +#define HAVE_LOCALTIME_R 1 +#define HAVE_LONG_LONG_INT 1 +#define HAVE_LSETXATTR 1 +#define HAVE_LSTAT 1 +#define HAVE_MBRTOWC 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMORY_H 1 +#define HAVE_MEMSET 1 +#define HAVE_MKDIR 1 +#define HAVE_MKFIFO 1 +#define HAVE_MKNOD 1 +#define HAVE_MKSTEMP 1 +#define HAVE_OPENAT 1 +#define HAVE_PATHS_H 1 +#define HAVE_PIPE 1 +#define HAVE_POLL 1 +#define HAVE_POLL_H 1 +#define HAVE_PTHREAD_H 1 +#define HAVE_PWD_H 1 +#define HAVE_READDIR_R 1 +#define HAVE_READLINK 1 +#define HAVE_READLINKAT 1 +#define HAVE_REGEX_H 1 +#define HAVE_SELECT 1 +#define HAVE_SETENV 1 +#define HAVE_SETLOCALE 1 +#define HAVE_SIGACTION 1 +#define HAVE_SIGNAL_H 1 +#define HAVE_STATFS 1 +#define HAVE_STDARG_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STRCHR 1 +#define HAVE_STRDUP 1 +#define HAVE_STRERROR 1 +#define HAVE_STRERROR_R 1 +#define HAVE_STRFTIME 1 +#define HAVE_STRINGS_H 1 +#define HAVE_STRING_H 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRUCT_STAT_ST_BLKSIZE 1 +#define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1 +#define HAVE_STRUCT_TM_TM_GMTOFF 1 +#define HAVE_SYMLINK 1 +#define HAVE_SYS_CDEFS_H 1 +#define HAVE_SYS_IOCTL_H 1 +#define HAVE_SYS_MOUNT_H 1 +#define HAVE_SYS_PARAM_H 1 +#define HAVE_SYS_POLL_H 1 +#define HAVE_SYS_SELECT_H 1 +#define HAVE_SYS_STATFS_H 1 +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TIME_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_UTSNAME_H 1 +#define HAVE_SYS_VFS_H 1 +#define HAVE_SYS_WAIT_H 1 +#define HAVE_TIME_H 1 +#define HAVE_TZSET 1 +#define HAVE_UINTMAX_T 1 +#define HAVE_UNISTD_H 1 +#define HAVE_UNLINKAT 1 +#define HAVE_UNSETENV 1 +#define HAVE_UNSIGNED_LONG_LONG 1 +#define HAVE_UNSIGNED_LONG_LONG_INT 1 +#define HAVE_UTIME 1 +#define HAVE_UTIMENSAT 1 +#define HAVE_UTIMES 1 +#define HAVE_UTIME_H 1 +#define HAVE_VFORK 1 +#define HAVE_VPRINTF 1 +#define HAVE_WCHAR_H 1 +#define HAVE_WCHAR_T 1 +#define HAVE_WCRTOMB 1 +#define HAVE_WCSCMP 1 +#define HAVE_WCSCPY 1 +#define HAVE_WCSLEN 1 +#define HAVE_WCTOMB 1 +#define HAVE_WCTYPE_H 1 +#define HAVE_WMEMCMP 1 +#define HAVE_WMEMCPY 1 +#define HAVE_ARC4RANDOM_BUF 1 +#define HAVE_ZLIB_H 1 +#define HAVE_BZLIB_H 1 +#define HAVE_LZMA_H 1 +#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1 +#define SIZEOF_WCHAR_T 4 +#define STDC_HEADERS 1 +#define STRERROR_R_CHAR_P 1 +#define TIME_WITH_SYS_TIME 1 + +#define IS_ANDROID_NOROOT + +#define __LIBARCHIVE_CONFIG_H_INCLUDED 1 + +#endif diff --git a/external/minitar/android.patch b/external/minitar/android.patch new file mode 100644 index 0000000..01107f9 --- /dev/null +++ b/external/minitar/android.patch @@ -0,0 +1,77 @@ +--- libarchive/archive_write_disk_posix.c ++++ libarchive/archive_write_disk_posix.c +@@ -2206,8 +2206,8 @@ restore_entry(struct archive_write_disk *a) + if (en) { + /* Everything failed; give up here. */ + if ((&a->archive)->error == NULL) +- archive_set_error(&a->archive, en, "Can't create '%s'", +- a->name); ++ archive_set_error(&a->archive, en, "Can't create '%s', errno = %d", ++ a->name, en); + return (ARCHIVE_FAILED); + } + +@@ -2237,13 +2237,13 @@ create_filesystem_object(struct archive_write_disk *a) + /* Since link(2) and symlink(2) don't handle modes, we're done here. */ + linkname = archive_entry_hardlink(a->entry); + if (linkname != NULL) { +-#if !HAVE_LINK ++#if !(HAVE_LINK || (defined(IS_ANDROID_NOROOT) && HAVE_SYMLINK)) + return (EPERM); + #else + archive_string_init(&error_string); + linkname_copy = strdup(linkname); + if (linkname_copy == NULL) { +- return (EPERM); ++ return (ENOMEM); + } + /* + * TODO: consider using the cleaned-up path as the link +@@ -2284,7 +2284,34 @@ create_filesystem_object(struct archive_write_disk *a) + */ + if (a->flags & ARCHIVE_EXTRACT_SAFE_WRITES) + unlink(a->name); ++#ifndef IS_ANDROID_NOROOT + r = link(linkname, a->name) ? errno : 0; ++ if (r != 0) ++ archive_set_error(&a->archive, ARCHIVE_FAILED, "Can't create hard link '%s', errno = %d", ++ a->name, r); ++#else /* IS_ANDROID_NOROOT */ ++/* ++ * Nonrooted Android can't do hard links! ++ * Just pretend they are symlinks. ++ * Let's treat the archive root as a chroot root for now. ++ * TODO: Fix this temporary solution later. ++ */ ++ if (linkname[0] != '/') { ++ if (linkname[0] == '.' && linkname[1] == '/') { ++ r = symlink(linkname + 1, a->name) ? errno : 0; ++ } else { ++ char _linkname[strlen(linkname) + 2]; ++ _linkname[0] = '/'; ++ strcpy(_linkname + 1, linkname); ++ r = symlink(_linkname, a->name) ? errno : 0; ++ } ++ } else { ++ r = symlink(linkname, a->name) ? errno : 0; ++ } ++ if (r != 0) ++ archive_set_error(&a->archive, ARCHIVE_FAILED, "Can't create a symlink substitution of the hardlink '%s', errno = %d", ++ a->name, r); ++#endif /* IS_ANDROID_NOROOT */ + /* + * New cpio and pax formats allow hardlink entries + * to carry data, so we may have to open the file +@@ -2329,7 +2356,11 @@ create_filesystem_object(struct archive_write_disk *a) + */ + if (a->flags & ARCHIVE_EXTRACT_SAFE_WRITES) + unlink(a->name); +- return symlink(linkname, a->name) ? errno : 0; ++ r = symlink(linkname, a->name) ? errno : 0; ++ if (r != 0) ++ archive_set_error(&a->archive, ARCHIVE_FAILED, "Can't create symlink '%s', errno = %d", ++ a->name, r); ++ return (r); + #else + return (EPERM); + #endif diff --git a/external/minitar/build.sh b/external/minitar/build.sh new file mode 100755 index 0000000..a110b0a --- /dev/null +++ b/external/minitar/build.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +set -e + +[ "$1" = '-u' ] && UPDATE=1 + +BUILD_DIR='build' +VER='3.5.1' +NAME="libarchive-$VER" + +export PATH="$HOME/Android/Sdk/ndk/21.3.6528147:$PATH" + +if [ -z "$UPDATE" ] ; then + +( cd bzip2 && ./build.sh ) +( cd lzma && ./build.sh ) + +mkdir -p "$BUILD_DIR" +( +cd "$BUILD_DIR" +wget -O - "https://www.libarchive.org/downloads/$NAME.tar.gz" | tar -xz +) + +fi + +export TARGET_SRC_DIR="$(realpath -s "$BUILD_DIR/$NAME")" + +if [ -z "$UPDATE" ] ; then + +patch -i "$(realpath -s android.patch)" -p0 -d "$TARGET_SRC_DIR" + +fi + +export NDK_PROJECT_PATH="$BUILD_DIR" +ndk-build NDK_APPLICATION_MK=./App-all.mk + +mkdir -p 'prebuilt' +cp -a "$BUILD_DIR/libs/"* 'prebuilt' diff --git a/external/minitar/bzip2/.gitignore b/external/minitar/bzip2/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/external/minitar/bzip2/.gitignore @@ -0,0 +1 @@ +/build diff --git a/external/minitar/bzip2/Android.mk b/external/minitar/bzip2/Android.mk new file mode 100644 index 0000000..3a7962f --- /dev/null +++ b/external/minitar/bzip2/Android.mk @@ -0,0 +1,20 @@ +LOCAL_PATH := $(TARGET_SRC_DIR) + +BIGFILES := -D_FILE_OFFSET_BITS=64 +libbz2_cflags := -Wall -Winline -O2 -g $(BIGFILES) + +libbz2_src_files := \ + blocksort.c \ + huffman.c \ + crctable.c \ + randtable.c \ + compress.c \ + decompress.c \ + bzlib.c + +include $(CLEAR_VARS) +LOCAL_MODULE := libbz2 +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := $(libbz2_src_files) +LOCAL_CFLAGS := $(libbz2_cflags) +include $(BUILD_STATIC_LIBRARY) diff --git a/external/minitar/bzip2/App-all.mk b/external/minitar/bzip2/App-all.mk new file mode 100644 index 0000000..affb94f --- /dev/null +++ b/external/minitar/bzip2/App-all.mk @@ -0,0 +1,3 @@ +APP_ABI := all +APP_PLATFORM := android-14 +APP_BUILD_SCRIPT := ./Android.mk diff --git a/external/minitar/bzip2/build.sh b/external/minitar/bzip2/build.sh new file mode 100755 index 0000000..e5ca7e9 --- /dev/null +++ b/external/minitar/bzip2/build.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +BUILD_DIR='build' +VER='1.0.8' +NAME="bzip2-$VER" + +mkdir -p "$BUILD_DIR" +( +cd "$BUILD_DIR" +wget -O - "https://sourceware.org/pub/bzip2/$NAME.tar.gz" | tar -xz +) + +export TARGET_SRC_DIR="$(realpath -s "$BUILD_DIR/$NAME")" + +export NDK_PROJECT_PATH="$BUILD_DIR" +ndk-build NDK_APPLICATION_MK=./App-all.mk + +mkdir -p "$BUILD_DIR/include" +cp -a "$TARGET_SRC_DIR"/bzlib.h "$BUILD_DIR/include" diff --git a/external/minitar/lzma/.gitignore b/external/minitar/lzma/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/external/minitar/lzma/.gitignore @@ -0,0 +1 @@ +/build diff --git a/external/minitar/lzma/Android.mk b/external/minitar/lzma/Android.mk new file mode 100644 index 0000000..308ad91 --- /dev/null +++ b/external/minitar/lzma/Android.mk @@ -0,0 +1,109 @@ +LOCAL_PATH := $(TARGET_SRC_DIR) + + +target_config := $(realpath $(call my-dir))/android-min.h + +#BIGFILES := -D_FILE_OFFSET_BITS=64 +#liblzma_cflags := -Wall -Winline -O2 -g $(BIGFILES) +liblzma_th_src_files := \ + src/liblzma/common/hardware_cputhreads.c \ + src/liblzma/common/outqueue.c \ + src/liblzma/common/stream_encoder_mt.c + +# src/liblzma/check/crc64_table.c \ +# src/liblzma/check/crc32_table.c \ +# src/liblzma/check/crc32_fast.c \ +# src/liblzma/check/crc64_fast.c \ + +# src/liblzma/check/crc64_tablegen.c \ +# src/liblzma/check/crc32_tablegen.c \ + +# src/liblzma/lzma/fastpos_table.c \ + +# src/liblzma/lzma/fastpos_tablegen.c \ + +# src/liblzma/rangecoder/price_tablegen.c \ + +liblzma_src_files := \ + src/liblzma/rangecoder/price_table.c \ + src/liblzma/lz/lz_decoder.c \ + src/liblzma/lz/lz_encoder_mf.c \ + src/liblzma/lz/lz_encoder.c \ + src/liblzma/common/common.c \ + src/liblzma/common/easy_preset.c \ + src/liblzma/common/stream_buffer_decoder.c \ + src/liblzma/common/hardware_physmem.c \ + src/liblzma/common/index.c \ + src/liblzma/common/block_buffer_decoder.c \ + src/liblzma/common/index_hash.c \ + src/liblzma/common/vli_size.c \ + src/liblzma/common/block_header_decoder.c \ + src/liblzma/common/easy_decoder_memusage.c \ + src/liblzma/common/stream_flags_encoder.c \ + src/liblzma/common/block_buffer_encoder.c \ + src/liblzma/common/filter_buffer_decoder.c \ + src/liblzma/common/stream_flags_common.c \ + src/liblzma/common/index_decoder.c \ + src/liblzma/common/index_encoder.c \ + src/liblzma/common/easy_encoder_memusage.c \ + src/liblzma/common/stream_encoder.c \ + src/liblzma/common/stream_buffer_encoder.c \ + src/liblzma/common/alone_decoder.c \ + src/liblzma/common/easy_encoder.c \ + src/liblzma/common/block_util.c \ + src/liblzma/common/stream_decoder.c \ + src/liblzma/common/auto_decoder.c \ + src/liblzma/common/block_encoder.c \ + src/liblzma/common/filter_common.c \ + src/liblzma/common/filter_flags_encoder.c \ + src/liblzma/common/filter_buffer_encoder.c \ + src/liblzma/common/alone_encoder.c \ + src/liblzma/common/filter_decoder.c \ + src/liblzma/common/stream_flags_decoder.c \ + src/liblzma/common/filter_encoder.c \ + src/liblzma/common/vli_decoder.c \ + src/liblzma/common/filter_flags_decoder.c \ + src/liblzma/common/block_header_encoder.c \ + src/liblzma/common/easy_buffer_encoder.c \ + src/liblzma/common/vli_encoder.c \ + src/liblzma/common/block_decoder.c \ + src/liblzma/lzma/lzma_encoder.c \ + src/liblzma/lzma/lzma_encoder_optimum_fast.c \ + src/liblzma/lzma/lzma_decoder.c \ + src/liblzma/lzma/lzma2_encoder.c \ + src/liblzma/lzma/lzma_encoder_presets.c \ + src/liblzma/lzma/lzma2_decoder.c \ + src/liblzma/lzma/lzma_encoder_optimum_normal.c \ + src/liblzma/check/sha256.c \ + src/liblzma/check/check.c \ + src/liblzma/check/crc32_small.c \ + src/liblzma/check/crc64_small.c \ + src/liblzma/simple/simple_coder.c \ + src/liblzma/simple/armthumb.c \ + src/liblzma/simple/ia64.c \ + src/liblzma/simple/arm.c \ + src/liblzma/simple/x86.c \ + src/liblzma/simple/sparc.c \ + src/liblzma/simple/powerpc.c \ + src/liblzma/simple/simple_encoder.c \ + src/liblzma/simple/simple_decoder.c \ + src/liblzma/delta/delta_common.c \ + src/liblzma/delta/delta_encoder.c \ + src/liblzma/delta/delta_decoder.c + +include $(CLEAR_VARS) +LOCAL_MODULE := liblzma +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := $(liblzma_src_files) +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/src/liblzma/api \ + $(LOCAL_PATH)/src/liblzma/common \ + $(LOCAL_PATH)/src/liblzma/check \ + $(LOCAL_PATH)/src/liblzma/lzma \ + $(LOCAL_PATH)/src/liblzma/lz \ + $(LOCAL_PATH)/src/liblzma/simple \ + $(LOCAL_PATH)/src/liblzma/delta \ + $(LOCAL_PATH)/src/liblzma/rangecoder \ + $(LOCAL_PATH)/src/common +LOCAL_CFLAGS := -include $(target_config) +include $(BUILD_STATIC_LIBRARY) diff --git a/external/minitar/lzma/App-all.mk b/external/minitar/lzma/App-all.mk new file mode 100644 index 0000000..affb94f --- /dev/null +++ b/external/minitar/lzma/App-all.mk @@ -0,0 +1,3 @@ +APP_ABI := all +APP_PLATFORM := android-14 +APP_BUILD_SCRIPT := ./Android.mk diff --git a/external/minitar/lzma/android-min.h b/external/minitar/lzma/android-min.h new file mode 100644 index 0000000..ed82c70 --- /dev/null +++ b/external/minitar/lzma/android-min.h @@ -0,0 +1,220 @@ +/*- + * Copyright (c) 2014 Trevor Drake + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ARCHIVE_PLATFORM_H_ANDROID_INCLUDED +#define ARCHIVE_PLATFORM_H_ANDROID_INCLUDED + +#include +#ifdef __ANDROID_API__ +#if __ANDROID_API__ > 20 +#define HAVE_FSTATVFS 1 +#define HAVE_STATVFS 1 +#define HAVE_TIMEGM 1 +#define HAVE_SYS_XATTR_H 1 +#define HAVE_LINUX_FIEMAP_H 1 +#define HAVE_SYS_STATVFS_H 1 +#endif +#endif + +#define HAVE_CHOWN 1 +#define HAVE_CHROOT 1 +#define HAVE_CTIME_R 1 +#define HAVE_CTYPE_H 1 +#define HAVE_DECL_EXTATTR_NAMESPACE_USER 0 +#define HAVE_DECL_INTMAX_MIN 1 +#define HAVE_DECL_INTMAX_MAX 1 +#define HAVE_DECL_INT64_MAX 1 +#define HAVE_DECL_INT64_MIN 1 +#define HAVE_DECL_SIZE_MAX 1 +#define HAVE_DECL_SSIZE_MAX 1 +#define HAVE_DECL_STRERROR_R 1 +#define HAVE_DECL_UINTMAX_MAX 1 +#define HAVE_DECL_UINT32_MAX 1 +#define HAVE_DECL_UINT64_MAX 1 +#define HAVE_DECL_INT32_MIN 1 +#define HAVE_DECL_INT32_MAX 1 +#define HAVE_DIRENT_H 1 +#define HAVE_DIRFD 1 +#define HAVE_DLFCN_H 1 +#define HAVE_EILSEQ 1 +#define HAVE_ERRNO_H 1 +#define HAVE_FCHDIR 1 +#define HAVE_FCHMOD 1 +#define HAVE_FCHOWN 1 +#define HAVE_FCNTL 1 +#define HAVE_FCNTL_H 1 +#define HAVE_FDOPENDIR 1 +#define HAVE_FGETXATTR 1 +#define HAVE_FLISTXATTR 1 +#define HAVE_FORK 1 +#define HAVE_FSEEKO 1 +#define HAVE_FSETXATTR 1 +#define HAVE_FSTAT 1 +#define HAVE_FSTATAT 1 +#define HAVE_FSTATFS 1 +#define HAVE_FTRUNCATE 1 +#define HAVE_GETEUID 1 +#define HAVE_GETPID 1 +#define HAVE_GETPWNAM_R 1 +#define HAVE_GETPWUID_R 1 +#define HAVE_GETXATTR 1 +#define HAVE_GMTIME_R 1 +#define HAVE_GRP_H 1 +#define HAVE_INTMAX_T 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_LCHOWN 1 +#define HAVE_LGETXATTR 1 +#define HAVE_LIBLZMA 1 +#define HAVE_LIBZ 1 +#define HAVE_LIMITS_H 1 +#define HAVE_LINK 1 +#define HAVE_LINUX_FS_H 1 +#define HAVE_LINUX_MAGIC_H 1 +#define HAVE_LINUX_TYPES_H 1 +#define HAVE_LISTXATTR 1 +#define HAVE_LLISTXATTR 1 +#define HAVE_LOCALE_H 1 +#define HAVE_LOCALTIME_R 1 +#define HAVE_LONG_LONG_INT 1 +#define HAVE_LSETXATTR 1 +#define HAVE_LSTAT 1 +#define HAVE_MBRTOWC 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMORY_H 1 +#define HAVE_MEMSET 1 +#define HAVE_MKDIR 1 +#define HAVE_MKFIFO 1 +#define HAVE_MKNOD 1 +#define HAVE_MKSTEMP 1 +#define HAVE_OPENAT 1 +#define HAVE_PATHS_H 1 +#define HAVE_PIPE 1 +#define HAVE_POLL 1 +#define HAVE_POLL_H 1 +#define HAVE_PTHREAD_H 1 +#define HAVE_PWD_H 1 +#define HAVE_READDIR_R 1 +#define HAVE_READLINK 1 +#define HAVE_READLINKAT 1 +#define HAVE_REGEX_H 1 +#define HAVE_SELECT 1 +#define HAVE_SETENV 1 +#define HAVE_SETLOCALE 1 +#define HAVE_SIGACTION 1 +#define HAVE_SIGNAL_H 1 +#define HAVE_STATFS 1 +#define HAVE_STDARG_H 1 +#define HAVE_STDBOOL_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STRCHR 1 +#define HAVE_STRDUP 1 +#define HAVE_STRERROR 1 +#define HAVE_STRERROR_R 1 +#define HAVE_STRFTIME 1 +#define HAVE_STRINGS_H 1 +#define HAVE_STRING_H 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRUCT_STAT_ST_BLKSIZE 1 +#define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1 +#define HAVE_STRUCT_TM_TM_GMTOFF 1 +#define HAVE_SYMLINK 1 +#define HAVE_SYS_CDEFS_H 1 +#define HAVE_SYS_IOCTL_H 1 +#define HAVE_SYS_MOUNT_H 1 +#define HAVE_SYS_PARAM_H 1 +#define HAVE_SYS_POLL_H 1 +#define HAVE_SYS_SELECT_H 1 +#define HAVE_SYS_STATFS_H 1 +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TIME_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_UTSNAME_H 1 +#define HAVE_SYS_VFS_H 1 +#define HAVE_SYS_WAIT_H 1 +#define HAVE_TIME_H 1 +#define HAVE_TZSET 1 +#define HAVE_UINTMAX_T 1 +#define HAVE_UNISTD_H 1 +#define HAVE_UNSETENV 1 +#define HAVE_UNSIGNED_LONG_LONG 1 +#define HAVE_UNSIGNED_LONG_LONG_INT 1 +#define HAVE_UTIME 1 +#define HAVE_UTIMENSAT 1 +#define HAVE_UTIMES 1 +#define HAVE_UTIME_H 1 +#define HAVE_VFORK 1 +#define HAVE_VPRINTF 1 +#define HAVE_WCHAR_H 1 +#define HAVE_WCHAR_T 1 +#define HAVE_WCRTOMB 1 +#define HAVE_WCSCMP 1 +#define HAVE_WCSCPY 1 +#define HAVE_WCSLEN 1 +#define HAVE_WCTOMB 1 +#define HAVE_WCTYPE_H 1 +#define HAVE_WMEMCMP 1 +#define HAVE_WMEMCPY 1 +#define HAVE_ARC4RANDOM_BUF 1 +#define HAVE_ZLIB_H 1 +#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1 +#define SIZEOF_WCHAR_T 4 +#define STDC_HEADERS 1 +#define STRERROR_R_CHAR_P 1 +#define TIME_WITH_SYS_TIME 1 + +#define HAVE_SMALL + +/* Define to 1 if any of HAVE_DECODER_foo have been defined. */ +#define HAVE_DECODERS + +/* Define to 1 if arm decoder is enabled. */ +#define HAVE_DECODER_ARM + +/* Define to 1 if armthumb decoder is enabled. */ +#define HAVE_DECODER_ARMTHUMB + +/* Define to 1 if delta decoder is enabled. */ +#define HAVE_DECODER_DELTA + +/* Define to 1 if ia64 decoder is enabled. */ +#define HAVE_DECODER_IA64 + +/* Define to 1 if lzma1 decoder is enabled. */ +#define HAVE_DECODER_LZMA1 + +/* Define to 1 if lzma2 decoder is enabled. */ +#define HAVE_DECODER_LZMA2 + +/* Define to 1 if powerpc decoder is enabled. */ +#define HAVE_DECODER_POWERPC + +/* Define to 1 if sparc decoder is enabled. */ +#define HAVE_DECODER_SPARC + +/* Define to 1 if x86 decoder is enabled. */ +#define HAVE_DECODER_X86 + +#endif diff --git a/external/minitar/lzma/build.sh b/external/minitar/lzma/build.sh new file mode 100755 index 0000000..ce75d31 --- /dev/null +++ b/external/minitar/lzma/build.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +BUILD_DIR='build' +VER='5.2.4' +NAME="xz-$VER" + +mkdir -p "$BUILD_DIR" +( +cd "$BUILD_DIR" +wget -O - "https://tukaani.org/xz/$NAME.tar.xz" | tar -xJ +) + +export TARGET_SRC_DIR="$(realpath -s "$BUILD_DIR/$NAME")" + +export NDK_PROJECT_PATH="$BUILD_DIR" +ndk-build NDK_APPLICATION_MK=./App-all.mk + +mkdir -p "$BUILD_DIR/include" +cp -a "$TARGET_SRC_DIR"/src/liblzma/api/lzma* "$BUILD_DIR/include" diff --git a/external/minitar/minitar-config.h b/external/minitar/minitar-config.h new file mode 100644 index 0000000..3ba331b --- /dev/null +++ b/external/minitar/minitar-config.h @@ -0,0 +1,23 @@ +/* + * NO_XZ - Implies NO_XZ_CREATE and NO_XZ_EXTRACT + * NO_XZ_CREATE - Suppress xz compression support. + * NO_XZ_EXTRACT - Suppress xz auto-detection and decompression. + * NO_BZIP2 - Implies NO_BZIP2_CREATE and NO_BZIP2_EXTRACT + * NO_BZIP2_CREATE - Suppress bzip2 compression support. + * NO_BZIP2_EXTRACT - Suppress bzip2 auto-detection and decompression. + * NO_COMPRESS - Implies NO_COMPRESS_CREATE and NO_COMPRESS_EXTRACT + * NO_COMPRESS_CREATE - Suppress compress(1) compression support + * NO_COMPRESS_EXTRACT - Suppress compress(1) auto-detect and decompression. + * NO_CREATE - Suppress all archive creation support. + * NO_CPIO_EXTRACT - Suppress auto-detect and dearchiving of cpio archives. + * NO_GZIP - Implies NO_GZIP_CREATE and NO_GZIP_EXTRACT + * NO_GZIP_CREATE - Suppress gzip compression support. + * NO_GZIP_EXTRACT - Suppress gzip auto-detection and decompression. + * NO_LOOKUP - Try to avoid getpw/getgr routines, which can be very large + * NO_TAR_EXTRACT - Suppress tar extraction + */ + +#define NO_COMPRESS +#define NO_CREATE +#define NO_CPIO_EXTRACT +#define NO_LOOKUP diff --git a/external/minitar/minitar/COPYING b/external/minitar/minitar/COPYING new file mode 100644 index 0000000..14bbefa --- /dev/null +++ b/external/minitar/minitar/COPYING @@ -0,0 +1,66 @@ +The libarchive distribution as a whole is Copyright by Tim Kientzle +and is subject to the copyright notice reproduced at the bottom of +this file. + +Each individual file in this distribution should have a clear +copyright/licensing statement at the beginning of the file. If any do +not, please let me know and I will rectify it. The following is +intended to summarize the copyright status of the individual files; +the actual statements in the files are controlling. + +* Except as listed below, all C sources (including .c and .h files) + and documentation files are subject to the copyright notice reproduced + at the bottom of this file. + +* The following source files are also subject in whole or in part to + a 3-clause UC Regents copyright; please read the individual source + files for details: + libarchive/archive_entry.c + libarchive/archive_read_support_filter_compress.c + libarchive/archive_write_add_filter_compress.c + libarchive/mtree.5 + +* The following source files are in the public domain: + libarchive/archive_getdate.c + +* The following source files are triple-licensed with the ability to choose + from CC0 1.0 Universal, OpenSSL or Apache 2.0 licenses: + libarchive/archive_blake2.h + libarchive/archive_blake2_impl.h + libarchive/archive_blake2s_ref.c + libarchive/archive_blake2sp_ref.c + +* The build files---including Makefiles, configure scripts, + and auxiliary scripts used as part of the compile process---have + widely varying licensing terms. Please check individual files before + distributing them to see if those restrictions apply to you. + +I intend for all new source code to use the license below and hope over +time to replace code with other licenses with new implementations that +do use the license below. The varying licensing of the build scripts +seems to be an unavoidable mess. + + +Copyright (c) 2003-2018 +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer + in this position and unchanged. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/external/minitar/minitar/README b/external/minitar/minitar/README new file mode 100644 index 0000000..4580793 --- /dev/null +++ b/external/minitar/minitar/README @@ -0,0 +1,16 @@ +Sorry, xz has been added. + +======= + +"minitar" is a minimal example of a program that uses libarchive to +read/write various archive formats. It's a more ambitious version of +'untar.c' that includes compile-time options to enable/disable various +features, including non-tar formats, archive creation, and automatic +decompression support. + +I use this as a test bed to check for "link pollution," ensuring that +a program using libarchive does not pull in unnecessary code. + +The "minitar" program is also a good starting point for anyone who +wants to use libarchive for their own purposes, as it demonstrates +basic usage of the library. diff --git a/external/minitar/minitar/minitar.c b/external/minitar/minitar/minitar.c new file mode 100644 index 0000000..2c176ed --- /dev/null +++ b/external/minitar/minitar/minitar.c @@ -0,0 +1,519 @@ +/*- + * This file is in the public domain. + * Do with it as you will. + */ + +/*- + * This is a compact "tar" program whose primary goal is small size. + * Statically linked, it can be very small indeed. This serves a number + * of goals: + * o a testbed for libarchive (to check for link pollution), + * o a useful tool for space-constrained systems (boot floppies, etc), + * o a place to experiment with new implementation ideas for bsdtar, + * o a small program to demonstrate libarchive usage. + * + * Use the following macros to suppress features: + * NO_XZ - Implies NO_XZ_CREATE and NO_XZ_EXTRACT + * NO_XZ_CREATE - Suppress xz compression support. + * NO_XZ_EXTRACT - Suppress xz auto-detection and decompression. + * NO_BZIP2 - Implies NO_BZIP2_CREATE and NO_BZIP2_EXTRACT + * NO_BZIP2_CREATE - Suppress bzip2 compression support. + * NO_BZIP2_EXTRACT - Suppress bzip2 auto-detection and decompression. + * NO_COMPRESS - Implies NO_COMPRESS_CREATE and NO_COMPRESS_EXTRACT + * NO_COMPRESS_CREATE - Suppress compress(1) compression support + * NO_COMPRESS_EXTRACT - Suppress compress(1) auto-detect and decompression. + * NO_CREATE - Suppress all archive creation support. + * NO_CPIO_EXTRACT - Suppress auto-detect and dearchiving of cpio archives. + * NO_GZIP - Implies NO_GZIP_CREATE and NO_GZIP_EXTRACT + * NO_GZIP_CREATE - Suppress gzip compression support. + * NO_GZIP_EXTRACT - Suppress gzip auto-detection and decompression. + * NO_LOOKUP - Try to avoid getpw/getgr routines, which can be very large + * NO_TAR_EXTRACT - Suppress tar extraction + * + * With all of the above macros defined (except NO_TAR_EXTRACT), you + * get a very small program that can recognize and extract essentially + * any uncompressed tar archive. On FreeBSD 5.1, this minimal program + * is under 64k, statically linked, which compares rather favorably to + * main(){printf("hello, world");} + * which is over 60k statically linked on the same operating system. + * Without any of the above macros, you get a static executable of + * about 180k with a lot of very sophisticated modern features. + * Obviously, it's trivial to add support for ISO, Zip, mtree, + * lzma/xz, etc. Just fill in the appropriate setup calls. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/* + * NO_CREATE implies NO_XZ_CREATE and implies NO_BZIP2_CREATE and NO_GZIP_CREATE and NO_COMPRESS_CREATE. + */ +#ifdef NO_CREATE +#undef NO_XZ_CREATE +#define NO_XZ_CREATE +#undef NO_BZIP2_CREATE +#define NO_BZIP2_CREATE +#undef NO_COMPRESS_CREATE +#define NO_COMPRESS_CREATE +#undef NO_GZIP_CREATE +#define NO_GZIP_CREATE +#endif + +/* + * The combination of NO_XZ_CREATE and NO_XZ_EXTRACT is + * equivalent to NO_XZ. + */ +#ifdef NO_XZ_CREATE +#ifdef NO_XZ_EXTRACT +#undef NO_XZ +#define NO_XZ +#endif +#endif + +#ifdef NO_XZ +#undef NO_XZ_EXTRACT +#define NO_XZ_EXTRACT +#undef NO_XZ_CREATE +#define NO_XZ_CREATE +#endif + +/* + * The combination of NO_BZIP2_CREATE and NO_BZIP2_EXTRACT is + * equivalent to NO_BZIP2. + */ +#ifdef NO_BZIP2_CREATE +#ifdef NO_BZIP2_EXTRACT +#undef NO_BZIP2 +#define NO_BZIP2 +#endif +#endif + +#ifdef NO_BZIP2 +#undef NO_BZIP2_EXTRACT +#define NO_BZIP2_EXTRACT +#undef NO_BZIP2_CREATE +#define NO_BZIP2_CREATE +#endif + +/* + * The combination of NO_COMPRESS_CREATE and NO_COMPRESS_EXTRACT is + * equivalent to NO_COMPRESS. + */ +#ifdef NO_COMPRESS_CREATE +#ifdef NO_COMPRESS_EXTRACT +#undef NO_COMPRESS +#define NO_COMPRESS +#endif +#endif + +#ifdef NO_COMPRESS +#undef NO_COMPRESS_EXTRACT +#define NO_COMPRESS_EXTRACT +#undef NO_COMPRESS_CREATE +#define NO_COMPRESS_CREATE +#endif + +/* + * The combination of NO_GZIP_CREATE and NO_GZIP_EXTRACT is + * equivalent to NO_GZIP. + */ +#ifdef NO_GZIP_CREATE +#ifdef NO_GZIP_EXTRACT +#undef NO_GZIP +#define NO_GZIP +#endif +#endif + +#ifdef NO_GZIP +#undef NO_GZIP_EXTRACT +#define NO_GZIP_EXTRACT +#undef NO_GZIP_CREATE +#define NO_GZIP_CREATE +#endif + +#ifndef NO_CREATE +static void create(const char *filename, int compress, const char **argv); +#endif +static void errmsg(const char *); +static void extract(const char *filename, int do_extract, int flags); +static int copy_data(struct archive *, struct archive *); +static void msg(const char *); +static void usage(void); + +static int verbose = 0; + +int +main(int argc, const char **argv) +{ + const char *filename = NULL; + int compress, flags, mode, opt; + + (void)argc; + mode = 'x'; + verbose = 0; + compress = '\0'; + flags = ARCHIVE_EXTRACT_TIME; + + /* Among other sins, getopt(3) pulls in printf(3). */ + while (*++argv != NULL && **argv == '-') { + const char *p = *argv + 1; + + while ((opt = *p++) != '\0') { + switch (opt) { +#ifndef NO_CREATE + case 'c': + mode = opt; + break; +#endif + case 'f': + if (*p != '\0') + filename = p; + else + filename = *++argv; + p += strlen(p); + break; +#ifndef NO_XZ_CREATE + case 'J': + compress = opt; + break; +#endif +#ifndef NO_BZIP2_CREATE + case 'j': + compress = opt; + break; +#endif + case 'p': + flags |= ARCHIVE_EXTRACT_PERM; + flags |= ARCHIVE_EXTRACT_ACL; + flags |= ARCHIVE_EXTRACT_FFLAGS; + break; + case 't': + mode = opt; + break; + case 'v': + verbose++; + break; + case 'x': + mode = opt; + break; +#ifndef NO_BZIP2_CREATE + case 'y': + compress = opt; + break; +#endif +#ifndef NO_COMPRESS_CREATE + case 'Z': + compress = opt; + break; +#endif +#ifndef NO_GZIP_CREATE + case 'z': + compress = opt; + break; +#endif + default: + usage(); + } + } + } + + switch (mode) { +#ifndef NO_CREATE + case 'c': + create(filename, compress, argv); + break; +#endif + case 't': + extract(filename, 0, flags); + break; + case 'x': + extract(filename, 1, flags); + break; + } + + return (0); +} + + +#ifndef NO_CREATE +static char buff[16384]; + +static void +create(const char *filename, int compress, const char **argv) +{ + struct archive *a; + struct archive_entry *entry; + ssize_t len; + int fd; + + a = archive_write_new(); + switch (compress) { +#ifndef NO_XZ_CREATE + case 'J': + archive_write_add_filter_xz(a); + break; +#endif +#ifndef NO_BZIP2_CREATE + case 'j': case 'y': + archive_write_add_filter_bzip2(a); + break; +#endif +#ifndef NO_COMPRESS_CREATE + case 'Z': + archive_write_add_filter_compress(a); + break; +#endif +#ifndef NO_GZIP_CREATE + case 'z': + archive_write_add_filter_gzip(a); + break; +#endif + default: + archive_write_add_filter_none(a); + break; + } + archive_write_set_format_ustar(a); + if (filename != NULL && strcmp(filename, "-") == 0) + filename = NULL; + archive_write_open_filename(a, filename); + + while (*argv != NULL) { + struct archive *disk = archive_read_disk_new(); +#ifndef NO_LOOKUP + archive_read_disk_set_standard_lookup(disk); +#endif + int r; + + r = archive_read_disk_open(disk, *argv); + if (r != ARCHIVE_OK) { + errmsg("archive_read_disk_open(): "); + errmsg(archive_error_string(disk)); + errmsg("\n"); + exit(1); + } + + for (;;) { + int needcr = 0; + + entry = archive_entry_new(); + r = archive_read_next_header2(disk, entry); + if (r == ARCHIVE_EOF) + break; + if (r != ARCHIVE_OK) { + errmsg(archive_error_string(disk)); + errmsg("\n"); + exit(1); + } + archive_read_disk_descend(disk); + if (verbose) { + msg("a "); + msg(archive_entry_pathname(entry)); + needcr = 1; + } + r = archive_write_header(a, entry); + if (r < ARCHIVE_OK) { + errmsg(": "); + errmsg(archive_error_string(a)); + needcr = 1; + } + if (r == ARCHIVE_FATAL) + exit(1); + if (r > ARCHIVE_FAILED) { +#if 0 + /* Ideally, we would be able to use + * the same code to copy a body from + * an archive_read_disk to an + * archive_write that we use for + * copying data from an archive_read + * to an archive_write_disk. + * Unfortunately, this doesn't quite + * work yet. */ + copy_data(disk, a); +#else + /* For now, we use a simpler loop to copy data + * into the target archive. */ + fd = open(archive_entry_sourcepath(entry), O_RDONLY); + len = read(fd, buff, sizeof(buff)); + while (len > 0) { + archive_write_data(a, buff, len); + len = read(fd, buff, sizeof(buff)); + } + close(fd); +#endif + } + archive_entry_free(entry); + if (needcr) + msg("\n"); + } + archive_read_close(disk); + archive_read_free(disk); + argv++; + } + archive_write_close(a); + archive_write_free(a); +} +#endif + +static void +extract(const char *filename, int do_extract, int flags) +{ + struct archive *a; + struct archive *ext; + struct archive_entry *entry; + int r; + + a = archive_read_new(); + ext = archive_write_disk_new(); + archive_write_disk_set_options(ext, flags); +#ifndef NO_XZ_EXTRACT + archive_read_support_filter_xz(a); +#endif +#ifndef NO_BZIP2_EXTRACT + archive_read_support_filter_bzip2(a); +#endif +#ifndef NO_GZIP_EXTRACT + archive_read_support_filter_gzip(a); +#endif +#ifndef NO_COMPRESS_EXTRACT + archive_read_support_filter_compress(a); +#endif +#ifndef NO_TAR_EXTRACT + archive_read_support_format_tar(a); +#endif +#ifndef NO_CPIO_EXTRACT + archive_read_support_format_cpio(a); +#endif +#ifndef NO_LOOKUP + archive_write_disk_set_standard_lookup(ext); +#endif + if (filename != NULL && strcmp(filename, "-") == 0) + filename = NULL; + if ((r = archive_read_open_filename(a, filename, 10240))) { + errmsg(archive_error_string(a)); + errmsg("\n"); + exit(r); + } + for (;;) { + int needcr = 0; + r = archive_read_next_header(a, &entry); + if (r == ARCHIVE_EOF) + break; + if (r != ARCHIVE_OK) { + errmsg(archive_error_string(a)); + errmsg("\n"); + exit(1); + } + if (verbose && do_extract) + msg("x "); + if (verbose || !do_extract) { + msg(archive_entry_pathname(entry)); + msg(" "); + needcr = 1; + } + if (do_extract) { + r = archive_write_header(ext, entry); + if (r != ARCHIVE_OK) { + char ens[16]; + errmsg(": "); + sprintf(ens, "%d", r); + errmsg(ens); + errmsg(": "); + sprintf(ens, "%d", archive_errno(ext)); + errmsg(ens); + errmsg(": "); + errmsg(archive_error_string(ext)); + needcr = 1; + } + else { + r = copy_data(a, ext); + if (r != ARCHIVE_OK) + needcr = 1; + } + } + if (needcr) + msg("\n"); + } + archive_read_close(a); + archive_read_free(a); + + archive_write_close(ext); + archive_write_free(ext); + exit(0); +} + +static int +copy_data(struct archive *ar, struct archive *aw) +{ + int r; + const void *buff; + size_t size; + int64_t offset; + + for (;;) { + r = archive_read_data_block(ar, &buff, &size, &offset); + if (r == ARCHIVE_EOF) + return (ARCHIVE_OK); + if (r != ARCHIVE_OK) { + errmsg(archive_error_string(ar)); + return (r); + } + r = archive_write_data_block(aw, buff, size, offset); + if (r != ARCHIVE_OK) { + errmsg(archive_error_string(ar)); + return (r); + } + } +} + +static void +msg(const char *m) +{ + write(1, m, strlen(m)); +} + +static void +errmsg(const char *m) +{ + if (m == NULL) { + m = "Error: No error description provided.\n"; + } + write(2, m, strlen(m)); +} + +static void +usage(void) +{ +/* Many program options depend on compile options. */ + const char *m = "Usage: minitar [-" +#ifndef NO_CREATE + "c" +#endif +#ifndef NO_XZ + "J" +#endif +#ifndef NO_BZIP2 + "j" +#endif + "tvx" +#ifndef NO_BZIP2 + "y" +#endif +#ifndef NO_COMPRESS + "Z" +#endif +#ifndef NO_GZIP + "z" +#endif + "] [-f file] [file]\n"; + + errmsg(m); + exit(1); +} diff --git a/external/minitar/prebuilt/arm64-v8a/minitar b/external/minitar/prebuilt/arm64-v8a/minitar new file mode 100755 index 0000000..23e5547 Binary files /dev/null and b/external/minitar/prebuilt/arm64-v8a/minitar differ diff --git a/external/minitar/prebuilt/armeabi-v7a/minitar b/external/minitar/prebuilt/armeabi-v7a/minitar new file mode 100755 index 0000000..236224d Binary files /dev/null and b/external/minitar/prebuilt/armeabi-v7a/minitar differ diff --git a/external/minitar/prebuilt/x86/minitar b/external/minitar/prebuilt/x86/minitar new file mode 100755 index 0000000..6cc847a Binary files /dev/null and b/external/minitar/prebuilt/x86/minitar differ diff --git a/external/minitar/prebuilt/x86_64/minitar b/external/minitar/prebuilt/x86_64/minitar new file mode 100755 index 0000000..0bca410 Binary files /dev/null and b/external/minitar/prebuilt/x86_64/minitar differ diff --git a/external/proot/.gitignore b/external/proot/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/external/proot/.gitignore @@ -0,0 +1 @@ +/build diff --git a/external/proot/LICENSE b/external/proot/LICENSE new file mode 100644 index 0000000..9b05694 --- /dev/null +++ b/external/proot/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 green-green-avk + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/external/proot/build.sh b/external/proot/build.sh new file mode 100755 index 0000000..7a93781 --- /dev/null +++ b/external/proot/build.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +./get-talloc.sh +./get-proot.sh +./make-talloc-static.sh +./make-proot.sh +./pack.sh diff --git a/external/proot/config b/external/proot/config new file mode 100644 index 0000000..b5c4eeb --- /dev/null +++ b/external/proot/config @@ -0,0 +1,48 @@ +PROOT_V='0.12_fork' +TALLOC_V='2.4.0' + +# `pre5' is for Android API < 21 where we can't _FILE_OFFSET_BITS=64 at least + +ARCHS='aarch64 armv7a armv7a-pre5 x86_64 i686 i686-pre5' + +BASE_DIR="$PWD" + +BUILD_DIR="$BASE_DIR/build" +mkdir -p "$BUILD_DIR" + +PKG_DIR="$BASE_DIR/packages" +mkdir -p "$PKG_DIR" + +NDK="$HOME/Android/Sdk/ndk/21.3.6528147" +TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-$(uname -m)" + +set-arch() { + MARCH="${1%%-*}" + if [ "$MARCH" != "$1" ] + then SUBARCH="${1#*-}" + else SUBARCH='' + fi + + if [ "$SUBARCH" == 'pre5' ] + then API=16 + else API=21 + fi + + INSTALL_ROOT="$BUILD_DIR/root-$ARCH/root" + STATIC_ROOT="$BUILD_DIR/static-$ARCH/root" + + case "$MARCH" in + arm*) MARCH_T='arm' ;; + *) MARCH_T="$MARCH" ;; + esac + + export AR="$(echo $TOOLCHAIN/bin/$MARCH_T-linux-android*-ar)" + export AS="$(echo $TOOLCHAIN/bin/$MARCH_T-linux-android*-as)" + export CC="$(echo $TOOLCHAIN/bin/$MARCH-linux-android*$API-clang)" + export CXX="$(echo $TOOLCHAIN/bin/$MARCH-linux-android*$API-clang++)" + export LD="$(echo $TOOLCHAIN/bin/$MARCH_T-linux-android*-ld)" + export RANLIB="$(echo $TOOLCHAIN/bin/$MARCH_T-linux-android*-ranlib)" + export STRIP="$(echo $TOOLCHAIN/bin/$MARCH_T-linux-android*-strip)" + export OBJCOPY="$(echo $TOOLCHAIN/bin/$MARCH_T-linux-android*-objcopy)" + export OBJDUMP="$(echo $TOOLCHAIN/bin/$MARCH_T-linux-android*-objdump)" +} diff --git a/external/proot/get-proot.sh b/external/proot/get-proot.sh new file mode 100755 index 0000000..bc40161 --- /dev/null +++ b/external/proot/get-proot.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e +shopt -s nullglob + +. ./config + +cd "$BUILD_DIR" + +if [ -d "proot-$PROOT_V" ] ; then exit 0 ; fi + +wget -O - "https://github.com/alufers/proot/archive/refs/tags/$PROOT_V.tar.gz" | tar -xzv diff --git a/external/proot/get-talloc.sh b/external/proot/get-talloc.sh new file mode 100755 index 0000000..ed2f686 --- /dev/null +++ b/external/proot/get-talloc.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e +shopt -s nullglob + +. ./config + +cd "$BUILD_DIR" + +if [ -d "talloc-$TALLOC_V" ] ; then exit 0 ; fi + +wget -O - "https://download.samba.org/pub/talloc/talloc-$TALLOC_V.tar.gz" | tar -xzv + +cp ../os2_delete_patched.c "talloc-$TALLOC_V/lib/replace/tests/os2_delete.c" diff --git a/external/proot/make-proot-for-apk.sh b/external/proot/make-proot-for-apk.sh new file mode 100755 index 0000000..471ecbf --- /dev/null +++ b/external/proot/make-proot-for-apk.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -e +shopt -s nullglob + +. ./config + +cd "$BUILD_DIR/proot-$PROOT_V/src" + +for ARCH in $ARCHS +do + +set-arch $ARCH + +export CFLAGS="-I$STATIC_ROOT/include -Werror=implicit-function-declaration" +export LDFLAGS="-L$STATIC_ROOT/lib" +export PROOT_UNBUNDLE_LOADER='.' +export PROOT_UNBUNDLE_LOADER_NAME='libproot-loader.so' +export PROOT_UNBUNDLE_LOADER_NAME_32='libproot-loader32.so' + +if [ "$SUBARCH" == 'pre5' ] +then export ANDROID_PRE5=1 +else unset ANDROID_PRE5 +fi + +make distclean || true +make V=1 "PREFIX=$INSTALL_ROOT-apk" install +make distclean || true +CFLAGS="$CFLAGS -DUSERLAND" make V=1 "PREFIX=$INSTALL_ROOT-apk" proot +cp -a ./proot "$INSTALL_ROOT-apk/bin/proot-userland" + +( +cd "$INSTALL_ROOT-apk/bin" +for FN in * +do +"$STRIP" "$FN" +case "$FN" in +lib*.so) ;; +*) mv -f "$FN" "lib$FN.so" ;; +esac +done +) + +done diff --git a/external/proot/make-proot.sh b/external/proot/make-proot.sh new file mode 100755 index 0000000..40f2abf --- /dev/null +++ b/external/proot/make-proot.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -e +shopt -s nullglob + +. ./config + +cd "$BUILD_DIR/proot-$PROOT_V/src" + +for ARCH in $ARCHS +do + +set-arch $ARCH + +export CFLAGS="-I$STATIC_ROOT/include -Werror=implicit-function-declaration" +export LDFLAGS="-L$STATIC_ROOT/lib" +export PROOT_UNBUNDLE_LOADER='../libexec/proot' + +if [ "$SUBARCH" == 'pre5' ] +then export ANDROID_PRE5=1 +else unset ANDROID_PRE5 +fi + +make distclean || true +make V=1 "PREFIX=$INSTALL_ROOT" install +make distclean || true +CFLAGS="$CFLAGS -DUSERLAND" make V=1 "PREFIX=$INSTALL_ROOT" proot +cp -a ./proot "$INSTALL_ROOT/bin/proot-userland" + +( +cd "$INSTALL_ROOT/bin" +for FN in * +do +"$STRIP" "$FN" +done +) + +( +cd "$INSTALL_ROOT/bin/$PROOT_UNBUNDLE_LOADER" +for FN in * +do +"$STRIP" "$FN" +done +) + +done diff --git a/external/proot/make-talloc-static.sh b/external/proot/make-talloc-static.sh new file mode 100755 index 0000000..4c3a401 --- /dev/null +++ b/external/proot/make-talloc-static.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +set -e +shopt -s nullglob + +. ./config + +cd "$BUILD_DIR/talloc-$TALLOC_V" + +DEF_CFLAGS="$CFLAGS" + +for ARCH in $ARCHS +do + +set-arch $ARCH + +if [ "$SUBARCH" == 'pre5' ] +then +FILE_OFFSET_BITS='NO' +export CFLAGS="$CFLAGS -D__ANDROID_API__=14" +else +FILE_OFFSET_BITS='OK' +export CFLAGS="$DEF_CFLAGS" +fi + +make distclean || true + +cat <cross-answers.txt +Checking uname sysname type: "Linux" +Checking uname machine type: "dontcare" +Checking uname release type: "dontcare" +Checking uname version type: "dontcare" +Checking simple C program: OK +building library support: OK +Checking for large file support: OK +Checking for -D_FILE_OFFSET_BITS=64: $FILE_OFFSET_BITS +Checking for WORDS_BIGENDIAN: OK +Checking for C99 vsnprintf: OK +Checking for HAVE_SECURE_MKSTEMP: OK +rpath library support: OK +-Wl,--version-script support: FAIL +Checking correct behavior of strtoll: OK +Checking correct behavior of strptime: OK +Checking for HAVE_IFACE_GETIFADDRS: OK +Checking for HAVE_IFACE_IFCONF: OK +Checking for HAVE_IFACE_IFREQ: OK +Checking getconf LFS_CFLAGS: OK +Checking for large file support without additional flags: OK +Checking for working strptime: OK +Checking for HAVE_SHARED_MMAP: OK +Checking for HAVE_MREMAP: OK +Checking for HAVE_INCOHERENT_MMAP: OK +Checking getconf large file support flags work: OK +EOF + +./configure "--prefix=$INSTALL_ROOT" --disable-rpath --disable-python --cross-compile --cross-answers=cross-answers.txt + +make + +mkdir -p "$STATIC_ROOT/include" +mkdir -p "$STATIC_ROOT/lib" + +ar rcs "$STATIC_ROOT/lib/libtalloc.a" bin/default/talloc*.o +cp -f talloc.h "$STATIC_ROOT/include" + +done diff --git a/external/proot/os2_delete_patched.c b/external/proot/os2_delete_patched.c new file mode 100644 index 0000000..6cb9911 --- /dev/null +++ b/external/proot/os2_delete_patched.c @@ -0,0 +1,136 @@ +/* + test readdir/unlink pattern that OS/2 uses + tridge@samba.org July 2005 +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "replace-test.h" + +#define NUM_FILES 700 +#define READDIR_SIZE 100 +#define DELETE_SIZE 4 + +#define TESTDIR "test.dir" + +static int test_readdir_os2_delete_ret; + +#define FAILED(d) (printf("failure: readdir [\nFailed for %s - %d = %s\n]\n", d, errno, strerror(errno)), test_readdir_os2_delete_ret = 1) + +#ifndef MIN +#define MIN(a,b) ((a)<(b)?(a):(b)) +#endif + +#ifdef _WIN32 +#define mkdir(d,m) _mkdir(d) +#endif + +static void cleanup(void) +{ + /* I'm a lazy bastard */ + if (system("rm -rf " TESTDIR)) { + FAILED("system"); + } + mkdir(TESTDIR, 0700) == 0 || FAILED("mkdir"); +} + +static void create_files(void) +{ + int i; + for (i=0;id_name); + // } + + // if (i == 0) { + // return 0; + // } + + // /* delete the first few */ + // for (j=0; jd_name, ".") == 0 || FAILED("match ."); + de = readdir(d); + strcmp(de->d_name, "..") == 0 || FAILED("match .."); + + while (1) { + int n = os2_delete(d); + if (n == 0) break; + total_deleted += n; + } + closedir(d); + + fprintf(stderr, "Deleted %d files of %d\n", total_deleted, NUM_FILES); + + rmdir(TESTDIR) == 0 || FAILED("rmdir"); + + if (system("rm -rf " TESTDIR) == -1) { + FAILED("system"); + } + + return test_readdir_os2_delete_ret; +} diff --git a/external/proot/pack.sh b/external/proot/pack.sh new file mode 100755 index 0000000..1b6b63f --- /dev/null +++ b/external/proot/pack.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e +shopt -s nullglob + +. ./config + +for ARCH in $ARCHS +do + +echo "For $ARCH:" + +set-arch $ARCH + +tar -czvf "$PKG_DIR/proot-android-$ARCH.tar.gz" -C "$INSTALL_ROOT/.." root + +done diff --git a/ubuntu-custom/build.sh b/ubuntu-custom/build.sh new file mode 100755 index 0000000..599c0b6 --- /dev/null +++ b/ubuntu-custom/build.sh @@ -0,0 +1,112 @@ +#!/bin/bash +# +# checkn1x build script +# https://asineth.me/checkn1x +# + +mkdir -p build +cd build + +export rootfs_folder=rootfs +export name_iso="custom-linux" +export ubuntu_version="23.10" +export ubuntu_name=ubuntu-base-$ubuntu_version + +mkdir -p $rootfs_folder + +mkdir -p iso/boot/grub + +rm -rf ./$name_iso.iso +rm -rf iso/boot/initramfs.xz + +if [ -d "$rootfs_folder/bin" ] +then + echo "Skip Extract Alpine Miniroot" +else + if [ -f "../$ubuntu_name-base-amd64.tar.gz" ] + then + echo "Extract Alpien Miniroot" + tar -xzf ../$ubuntu_name-base-amd64.tar.gz -C ./$rootfs_folder + else + echo "Download Alpine Root" + wget https://dl-cdn.ubuntulinux.org/ubuntu/edge/releases/x86_64/$ubuntu_name-base-amd64.tar.gz + echo "Extract Alpien Miniroot" + tar -xzf ../$ubuntu_name-base-amd64.tar.gz -C ./$rootfs_folder + fi +fi + + +umount -v $rootfs_folder/dev >/dev/null 2>&1 +umount -v $rootfs_folder/sys >/dev/null 2>&1 +umount -v $rootfs_folder/proc >/dev/null 2>&1 + + +mount -vo bind /dev $rootfs_folder/dev +mount -vt sysfs sysfs $rootfs_folder/sys +mount -vt proc proc $rootfs_folder/proc + +echo "nameserver 8.8.8.8 \n\ +nameserver 8.8.4.4" > $rootfs_folder/etc/resolv.conf + +chmod 777 $rootfs_folder/tmp + +export run_chroot="chroot $rootfs_folder /usr/bin/env PATH=/usr/bin:/bin:/usr/sbin:/sbin /bin/bash" +echo "sudo $run_chroot" + +$run_chroot + +# echo "Update Package Core" +# cat << ! | $run_chroot +# apt-get update -y +# apt-get upgrade -y +# ! + + +# echo "Update Package Core" +# cat << ! | $run_chroot +# apt-get -y linux-firmware +# ! + + +# # echo "Umount" +# # umount -v $rootfs_folder/dev >/dev/null 2>&1 +# # umount -v $rootfs_folder/sys >/dev/null 2>&1 +# # umount -v $rootfs_folder/proc >/dev/null 2>&1 + + +# # # # kernel modules +# # # cat << ! > $rootfs_folder/etc/inittab +# # # # /etc/inittab +# # # ::sysinit:/sbin/openrc sysinit +# # # ::wait:/sbin/openrc default +# # # tty1::respawn:/bin/login -f root +# # # tty2::respawn:/bin/login -f root +# # # tty3::respawn:/bin/login -f root +# # # tty4::respawn:/bin/login -f root +# # # tty5::respawn:/bin/login -f root +# # # ::ctrlaltdel:/sbin/reboot -f +# # # # Stuff to do before rebooting +# # # ::shutdown:/sbin/openrc shutdown +# # # ! + + +# # # cp -av $rootfs_folder/boot/vmlinuz-lts iso/boot/vmlinuz +# # # cat << ! > iso/boot/grub/grub.cfg +# # # insmod all_video +# # # echo 'Custom Alpine Linux' +# # # linux /boot/vmlinuz quiet loglevel=3 +# # # initrd /boot/initramfs.xz +# # # boot +# # # ! + +# # # # initramfs +# # pushd $rootfs_folder +# # rm -rfv boot/* +# # rm -rfv tmp/* +# # rm -rfv var/cache/* +# # find . | cpio -oH newc | xz -C crc32 --x86 -vz9eT0 > ../iso/boot/initramfs.xz +# # popd + +# # # # iso creation +# # grub-mkrescue -o "./$name_iso.iso" iso --compress=xz + diff --git a/ubuntu-custom/clean.sh b/ubuntu-custom/clean.sh new file mode 100755 index 0000000..c8e4f36 --- /dev/null +++ b/ubuntu-custom/clean.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# checkn1x build script +# https://asineth.me/checkn1x +# + +echo "Umount" +umount -v $rootfs_folder/dev >/dev/null 2>&1 +umount -v $rootfs_folder/sys >/dev/null 2>&1 +umount -v $rootfs_folder/proc >/dev/null 2>&1 + +rm -rf build \ No newline at end of file diff --git a/ubuntu-custom/new.sh b/ubuntu-custom/new.sh new file mode 100644 index 0000000..fc44dc6 --- /dev/null +++ b/ubuntu-custom/new.sh @@ -0,0 +1,37 @@ + + +# mkdir -pv work +# mkdir -pv work/rootfs +# mkdir -pv work/iso/boot +# # tar -xzf /home/galaxeus/Documents/linux/ubuntu-custom/ubuntu-base-23.10-base-amd64.tar.gz -C ./work/rootfs + +# sudo mount -vo bind /dev rootfs/dev +# sudo mount -vt sysfs sysfs rootfs/sys +# sudo mount -vt proc proc rootfs/proc + + +# # sudo chroot rootfs /usr/bin/env PATH=/usr/bin:/bin:/usr/sbin:/sbin /bin/bash + +# echo "Archivon" > rootfs/etc/hostname + +# # fix apt-get update +# sudo chmod 777 rootfs/tmp + + +# sudo cp -av rootfs/boot/vmlinuz-**-**-generic iso/boot/vmlinuz +# sudo cp -av rootfs/boot/initrd.img iso/boot/initrd + +# # clean up +# # rm -rfv tmp/* +# # rm -rfv boot/* +# # clean up +# # rm -rfv var/cache/* + + +# sudo grub-mkrescue -o "../checkn1x-linux.iso" iso --compress=xz + + + +umount -v -l -f work/rootfs/dev >/dev/null 2>&1 +umount -v -l -f work/rootfs/sys >/dev/null 2>&1 +umount -v -l -f work/rootfs/proc >/dev/null 2>&1