1#!/bin/sh
2# NetHack 3.7  macosx.sh $NHDT-Date: 1597332920 2020/08/13 15:35:20 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.24 $
3# Copyright (c) Kenneth Lorber, Kensington, Maryland, 2007.
4# NetHack may be freely redistributed.  See license for details.
5#
6# hints helper script for macosx
7# DO NOT invoke directly.
8
9# Works for 10.4 and 10.5.  (The 10.5 support might work for 10.4 but keep
10# both versions in case we need to support earlier versions.)
11
12cmd=$1
13
14case "x$cmd" in
15xuser)
16		# fail unless user exists (good through 10.4)
17	user=$2
18	gotuser=`niutil -readval . /users/$user name 0 2>/dev/null`
19	[ -z $gotuser ] && (echo "User $user does not exist."
20		exit 1;
21	)
22	;;
23
24#name: dummy1
25#_writers_passwd: dummy1
26#_writers_tim_password: dummy1
27#_writers_picture: dummy1
28#home: /Users/dummy1
29#gid: 504
30#picture: /Library/User Pictures/Animals/Dragonfly.tif
31#uid: 504
32#hint: dummy1
33#_writers_hint: dummy1
34#sharedDir:
35#_shadow_passwd:
36#_writers_realname: dummy1
37#shell: /bin/bash
38#passwd: ********
39#authentication_authority: ;ShadowHash;
40#realname: dummyname1
41#generateduid: F6D4991C-BDF5-481F-A407-D84C6A2D0E2A
42
43xgroup)
44		# fail unless group exists (good through 10.4)
45	group=$2
46	gotgrp=`niutil -readval . /groups/$group name 0 2>/dev/null`
47	[ -z $gotgrp ] && ( echo "Group $group does not exist."
48		exit 1
49	)
50	;;
51
52#niutil -read . /groups/bin name 0
53#name: bin
54#gid: 7
55#passwd: *
56#generateduid: ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000007
57#smb_sid: S-1-5-21-107
58#realname: Binary
59
60xuser2)
61		# fail unless user exists (required as of 10.5)
62	user=$2
63	if( dscl localhost -read /Search/Users/$user 1>/dev/null 2>&1 );
64	then
65		true;
66	else
67		echo "User $user does not exist.";
68		exit 1;
69	fi
70	;;
71
72xgroup2)
73		# if group does not exist, create it (required as of 10.5)
74	group=$2
75	[ -z $group ] && ( echo "No group specified."
76		exit 1
77	)
78	if( dscl localhost -read /Search/Groups/$group 1>/dev/null 2>&1 );
79	then
80		true;
81	else
82		echo "Group $group does not exist - creating.";
83		dseditgroup -o create -r "Games Group" -s 3600 $group
84		if( dscl localhost -read /Search/Groups/$group 1>/dev/null 2>&1 );
85		then
86			true;
87		else
88			echo "Unable to create group $group."
89			exit 1
90		fi
91	fi
92	;;
93
94xeditsysconf)
95	src=$2
96	dest=$3
97	ptg=1
98	# We don't need an LLDB module because any MacOSX new enough to
99	# have no Apple supported gdb is also new enough to get good
100	# stack traces through libc.
101	# NB: xcrun will check $PATH
102	if [[ -x /usr/bin/xcrun && `/usr/bin/xcrun -f gdb 2>/dev/null` ]] ; then
103            gdbpath="GDBPATH="`/usr/bin/xcrun -f gdb`
104	elif [ -f /usr/bin/gdb ]; then
105	    gdbpath='GDBPATH=/usr/bin/gdb' #traditional location
106	elif [ -f /opt/local/bin/ggdb ]; then
107	    gdbpath='GDBPATH=/opt/local/bin/ggdb' #macports gdb
108	elif [ -f /Developer/usr/bin/gdb ]; then
109	    # this one seems to be broken with Xcode 5.1.1 on Mountain Lion
110	    gdbpath='GDBPATH=/Developer/usr/bin/gdb' #older Xcode tools
111	else
112	    gdbpath='#GDBPATH' #none of the above
113	    ptg=0
114	fi
115	if [ -f /bin/grep ]; then
116	    greppath='GREPPATH=/bin/grep'
117	elif [ -f /usr/bin/grep ]; then
118	    greppath='GREPPATH=/usr/bin/grep'
119	else
120	    greppath='#GREPPATH'
121	fi
122	# PANICTRACE_GDB value should only be replaced if gdbpath is '#GDBPATH'
123	if ! [ -e $dest ]; then
124		sed -e "s:^GDBPATH=.*:$gdbpath:" \
125		    -e "s:^GREPPATH=.*:$greppath:" \
126		    -e "s/^PANICTRACE_GDB=./PANICTRACE_GDB=$ptg/" \
127		    -e 's/^#OPTIONS=.*/&\
128OPTIONS=!use_darkgray/' \
129		    $src > $dest
130	fi
131	;;
132
133#% dscl localhost -read /Search/Groups/wheel
134# AppleMetaNodeLocation: /Local/Default
135# GeneratedUID: ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000
136# GroupMembership: root
137# Password: *
138# PrimaryGroupID: 0
139# RealName:
140#  System Group
141# RecordName: wheel
142# RecordType: dsRecTypeStandard:Groups
143# SMBSID: S-1-5-21-100
144
145xdescplist)	SVSDOT=`util/makedefs --svs .`
146	cat <<E_O_M;
147<?xml version="1.0" encoding="UTF-8"?>
148<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
149<plist version="1.0">
150<dict>
151        <key>IFPkgDescriptionDeleteWarning</key>
152        <string></string>
153        <key>IFPkgDescriptionDescription</key>
154        <string>NetHack $SVSDOT for MacOS
155</string>
156        <key>IFPkgDescriptionTitle</key>
157        <string>NetHack</string>
158        <key>IFPkgDescriptionVersion</key>
159        <string>$SVSDOT</string>
160</dict>
161</plist>
162E_O_M
163	;;
164
165xinfoplist)	SVSDOT=`util/makedefs --svs .`
166	cat <<E_O_M;
167<?xml version="1.0" encoding="UTF-8"?>
168<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
169<plist version="1.0">
170<dict>
171	<key>CFBundleGetInfoString</key>
172	<string>NetHack $SVSDOT for MacOS</string>
173	<key>CFBundleIdentifier</key>
174	<string>org.nethack.macos</string>
175	<key>CFBundleName</key>
176	<string>NetHack</string>
177	<key>CFBundleShortVersionString</key>
178	<string>$SVSDOT</string>
179	<key>IFMajorVersion</key>
180	<integer>3</integer>
181	<key>IFMinorVersion</key>
182	<integer>3</integer>
183	<key>IFPkgFlagAllowBackRev</key>
184	<true/>
185	<key>IFPkgFlagAuthorizationAction</key>
186	<string>RootAuthorization</string>
187	<key>IFPkgFlagDefaultLocation</key>
188	<string>/</string>
189	<key>IFPkgFlagInstallFat</key>
190	<false/>
191	<key>IFPkgFlagIsRequired</key>
192	<false/>
193	<key>IFPkgFlagOverwritePermissions</key>
194	<true/>
195	<key>IFPkgFlagRelocatable</key>
196	<false/>
197	<key>IFPkgFlagRestartAction</key>
198	<string>NoRestart</string>
199	<key>IFPkgFlagRootVolumeOnly</key>
200	<false/>
201	<key>IFPkgFlagUpdateInstalledLanguages</key>
202	<false/>
203	<key>IFPkgFlagUseUserMask</key>
204	<false/>
205	<key>IFPkgFormatVersion</key>
206	<real>0.10000000149011612</real>
207</dict>
208</plist>
209E_O_M
210	;;
211
212*)      echo "Unknown command $cmd"
213	exit 1
214        ;;
215esac
216
217# dscl localhost -read /Search/Users/games
218# dsAttrTypeNative:_writers_hint: games
219# dsAttrTypeNative:_writers_jpegphoto: games
220# dsAttrTypeNative:_writers_LinkedIdentity: games
221# dsAttrTypeNative:_writers_passwd: games
222# dsAttrTypeNative:_writers_picture: games
223# dsAttrTypeNative:_writers_realname: games
224# dsAttrTypeNative:_writers_UserCertificate: games
225# AppleMetaNodeLocation: /Local/Default
226# AuthenticationAuthority: ;ShadowHash; ;Kerberosv5;;games@LKDC:SHA1.3F695B215C78511043D9787CA51DE92E6494A021;LKDC:SHA1.3F695B215C78511043D9787CA51DE92E6494A021;
227# AuthenticationHint: games
228# GeneratedUID: A727EFB1-D6AA-4FE2-8524-0E154890E9A9
229# NFSHomeDirectory: /Users/games
230# Password: ********
231# Picture:
232#  /Library/User Pictures/Flowers/Sunflower.tif
233# PrimaryGroupID: 20
234# RealName: games
235# RecordName: games
236# RecordType: dsRecTypeStandard:Users
237# UniqueID: 505
238# UserShell: /bin/bash
239
240# see also: http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix/additionalfeatures/chapter_10_section_9.html
241
242# another mess: 10.4 creates a group for every user, 10.5 dumps you into staff.
243# so I think we need to explicitly create group games in both (if it doesn't
244# exist) and use owner bin (nope that fails since everything seems to be owned
245# by root.  Do we want that?  How about just creating user games as well?)
246
247# [Hermes:sys/unix/hints] keni% dscl localhost -read /Search/Users/games9
248# <dscl_cmd> DS Error: -14136 (eDSRecordNotFound)
249# [Hermes:sys/unix/hints] keni% dscl localhost -read /Search/Users/games9 >/dev/null
250# <dscl_cmd> DS Error: -14136 (eDSRecordNotFound)
251# [Hermes:sys/unix/hints] keni% dscl localhost -read /Search/Users/games > /dev/null
252# status is good: 0 or 56
253
254# file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/releasenotes/MacOSXServer/RN-DirectoryServices/index.html
255