~pcwiz Posted March 4, 2008 Share Posted March 4, 2008 OK, So I want to create a simple preinstall bash script to go along with my PackageMaker project that will back up the kernel and then remove it to allow the installation of a new kernel. Here is my script: #!/bin/bash cp -r /mach_kernel /P35Backup/ rm -r /mach_kernel Would that be correct? And what extension would I save it in to allow me to import it into PackageMaker? .sh shell script extension? Thanks ~pcwis Link to comment https://www.insanelymac.com/forum/topic/91578-bash-scripts/ Share on other sites More sharing options...
stroke Posted March 4, 2008 Share Posted March 4, 2008 I would do: #!/bin/bash mkdir /P35Backup/ cp /mach_kernel /P35Backup rm -rf /mach_kernel Extension isn't even needed, however make sure to chmod the shell script +x. Link to comment https://www.insanelymac.com/forum/topic/91578-bash-scripts/#findComment-653281 Share on other sites More sharing options...
~pcwiz Posted March 4, 2008 Author Share Posted March 4, 2008 So just save the script as plain text and import it? How would I chmod it? Like this?: chmod +x ~/Desktop/script.sh Thx EDIT: Also, do I need to add "exit 0" to the end of the script? I saw this being done. EDIT2: So I made a sample script just to check if I was doing things right: !#/bin/bash mkdir /P35Backup/ cp /mach_kernel /P35Backup I save it as script.sh on the Desktop. Then I go to terminal and chmod it: chmod +x ~/Desktop/script.sh Then I run the script from within Terminal sudo ~/Desktop/script.sh The script is executed properly and P35Backup is made, mach kernel is copied and all but I get this warning in Terminal: script.sh: line 1: !#/bin/bash: No such file or directory Like I mean the script works, but I get that. Is that anything to worry about? EDIT3: AHA, I switched around the ! and the # and it works fine with no errors! AM I GOOD TO GO? :D Link to comment https://www.insanelymac.com/forum/topic/91578-bash-scripts/#findComment-653291 Share on other sites More sharing options...
Headrush69 Posted March 4, 2008 Share Posted March 4, 2008 AHA, I switched around the ! and the # and it works fine with no errors! AM I GOOD TO GO? :D You had it listed right in the first sample. (And don't say I told you it was !# ) No exit 0 is not required. Link to comment https://www.insanelymac.com/forum/topic/91578-bash-scripts/#findComment-653400 Share on other sites More sharing options...
Recommended Posts