summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2022-06-27 01:14:42 +0100
committerdavidovski <david@davidovski.xyz>2022-06-27 01:14:42 +0100
commit7bba6cd7612293796e905885f9ed3072877798ab (patch)
treedd01942dbdd474a4df62ecf74479f5e78d83f1c8 /src/tools
parent79fb6f41104cd0d88891598ddfc3c30d1bb0352d (diff)
added shmk, building all with shmk
Diffstat (limited to 'src/tools')
-rwxr-xr-xsrc/tools/default-jvm.sh52
-rw-r--r--src/tools/xichroot.sh58
2 files changed, 110 insertions, 0 deletions
diff --git a/src/tools/default-jvm.sh b/src/tools/default-jvm.sh
new file mode 100755
index 0000000..56c427c
--- /dev/null
+++ b/src/tools/default-jvm.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+JVM_DIR=/usr/lib/jvm
+JAVA_BIN=/bin/java
+
+usage () {
+ cat << EOF
+xilinux-java
+ Print the name of the currently linked jvm
+ non-zero exit code if none is linked
+
+xilinux-java [name]
+ create symlinks to /usr/lib/jvm/[name]/bin to /bin
+
+xilinux-java [-l]
+ list installed JVMs
+EOF
+}
+
+get () {
+ [ -h "$JAVA_BIN" ] && {
+ path=$(readlink "$JAVA_BIN")
+ path=${path%%/bin/java}
+ path=${path##*/}
+ echo $path
+ }
+}
+
+link () {
+ [ -d "$1" ] && for bin in $1/bin/*; do
+ ln -sf $bin /bin/${bin##*/}
+ done
+}
+
+
+[ "$#" = "0" ] && {
+ get || return 1
+} || {
+ case "$1" in
+ "-l"|"--list")
+ ls -1 $JVM_DIR
+ ;;
+ "-h"|"--help")
+ usage
+ ;;
+ *)
+ link $1 \
+ || link $JVM_DIR/$1 \
+ || get
+ ;;
+ esac
+}
+
diff --git a/src/tools/xichroot.sh b/src/tools/xichroot.sh
new file mode 100644
index 0000000..7136e25
--- /dev/null
+++ b/src/tools/xichroot.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+# This script is intended for root users to automatically mount requried dirs and chroot into an installed system
+# simplifed version of arch-chroot from <https://github.com/archlinux/arch-install-scripts>
+
+args=$@
+target=$1
+
+die() { printf "$@\n"; exit 1;}
+
+ignore_error() {
+ "$@" 2>/dev/null
+ return 0
+}
+
+chroot_add_mount() {
+ mount "$@" && CHROOT_ACTIVE_MOUNTS=("$2" "${CHROOT_ACTIVE_MOUNTS[@]}")
+}
+
+chroot_maybe_add_mount() {
+ local cond=$1; shift
+ if eval "$cond"; then
+ chroot_add_mount "$@"
+ fi
+}
+
+chroot_setup() {
+ CHROOT_ACTIVE_MOUNTS=()
+ [[ $(trap -p EXIT) ]] && die '(BUG): attempting to overwrite existing EXIT trap'
+ trap 'chroot_teardown' EXIT
+
+ chroot_add_mount proc "$target/proc" -t proc -o nosuid,noexec,nodev
+ chroot_add_mount sys "$target/sys" -t sysfs -o nosuid,noexec,nodev,ro
+ ignore_error chroot_maybe_add_mount "[[ -d '$1/sys/firmware/efi/efivars' ]]" \
+ efivarfs "$target/sys/firmware/efi/efivars" -t efivarfs -o nosuid,noexec,nodev
+ chroot_add_mount udev "$target/dev" -t devtmpfs -o mode=0755,nosuid
+ chroot_add_mount devpts "$target/dev/pts" -t devpts -o mode=0620,gid=5,nosuid,noexec
+ chroot_add_mount shm "$target/dev/shm" -t tmpfs -o mode=1777,nosuid,nodev
+ chroot_add_mount /run "$target/run" --bind
+ chroot_add_mount tmp "$target/tmp" -t tmpfs -o mode=1777,strictatime,nodev,nosuid
+}
+
+chroot_teardown() {
+ if (( ${#CHROOT_ACTIVE_MOUNTS[@]} )); then
+ umount "${CHROOT_ACTIVE_MOUNTS[@]}"
+ fi
+ unset CHROOT_ACTIVE_MOUNTS
+}
+
+[ "$EUID" -eq 0 ] || die "Please run this as root"
+[[ -d $target ]] || die "$target is not a directory; cannot chroot!"
+
+chroot_setup $@
+
+if [ $# -gt 1 ]; then
+ chroot $@
+else
+ chroot $@ /bin/sh -l
+fi