1#!/bin/sh -e23help() {4 cat - >&2 <<EOF5doasedit - like sudoedit, but for doas67doasedit file...89Every argument will be treated as a file to edit. There's no support for10passing arguments to doas, so you can only doas root.1112This script is SECURITY SENSITIVE! Special care has been taken to correctly13preserve file attributes. Please exercise CAUTION when modifying AND using14this script.15EOF16}1718case "$1" in --help|-h) help; exit 0;; esac1920export TMPDIR=/dev/shm/21trap 'trap - EXIT HUP QUIT TERM INT ABRT; rm -f "$tmp" "$tmpcopy"' EXIT HUP QUIT TERM INT ABRT2223for file; do24 case "$file" in -*) file=./"$file" ;; esac2526 tmp="$(mktemp)"27 if [ -f "$file" ] && [ ! -r "$file" ]; then28 doas cat "$file" > "$tmp"29 elif [ -r "$file" ]; then30 cat "$file" > "$tmp"31 fi3233 tmpcopy="$(mktemp)"34 cat "$tmp" > "$tmpcopy"3536 ${EDITOR:-vi} "$tmp"3738 if cmp -s "$tmp" "$tmpcopy"; then39 echo 'File unchanged, exiting...'40 else41 doas dd if="$tmp" of="$file"42 echo 'Done, changes written'43 fi4445 rm "$tmp" "$tmpcopy"46done