summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-08-14 21:15:21 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-08-14 21:15:21 -0400
commitf61ce11643e228343d111f47c03f2dded83dc300 (patch)
treee23f1b3a687a114213262b7cd8b6fd3612fe9f2e
parenta3e647985f2c429c06613eedaf7824ff7cba5484 (diff)
replace osi-run with osi-shell
-rw-r--r--osi-mk.d/systemd-osi-run.sh36
-rw-r--r--osi-mk.d/systemd-osi-shell.sh44
-rwxr-xr-xosi-shell (renamed from osi-run)40
-rwxr-xr-xruntests20
4 files changed, 73 insertions, 67 deletions
diff --git a/osi-mk.d/systemd-osi-run.sh b/osi-mk.d/systemd-osi-run.sh
deleted file mode 100644
index dad9520..0000000
--- a/osi-mk.d/systemd-osi-run.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/hint/bash
-
-load_module "$(dirname -- "${BASH_SOURCE[0]}")/testuser.sh"
-
-post_install+=(10:systemd-osi-run:post_install)
-systemd-osi-run:post_install() {
- local arg_mountpoint=$1
-
- cat <<-'EOT' > "${arg_mountpoint}/etc/systemd/system/osi-run.target"
- [Unit]
- Description=osi-run target
- Requires=multi-user.target
- After=multi-user.target
- Conflicts=rescue.target
- AllowIsolate=yes
- EOT
- ln -sT osi-run.target "${arg_mountpoint}/etc/systemd/system/default.target"
-
- cat <<-'EOT' > "${arg_mountpoint}/etc/systemd/system/osi-run.service"
- [Unit]
- Description=osi-run service
- Wants=network-online.target
- After=network-online.target
- After=multi-user.target
- ConditionPathExists=/etc/osi-run
-
- [Service]
- Type=oneshot
- StandardOutput=journal+console
- ExecStart=/bin/bash -c '{ su testuser -c /etc/osi-run 2>&1; echo $? > /var/log/osi-run.status; } | tee /var/log/osi-run.out; rm -f /etc/osi-run; systemctl poweroff --no-block'
-
- [Install]
- WantedBy=osi-run.target
- EOT
- systemctl --root="$arg_mountpoint" enable osi-run.service
-}
diff --git a/osi-mk.d/systemd-osi-shell.sh b/osi-mk.d/systemd-osi-shell.sh
new file mode 100644
index 0000000..18ba167
--- /dev/null
+++ b/osi-mk.d/systemd-osi-shell.sh
@@ -0,0 +1,44 @@
+#!/hint/bash
+
+post_install+=(10:systemd-osi-shell:post_install)
+systemd-osi-shell:post_install() {
+ local arg_mountpoint=$1
+
+ cat <<-'EOT' > "${arg_mountpoint}/etc/systemd/system/osi-shell.target"
+ [Unit]
+ Description=osi-shell target
+ Requires=multi-user.target
+ After=multi-user.target
+ Conflicts=rescue.target
+ AllowIsolate=yes
+ EOT
+ ln -sT -- osi-shell.target "${arg_mountpoint}/etc/systemd/system/default.target"
+
+ cat <<-'EOT' > "${arg_mountpoint}/etc/systemd/system/osi-shell.service"
+ [Unit]
+ Description=osi-shell service
+ Wants=network-online.target
+ After=network-online.target
+
+ [Service]
+ KillSignal=SIGHUP
+ KillMode=process
+ IgnoreSIGPIPE=no
+
+ ExecStart=/bin/sh
+ StandardInput=tty
+ TTYPath=/dev/ttyS0
+ TTYReset=yes
+ TTYVHangup=yes
+
+ # Write the exit status to ttyS1 and poweroff
+ # Bash sets exit status to 128+SIGNAL if we get killed by a signal,
+ # but there's not a good one-liner way to get from signal name to number,
+ # so just use 128.
+ ExecStopPost=/bin/sh -c 'if [ "$EXIT_CODE" = exited ]; then echo $EXIT_STATUS; else echo 128; fi > /dev/ttyS1; systemctl poweroff --no-block'
+
+ [Install]
+ WantedBy=osi-shell.target
+ EOT
+ systemctl --root="$arg_mountpoint" enable osi-shell.service
+}
diff --git a/osi-run b/osi-shell
index c39e3b4..1230f19 100755
--- a/osi-run
+++ b/osi-shell
@@ -1,22 +1,13 @@
#!/usr/bin/env bash
# 2018 Luke Shumaker
declare -r NAME=osi-run
-declare -r VERSION=20180812
+declare -r VERSION=20180814
set -euE
source "${BASH_SOURCE[0]%/*}/lib/osi.sh"
main() {
-
local arg_mode=main
- local arg_mountpoint=
- local arg_image=
- local arg_qemu=(
- qemu-system-x86_64
- -machine accel=kvm
- -m 512
- )
-
local args
if ! args="$(getopt -n "${0##*/}" -o hV -l help,version -- "$@")"; then
arg_mode=error
@@ -52,8 +43,8 @@ main() {
return 0
;;
usage)
- print 'Usage: %s [OPTIONS] FILENAME.img < SCRIPT.sh' "${0##*/}"
- print 'Operating System Image: Run Script'
+ print 'Usage: %s [OPTIONS] FILENAME.img [< SCRIPT.sh]' "${0##*/}"
+ print 'Operating System Image: Interactive Shell'
echo
print 'OPTIONS:'
print ' -h, --help display this help'
@@ -61,16 +52,23 @@ main() {
return 0
;;
main)
- arg_mountpoint=$(mktemp -dt -- "${0##*/}.XXXXXXXXXX")
- trap "rmdir -- ${arg_mountpoint@Q}" EXIT
- sudo -- ./osi-mount --root -- "$arg_image" "$arg_mountpoint" install -Dm755 /dev/stdin "$arg_mountpoint/etc/osi-run"
- "${arg_qemu[@]}" \
- -name "osi-run $arg_image" \
- -drive media=disk,format=raw,if=virtio,file="$arg_image"
- sudo -- ./osi-mount --user -- "$arg_image" "$arg_mountpoint" sh -c "cat ${arg_mountpoint@Q}/var/log/osi-run.out; exit \$(cat ${arg_mountpoint@Q}/var/log/osi-run.status)"
- ;;
+ tmp=$(mktemp -td -- "${0##*/}.XXXXXXXXXX")
+ trap "rm -rf -- ${tmp@Q}" EXIT
- *) error 1 'Internal error. The programmer writing this tool screwed up.';;
+ mkfifo -- "$tmp/sync"
+
+ qemu-system-x86_64 \
+ -machine accel=kvm \
+ -m 512 \
+ -name "osi-shell $arg_image" \
+ -drive media=disk,format=raw,if=virtio,file="$arg_image" \
+ -serial stdio \
+ -serial file:"$tmp/exit" \
+ < <(cat <"$tmp/sync" >/dev/null; cat; while sleep 0.1; do printf '\x04'; done) \
+ > >(read -N1 c; printf '%s' "$c"; :>"$tmp/sync"; exec cat)
+
+ return "$(sed 's/\r$//' <"$tmp/exit")"
+ ;;
esac
}
diff --git a/runtests b/runtests
index 98ed8dc..cb8e581 100755
--- a/runtests
+++ b/runtests
@@ -41,7 +41,7 @@ check: ${WORKDIR}/build-$(COMMIT)/pkgdest
.PHONY: check
# osi-mk base images ###########################################################
-${WORKDIR}/base.raw: osi-mk.d/systemd-osi-run.sh
+${WORKDIR}/base.raw: osi-mk.d/systemd-osi-shell.sh
${WORKDIR}/base.raw:
rm -f -- '$@'
mkdir -p -- '$(@D)'
@@ -57,9 +57,9 @@ ${WORKDIR}/build.raw:
--edit='$(filter %.raw,$^)' \
$(addprefix --module=,$(filter osi-mk.d/%.sh,$^)) \
'$@.tmp'
- ./osi-run '$@.tmp' <<-'EOF'
- #!/usr/bin/env bash
- set -ex
+ ./osi-shell '$@.tmp' <<-'EOF'
+ su testuser || exit
+ set -e
libreblacklist update
script --return --quiet --command 'sudo librechroot make' /dev/null
EOF
@@ -83,9 +83,9 @@ ${WORKDIR}/build-232/build.raw:
'$@.tmp'
mv -T -- '$@.tmp' '$@'
${WORKDIR}/build-232/build.log: %/build.log: %/build.raw
- ./osi-run '$<' <<-EOF |& tee '$@.tmp'
- #!/usr/bin/env bash
- set -ex
+ ./osi-shell '$<' <<-EOF |& tee '$@.tmp'
+ su testuser || exit
+ set -e
cd ~/packages/abs/systemd
# sync on rebuild because the downgrade in [repo] will confuse chcleanup
script --return --quiet --command 'sudo librechroot sync' /dev/null
@@ -109,9 +109,9 @@ ${WORKDIR}/build-$(COMMIT)/build.raw: | ${WORKDIR}/.COMMIT.mk
'$@.tmp'
mv -T -- '$@.tmp' '$@'
${WORKDIR}/build-$(COMMIT)/build.log: %/build.log: %/build.raw
- ./osi-run '$<' <<-EOF |& tee '$@.tmp'
- #!/usr/bin/env bash
- set -ex
+ ./osi-shell '$<' <<-EOF |& tee '$@.tmp'
+ su testuser || exit
+ set -e
cd ~/packages/abs/systemd
sed 's:@COMMIT@:${COMMIT}:' < PKGBUILD.in > PKGBUILD
script --return --quiet --command 'sudo libremakepkg' /dev/null