-
Notifications
You must be signed in to change notification settings - Fork 0
/
void-install.sh
74 lines (61 loc) · 2.12 KB
/
void-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
# Create a voidlinux Termux environment
# Usage: void-install.sh libc
# Examples:
# void-install.sh musl
die() { echo $*; exit 1; }
REPOURL="https://repo.voidlinux.eu/live/current/"
echo "Checking host architecture..."
case "$(getprop ro.product.cpu.abi)" in
arm64-v8a) ARCH=aarch64 ;;
armeabi|armeabi-v7a) ARCH=armv7l ;;
x86_64) ARCH=x86_64 ;;
esac
case "$1" in
glibc|"") ;;
musl) ARCH="$ARCH-musl" ;;
*) die "This C standard library is not supported" ;;
esac
echo "Creating directory..."
[ -n "$CHROOT_DIR" ] || CHROOT_DIR="$HOME/.chroots"
mkdir -p "$CHROOT_DIR/void-$ARCH"
echo "Updating apt database..."
apt update -y -qq $> /dev/null
echo "Checking required tools..."
for i in "bsdtar" "curl" "proot"; do
if [ -e "$PREFIX/bin/$i" ]; then
echo " * $i found"
else
echo " * $i not found. Installing..."
apt install -y -qq $i || die "APT failed to install $i"
fi
done
echo "Downloading tarball..."
cd $PREFIX/tmp/
curl -s "$REPOURL/sha256sums.txt" | grep "void-$ARCH" > sha256sum.txt || die "Failed to fetch the tarball from the repository"
read -r sha256 filename < "sha256sum.txt"
curl -O "https://repo.voidlinux.eu/live/current/$filename"
echo "Checking integrity of file..."
sha256sum -c sha256sum.txt || die "The tarball is corrupted. Try to run the script again."
echo "Extracting tarball..."
bsdtar -xpf $filename -C $CHROOT_DIR/void-$ARCH/ 2> /dev/null
echo "Configuring system"
echo "nameserver 8.8.8.8" >> "$CHROOT_DIR/void-$ARCH/etc/resolv.conf"
chmod 644 "$CHROOT_DIR/void-$ARCH/etc/resolv.conf"
echo "Creating the login file..."
BIN="$PREFIX/bin/void-$ARCH"
cat << EOF > $BIN
#!/bin/sh
# Login to voidlinux chroot
# Usage: void-$ARCH [root]
[ -n "\$CHROOT_DIR" ] || CHROOT_DIR="\$HOME/.chroots"
unset LD_PRELOAD
if [ "\$1" = "root" ]; then
exec proot --link2symlink -0 -r "\$CHROOT_DIR/void-$ARCH" -b /dev -b /sys -b /proc -b "\$HOME" /usr/bin/env -i /usr/bin/bash --login
else
exec proot --link2symlink -r "\$CHROOT_DIR/void-$ARCH" -b /dev -b /sys -b /proc -b "\$HOME" /usr/bin/env -i /usr/bin/bash --login
fi
EOF
chmod 700 $BIN
echo "Installation finished"
echo "Run the command void-$ARCH [root] to enter the chroot"