Advertisement
BSDG33KCLUB

rc.cdrom (opendarwin install script)

Jun 13th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.07 KB | None | 0 0
  1. #!/bin/sh
  2. # OpenDarwin install script
  3. # $Id: rc.cdrom,v 1.30 2005/04/28 20:06:46 kevin Exp $
  4.  
  5. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/etc:/private/etc ; export PATH
  6. ARCH=`arch`
  7. TARGET_MOUNT=/mnt
  8. AVAIL_SHELLS="sh tcsh csh bash zsh"
  9. T_UID_DEFAULT=1000
  10. T_GID_DEFAULT=1000
  11.  
  12. abort () {
  13. echo "Aborting the installation"
  14. echo "Press enter to reboot"
  15. read REBOOT
  16. shutdown -r now
  17. }
  18.  
  19. umount_target_disk () {
  20. umount -f ${ROOTPART}
  21. }
  22.  
  23. finishup () {
  24.  
  25. echo "Installation of the base system is now complete."
  26. echo "You may: "
  27. until [ ! : ]
  28. do
  29. echo "1) add a user to the new system"
  30. echo "2) Reboot"
  31. echo "3) Spawn a shell"
  32. echo -n "Your Choice: "
  33. read CHOICE
  34. case ${CHOICE} in
  35. 1) add_user ;;
  36. 2) umount_target_disk
  37. shutdown -r now
  38. break ;;
  39. 3) umount_target_disk
  40. /bin/sh
  41. break ;;
  42. esac
  43. done
  44.  
  45. }
  46.  
  47. add_user () {
  48.  
  49. # a few helper vars
  50. # make T_PW and T_PW_2 not equal
  51. ADMIN_USER=0
  52. SHELL_VALID=0
  53. T_PW=0
  54. T_PW_2=1
  55.  
  56.  
  57. echo ""
  58. echo -n "Username: "
  59. read T_USERNAME
  60. echo -n "Realname: "
  61. read T_REALNAME
  62. echo -n "UID (default: ${T_UID_DEFAULT}): "
  63. read T_UID
  64. echo -n "GID (default: ${T_GID_DEFAULT}): "
  65. read T_GID
  66.  
  67. if [ "$T_UID" == "" ]; then
  68. T_UID=${T_UID_DEFAULT}
  69. fi
  70.  
  71. if [ "$T_GID" == "" ]; then
  72. T_GID=${T_GID_DEFAULT}
  73. fi
  74.  
  75. until [ "$SHELL_VALID" == "1" ]; do
  76. echo -n "Available shells: "
  77. for shell in ${AVAIL_SHELLS}
  78. do
  79. echo -n "${shell} "
  80. done
  81. echo ""
  82. echo -n "Shell: "
  83. read T_SHELL;
  84.  
  85. for shell in ${AVAIL_SHELLS}
  86. do
  87. if [ "$T_SHELL" == "$shell" ]; then
  88. SHELL_VALID=1
  89. fi
  90. done
  91. done
  92.  
  93. echo -n "Home directory (default: /Users/${T_USERNAME}): "
  94. read T_HOMEDIR;
  95.  
  96. if [ "$T_HOMEDIR" == "" ]; then
  97. T_HOMEDIR=/Users/${T_USERNAME}
  98. fi
  99.  
  100. echo -n "Add ${T_USERNAME} to the admin group? (yes/no): "
  101. read CHOICE;
  102.  
  103. if [ "$CHOICE" == "yes" ]; then
  104. ADMIN_USER=1
  105. fi
  106.  
  107. while [ 1 ]; do
  108. T_PW=`openssl passwd`
  109. if [ ${?} == "0" ]; then
  110. break
  111. fi
  112. done
  113.  
  114. echo ""
  115. echo "Username: ${T_USERNAME}"
  116. echo "Realname: ${T_REALNAME}"
  117. echo "UID: ${T_UID}"
  118. echo "GID: ${T_GID}"
  119. echo "Shell: ${T_SHELL}"
  120. echo "Home: ${T_HOMEDIR}"
  121. echo ""
  122. echo -n "Add (yes/no): "
  123. read CHOICE
  124.  
  125. if [ "$CHOICE" == "yes" ]; then
  126. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /users/${T_USERNAME} passwd ${T_PW}
  127. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /users/${T_USERNAME} realname ${REALNAME}
  128. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /users/${T_USERNAME} uid ${T_UID}
  129. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /users/${T_USERNAME} gid ${T_GID}
  130. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /users/${T_USERNAME} shell /bin/${T_SHELL}
  131. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /users/${T_USERNAME} home ${T_HOMEDIR}
  132. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /groups/${T_USERNAME} name ${T_USERNAME}
  133. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /groups/${T_USERNAME} gid ${T_GID}
  134. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /groups/${T_USERNAME} passwd "*"
  135.  
  136. if [ "$ADMIN_USER" == "1" ]; then
  137. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /groups/admin users ${T_USERNAME}
  138. fi
  139.  
  140. mkdir -p ${TARGET_MOUNT}/${T_HOMEDIR}
  141. chown ${T_UID}:${T_GID} ${TARGET_MOUNT}/${T_HOMEDIR}
  142. echo "User ${T_USERNAME} created"
  143. echo ""
  144.  
  145. if [ "$T_UID" == "$T_UID_DEFAULT" ]; then
  146. T_UID_DEFAULT=$(($T_UID_DEFAULT+1))
  147. T_GID_DEFAULT=$(($T_GID_DEFAULT+1))
  148. fi
  149. fi
  150. }
  151.  
  152. # and a way to iterate through the list of available services
  153. # with a method to initialize them
  154. enable_various_services() {
  155.  
  156. echo "Following services can be enabled: "
  157. chroot ${TARGET_MOUNT} /sbin/service --list
  158.  
  159. while [ 1 ]; do
  160. echo -n "Enter service to enabled ('quit' to abort, list to print list): "
  161. read SERVICE
  162. if [ "$SERVICE" == "quit" ]; then
  163. break
  164. fi
  165. if [ "$SERVICE" == "list" ]; then
  166. chroot ${TARGET_MOUNT} /sbin/service --list
  167. else
  168. echo "Enabling service: ${SERVICE}"
  169. sed -e 's/disable.*=.*yes/disable = no/' < ${TARGET_MOUNT}/etc/xinetd.d/${SERVICE} > ${TARGET_MOUNT}/etc/xinetd.d/${SERVICE}.new
  170. mv ${TARGET_MOUNT}/etc/xinetd.d/${SERVICE}.new ${TARGET_MOUNT}/etc/xinetd.d/${SERVICE}
  171. fi
  172. done
  173. }
  174.  
  175. choose_filesystem_type () {
  176. while [ 1 ]; do
  177. echo "Choose the filesystem type from the following."
  178. echo " hfs) HFS+ (journaled) filesystem"
  179. echo " ufs) UFS filesystem"
  180. echo -n "Filesystem type: "
  181. read FILESYSTEMTYPE
  182. if [ "$FILESYSTEMTYPE" == "hfs" -o "$FILESYSTEMTYPE" == "ufs" ]; then
  183. break
  184. fi
  185. done
  186. }
  187.  
  188. # This function will nuke the whole disk and create the 0xAB and 0xA8
  189. # partitions. $INSTALLDEV and $RAWINSTDEV need to be set to the
  190. # device to nuke, and the corresponding raw device.
  191. partition_disk () {
  192. # needs help on ppc
  193. echo "Partitioning disk ${INSTALLDEV} using filesystem type ${FILESYSTEMTYPE}"
  194. echo "Warning: this will destroy all data on the disk!"
  195. echo -n "Continue? (y/n) "
  196. read CONT
  197.  
  198. if [ "${CONT}" == "y" -o "${CONT}" == "yes" ]; then
  199. fdisk -i -y -a ${FILESYSTEMTYPE} ${RAWINSTDEV}
  200. else
  201. abort
  202. fi
  203.  
  204. }
  205.  
  206. # This will look for partitions on the selected disk, and
  207. # allow the user to select the 0xA8 partitions to use.
  208. # $INSTALLDEV needs to be set to the device to look for,
  209. # and $ROOTPART will be set to the chosen value upon return.
  210. use_partitions () {
  211. echo ""
  212. PARTS=`ls -1 ${INSTALLDEV}s*`
  213.  
  214. echo "The following partitions are available:"
  215. for devs in ${PARTS}
  216. do
  217. echo ${devs}
  218. done
  219.  
  220. ROOTPART=""
  221. until [[ ${ROOTPART} != "" && -b ${ROOTPART} ]]
  222. do
  223. echo "Which will be the root partition?"
  224. read ROOTPART
  225. done
  226.  
  227. echo "Using: "
  228. echo "${ROOTPART} as the root partition"
  229.  
  230. }
  231.  
  232. # This just runs fdisk interactivly on the chosen raw install device
  233. run_fdisk () {
  234. echo "Starting fdisk"
  235. if [ "${ARCH}" == "i386" ]; then
  236. fdisk -e ${RAWINSTDEV}
  237. elif [ "${ARCH}" == "ppc" ]; then
  238. /usr/sbin/pdisk
  239. fi
  240. }
  241.  
  242. install_booter () {
  243. if [ "${ARCH}" == "i386" ]; then
  244. cd /
  245. umount -f ${ROOTPART}
  246. RAWROOTPART=`echo ${ROOTPART} | sed 's/disk/rdisk/'`
  247. if [ "${FILESYSTEMTYPE}" == "ufs" ]; then
  248. dd if=/usr/standalone/i386/boot1u of=${RAWROOTPART} bs=512 count=15 >>/dev/null 2>&1
  249. elif [ "${FILESYSTEMTYPE}" == "hfs" ]; then
  250. dd if=/usr/standalone/i386/boot1h of=${RAWROOTPART} bs=512 count=1 >>/dev/null 2>&1
  251. /usr/sbin/startupfiletool ${RAWROOTPART} /usr/standalone/i386/boot >/dev/null 2>&1
  252. bless -device ${ROOTPART} -setBoot >/dev/null 2>&1
  253. fi
  254. mount -t ${FILESYSTEMTYPE} ${ROOTPART} ${TARGET_MOUNT}
  255. bless -mount ${TARGET_MOUNT} -setBoot >/dev/null 2>&1
  256. cd ${TARGET_MOUNT}
  257. elif [ "${ARCH}" == "ppc" ]; then
  258. bless -folder ${TARGET_MOUNT}/System/Library/CoreServices -folder9 ${TARGET_MOUNT}/System/Library/CoreServices -bootinfo ${TARGET_MOUNT}/usr/standalone/ppc/bootx.bootinfo -setBoot
  259. fi
  260. }
  261.  
  262. install_packages () {
  263. VOLUMENAME="Darwin"
  264.  
  265. echo "WARNING: answering "yes" here will destroy all data on the partition"
  266. until [ ! : ]
  267. do
  268. echo -n "Would you like to do a clean install? (yes/no)"
  269. read ANSWER
  270. if [ "$ANSWER" == "yes" ]; then
  271. echo -n "Desired Volumename: "
  272. read VOLUMENAME
  273.  
  274. echo "Creating ${FILESYSTEMTYPE} Filesystem on ${ROOTPART}"
  275. if [ "${FILESYSTEMTYPE}" == "hfs" ]; then
  276. newfs_hfs -J -v "${VOLUMENAME}" ${ROOTPART} >> /dev/null 2>&1
  277. break
  278. elif [ "${FILESYSTEMTYPE}" == "ufs" ]; then
  279. newfs -v "${VOLUMENAME}" ${ROOTPART} >> /dev/null 2>&1
  280. break
  281. else
  282. echo "error: nknown filesystem type: $FILESYSTEMTYPE"
  283. abort
  284. fi
  285. elif [ "$ANSWER" == "no" ]; then
  286. break
  287. fi
  288. done
  289. mount -t ${FILESYSTEMTYPE} ${ROOTPART} ${TARGET_MOUNT}
  290. cd ${TARGET_MOUNT}
  291. echo "Installing packages on ${ROOTPART}"
  292. for f in /System/Installation/Packages_${ARCH}/files-*.tar.bz2 \
  293. /System/Installation/Packages_${ARCH}/*-*.tar.bz2 \
  294. /System/Installation/BinaryDrivers_${ARCH}/*-*.tar.bz2 ; do
  295. echo "Uncompressing $(basename $f)"
  296. tar xjpf $f 2>/dev/null
  297. if [ "$?" != "0" ]; then
  298. echo "warning: error during extraction"
  299. fi
  300. done
  301.  
  302. cd /
  303. }
  304.  
  305. main() {
  306.  
  307. if [ -f "/Release Notes.txt" ]; then
  308. echo ""
  309. echo "Welcome to the installation of" `grep 'Darwin [0-9.-]*' /Release\ Notes.txt | head -1 | awk '{print $1" "$2}'`
  310. echo ""
  311. fi
  312. if [ -f "/Important Notice.txt" ]; then
  313. cat "/Important Notice.txt"
  314. fi
  315.  
  316. # Get the device the user wants to install onto.
  317. INSTALLDEV="novalue"
  318. until [[ ${INSTALLDEV} != "" && -b ${INSTALLDEV} ]]
  319. do
  320. echo "The following devices are available for installation:"
  321. until [[ ! -z "${FOO}" ]]
  322. do
  323. FOO=`iofindwholemedia`
  324. done
  325. iofindwholemedia
  326. echo "Enter 'shell' to drop into a shell"
  327. echo -n "Which device would you like to install Darwin onto? "
  328. read INSTALLDEV
  329.  
  330. if [ "${INSTALLDEV}" == "shell" ]; then
  331. exec /bin/sh
  332. fi
  333.  
  334. INSTALLDEV=`iofindwholemedia ${INSTALLDEV}`
  335.  
  336. if [ ! -b "${INSTALLDEV}" ]; then
  337. echo ""
  338. echo "${INSTALLDEV} doesn't exist, please enter one of the listed devices."
  339. echo ""
  340. fi
  341. done
  342.  
  343. RAWINSTDEV=`echo ${INSTALLDEV} | sed 's/disk/rdisk/'`
  344.  
  345.  
  346. if [ "${ARCH}" == "i386" ]; then
  347. if fdisk -t ${RAWINSTDEV} ; then
  348. echo ""
  349. echo "For partitioning the disk, you have the following choices:"
  350. until [ ! : ]
  351. do
  352. echo "1) Auto-partition the disk (Destroys all disk contents)"
  353. echo "2) Manually partition the disk using fdisk"
  354. echo "3) Use existing partitions"
  355. echo -n "Choice: "
  356. read ANSWER
  357. case ${ANSWER} in
  358. 1) choose_filesystem_type
  359. partition_disk
  360. # Don't ask which to use, since we already know.
  361. ROOTPART="${INSTALLDEV}s1"
  362. break
  363. ;;
  364. 2) run_fdisk
  365. use_partitions
  366. choose_filesystem_type
  367. break
  368. ;;
  369. 3) use_partitions
  370. choose_filesystem_type
  371. break
  372. ;;
  373. esac
  374. done
  375. else
  376. echo ""
  377. echo "For partitioning the disk, you have the following choices:"
  378. until [ ! : ]
  379. do
  380. echo "1) Auto-partition the disk (Destroys all disk contents)"
  381. echo "2) Manually partition the disk using fdisk"
  382. echo -n "Choice: "
  383. read ANSWER
  384. case ${ANSWER} in
  385. 1) partition_disk
  386. # Don't ask which to use, since we already know.
  387. ROOTPART="${INSTALLDEV}s1"
  388. break
  389. ;;
  390. 2) run_fdisk
  391. use_partitions
  392. break
  393. ;;
  394. esac
  395. done
  396. fi
  397. elif [ "${ARCH}" == "ppc" ]; then
  398. until [ ! : ]
  399. do
  400. FILESYSTEMTYPE="hfs"
  401. echo "Which (Apple_HFS) partition would you like to install into: "
  402. pdisk --list ${INSTALLDEV} 2> /dev/null
  403. slice=""
  404. until [[ "$slice" != "" && -b ${INSTALLDEV}s${slice} ]]
  405. do
  406. echo -n "Your choice: "
  407. read slice
  408. done
  409. ROOTPART="${INSTALLDEV}s${slice}"
  410. break
  411. done
  412. fi
  413. install_packages
  414. install_booter
  415. echo 'LANGUAGE=English' > ${TARGET_MOUNT}/var/log/CDIS.custom
  416. echo "Updating mkext cache"
  417. export TMPDIR=${TARGET_MOUNT}/private/tmp
  418. kextcache -K ${TARGET_MOUNT}/mach_kernel -a ${ARCH} -m ${TARGET_MOUNT}/System/Library/Extensions.mkext ${TARGET_MOUNT}/System/Library/Extensions 2>/dev/null
  419. export -n TMPDIR
  420.  
  421. echo "Creating root user"
  422.  
  423. # loop until password was entered the same twice
  424. while [ 1 ]; do
  425. ROOT_PW=`openssl passwd`
  426. if [ ${?} == "0" ]; then
  427. break
  428. fi
  429. done
  430.  
  431. nicl -raw ${TARGET_MOUNT}/var/db/netinfo/local.nidb -create /users/root passwd ${ROOT_PW}
  432.  
  433. echo -n "Set computer name (Bonjour hostname): "
  434. read BONJOUR
  435. configd
  436. echo "$BONJOUR" | chroot ${TARGET_MOUNT} scutil --set ComputerName
  437. echo "$BONJOUR" | tr A-Z a-z | sed -e 's/[^a-z0-9_-][^a-z0-9_-]*/-/g' | chroot ${TARGET_MOUNT} scutil --set LocalHostName
  438.  
  439. echo "Configuring emacs"
  440. chroot ${TARGET_MOUNT} /usr/libexec/dumpemacs > /dev/null 2>&1
  441.  
  442. finishup
  443. }
  444.  
  445. # Set the erase character properly
  446. # This is only for telnet consoles...
  447. #stty erase 
  448.  
  449. # Ignore ^C
  450. #trap "" 2
  451.  
  452. main
  453.  
  454. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement