Jump to content

Shell scripting help please!


  • Please log in to reply
4 replies to this topic

#1
~pcwiz

~pcwiz

    InsanelyMac V.I.P.

  • Retired
  • 5,900 posts
  • Gender:Male
Hi all,

For my app, OSx86 Tools, there is a Boot Editor function that launches a shell script in Terminal with prompts to modify your com.apple.boot.plist file with different flags. Here is the script:

#!/bin/sh
# Script by eddie11c
echo "This will create a new Boot.plist. The old one will be backed up as com.apple.Boot.plist.orig"
			cp -Rf "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist" "/Library/Preferences/SystemConfiguration/com.apple.Boot.orig.plist"
			pl=$( cat "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist" | sed -n 8p | sed 's_<string>__' | sed 's_</string>__' )
			cT=$( cat "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist" | sed -n 10p | sed 's_<string>__' | sed 's_</string>__' )
			Graph=$( cat "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist" | sed -n 14p | sed 's_<string>__' | sed 's_</string>__' )
			EF=$( cat "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist" | sed -n 16p | sed 's_<string>__' | sed 's_</string>__' )
			echo "Current Kernel Flags: ${pl}"
			echo "Please type all kernel flags you wish to use, this will replace any currently there. Be sure to format correctly with a space between each.(Example: -v -x)"
			read Num1
			echo "Do you want Quiet Boot?(y/n) This will ignore the Timeout option and Kernel Flag -v."
			read Num4
			while [[ ${Num4} != "n" && ${Num4} != "y" ]]
			do
				echo "Invalid choice, please enter y for yes or n for no. Do you want Quiet Boot?(y/n)"
				read Num4
			done
			echo "Please enter how many seconds you wish the Timeout to be."
			read Num2
			echo "If you want to set Graphics Mode, please enter resolution/depth. Example:1280x1024x32. To turn off leave blank."
			read Num5
			echo "Please enter your EFI string. Leave blank to use none."
			read Num3
			cd /Library/Application\ Support/OSx86\ Tool
			if [[ ${Num4} = "y" ]]; then
				QB="yes"
				echo "Quiet Boot turned on."
				Num2=""
				Num6=$( echo ${Num1} | sed 's/-v //' | sed 's/-v//')
			else
				QB=""
				Num6=${Num1}
			fi
			plis=$( cat test.txt | sed "s/KF/${Num6}/" | sed "s/QB/${QB}/" | sed "s/GM/${Num5}/" |sed "s/SE/${Num2}/" | sed "s/EF/${Num3}/" > test1.txt )
			if [[ ${Num3} = "" ]]; then
				cat test1.txt | sed -e 15,16d > test2.txt
			else
				cp test1.txt test2.txt
			fi
			if [[ ${Num5} = "" ]];then
				cat test2.txt | sed -e 13,14d > test3.txt
			else
				cp test2.txt test3.txt
			fi
			if [[ ${Num4} = "n" ]]; then
				cat test3.txt | sed -e 11,12d > test4.txt
			else
				cp test3.txt test4.txt
			fi
			if [[ ${QB} = "yes" ]]; then
				cat test4.txt | sed -e 9,10d > test5.txt
			else
				cp test4.txt test5.txt
			fi
			echo "Kernel Flags: ${Num6}"
			echo "Timeout: ${Num2}"
			echo "Graphics Mode: ${Num5}"
			echo "EFI string: ${Num3}"
			cp "test5.txt" "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
			chown -R root:admin "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
			chmod -R 644 "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
			plist=$( cat "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist" )
			echo ""
			echo "Here is your new com.apple.Boot.plist file:"
			echo ""
			echo "${plist}"
			rm -Rf "test1.txt"
			rm -Rf "test2.txt"
			rm -Rf "test3.txt"
			rm -Rf "test4.txt"
			rm -Rf "test5.txt"
			exit 0

As you can see, eddie11c wrote the script, but he is currently busy and doesn't have the time to fix it up so I ask the community's shell scripting gurus to help fix this. This is the only thing preventing OSx86 Tools from going to final release. There are two problems that need to be fixed with this:

1) In the "Please enter your EFI string. Leave blank to use none." prompt, you can enter the string to be inserted into the com.apple.boot.plist file. The problem is, the characters cut off at I think 1023 characters, so only part of the EFI string gets inputted. This is the first thing that needs to be fixed.

2) After every prompt, the script saves and makes the modifications to the com.apple.boot.plist file. This is dangerous since if you quit the script in the middle of the wizard it will corrupt the plist. This needs to be fixed so that all the modifications are made at the end, after a confirmation prompt.

If anyone could help with either of those two, it would be much appreciated!

#2
ColdStart

ColdStart

    InsanelyMac Protégé

  • Members
  • Pip
  • 29 posts
  • Gender:Male
I'll take a try at both problems.
A likely fix for the first problem would be to use an alternative scripting language that is guaranteed to be installed, such as Perl (used in many official Apple installers.)
I'll probably have a finished script by tomorrow.

#3
~pcwiz

~pcwiz

    InsanelyMac V.I.P.

  • Retired
  • 5,900 posts
  • Gender:Male
Thanks ColdStart, the help is much appreciated! ;) The type of script doesn't really matter as long as it can be executed from within Terminal ;)

#4
ColdStart

ColdStart

    InsanelyMac Protégé

  • Members
  • Pip
  • 29 posts
  • Gender:Male
All finished. I sent you a link to the code via PM.
If you require any changes please let me know!

#5
~pcwiz

~pcwiz

    InsanelyMac V.I.P.

  • Retired
  • 5,900 posts
  • Gender:Male
Thanks a ton ColdStart, it works great :)

EDIT: One small bug I found while testing, I pmed you about it :rolleyes:





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy