fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
c5e4fed02
master
1#!/bin/sh -e 2 3# Modified from Debian's add-shell to work on OS X 4 5if test $# -eq 0 6then 7 echo "usage: $0 shellname [shellname ...]" 8 exit 1 9fi 10 11scriptname=$(basename "$0") 12if [ "$(id -u)" -ne 0 ]; then 13 echo "${scriptname} must be run as root" 14 exit 1 15fi 16 17file=/etc/shells 18# I want this to be GUARANTEED to be on the same filesystem as $file 19tmpfile=${file}.tmp 20 21set -o noclobber 22 23# shellcheck disable=SC2064 24trap "rm -f $tmpfile" EXIT 25 26if ! cat $file > $tmpfile 27then 28 cat 1>&2 <<EOF 29Either another instance of $0 is running, or it was previously interrupted. 30Please examine ${tmpfile} to see if it should be moved onto ${file}. 31EOF 32 exit 1 33fi 34 35# Append a newline if it doesn't exist 36[ -z "$(tail -c1 "$tmpfile")" ] || echo "" >> "$tmpfile" 37 38for i 39do 40 if ! grep -q "^${i}$" "$tmpfile" 41 then 42 echo "$i" >> "$tmpfile" 43 fi 44done 45 46chmod 0644 $tmpfile 47chown root:wheel $tmpfile 48 49mv $tmpfile $file 50 51trap "" EXIT 52exit 0