From 2c09e0dc7f7c8401c3ee131f65147b2ddb4b8279 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 5 Aug 2020 12:52:04 +0200 Subject: [PATCH] Installer: separate writing bootsector from other install finishing code Remove the InstallerInitScript (it does nothing) and the InstallerFinishScript (it does too many things). Instead implement the finishing directly in Installer. Separate writing the bootsector, so that the "write bootsector" menu writes only the bootsector. Fixes #16303 --- build/jam/packages/Haiku | 3 +- build/jam/packages/HaikuBootstrap | 3 +- data/system/boot/InstallerFinishScript | 21 -------------- data/system/boot/InstallerInitScript | 5 ---- src/apps/installer/WorkerThread.cpp | 37 +++++++++++-------------- src/apps/installer/WorkerThread.h | 2 +- src/tests/apps/installer/CopyEngine.cpp | 28 ------------------- src/tests/apps/installer/CopyEngine.h | 2 -- 8 files changed, 19 insertions(+), 82 deletions(-) delete mode 100644 data/system/boot/InstallerFinishScript delete mode 100644 data/system/boot/InstallerInitScript diff --git a/build/jam/packages/Haiku b/build/jam/packages/Haiku index 9d4de494ec..d5828d7b7c 100644 --- a/build/jam/packages/Haiku +++ b/build/jam/packages/Haiku @@ -121,8 +121,7 @@ AddSymlinkToPackage bin : trash : untrash ; AddSymlinkToPackage bin : less : more ; # scripts and data files -local bootScripts = PostInstallScript SetupEnvironment - InstallerInitScript InstallerFinishScript ; +local bootScripts = PostInstallScript SetupEnvironment ; SEARCH on $(bootScripts) = [ FDirName $(HAIKU_TOP) data system boot ] ; AddFilesToPackage boot : $(bootScripts) ; diff --git a/build/jam/packages/HaikuBootstrap b/build/jam/packages/HaikuBootstrap index 40719b95fd..2bea48e1ac 100644 --- a/build/jam/packages/HaikuBootstrap +++ b/build/jam/packages/HaikuBootstrap @@ -115,8 +115,7 @@ AddSymlinkToPackage bin : trash : untrash ; AddSymlinkToPackage bin : less : more ; # scripts and data files -local bootScripts = PostInstallScript SetupEnvironment - InstallerInitScript InstallerFinishScript ; +local bootScripts = PostInstallScript SetupEnvironment ; SEARCH on $(bootScripts) = [ FDirName $(HAIKU_TOP) data system boot ] ; AddFilesToPackage boot : $(bootScripts) ; diff --git a/data/system/boot/InstallerFinishScript b/data/system/boot/InstallerFinishScript deleted file mode 100644 index db50477984..0000000000 --- a/data/system/boot/InstallerFinishScript +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -## The installer finish script. - -target=$1 - -if [ -z "$target" ]; then - echo "Usage: $0 " - exit 1 -fi - -if [ ! -d "$target" ]; then - echo "$target isn't mounted" - exit 1 -fi - -mkdir -p "$target/system/cache/tmp" - -# remove Installer link -rm -f "$target/home/Desktop/Installer" - -makebootable "$target" diff --git a/data/system/boot/InstallerInitScript b/data/system/boot/InstallerInitScript deleted file mode 100644 index 373d9cdb79..0000000000 --- a/data/system/boot/InstallerInitScript +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -## The installer init script. - - - diff --git a/src/apps/installer/WorkerThread.cpp b/src/apps/installer/WorkerThread.cpp index 4c8acff668..528db15668 100644 --- a/src/apps/installer/WorkerThread.cpp +++ b/src/apps/installer/WorkerThread.cpp @@ -227,7 +227,7 @@ WorkerThread::MessageReceived(BMessage* message) } } - if (_LaunchFinishScript(targetDirectory) != B_OK) { + if (_WriteBootSector(targetDirectory) != B_OK) { _SetStatusMessage( B_TRANSLATE("Error writing boot sector.")); break; @@ -304,17 +304,13 @@ WorkerThread::WriteBootSector(BMenu* targetMenu) status_t -WorkerThread::_LaunchInitScript(BPath &path) +WorkerThread::_WriteBootSector(BPath &path) { BPath bootPath; find_directory(B_BEOS_BOOT_DIRECTORY, &bootPath); - BString command("/bin/sh "); - command += bootPath.Path(); - command += "/InstallerInitScript "; - command += "\""; - command += path.Path(); - command += "\""; - _SetStatusMessage(B_TRANSLATE("Starting installation.")); + BString command; + command.SetToFormat("makebootable \"%s\"", path.Path()); + _SetStatusMessage(B_TRANSLATE("Writing bootsector.")); return system(command.String()); } @@ -322,15 +318,14 @@ WorkerThread::_LaunchInitScript(BPath &path) status_t WorkerThread::_LaunchFinishScript(BPath &path) { - BPath bootPath; - find_directory(B_BEOS_BOOT_DIRECTORY, &bootPath); - BString command("/bin/sh "); - command += bootPath.Path(); - command += "/InstallerFinishScript "; - command += "\""; - command += path.Path(); - command += "\""; _SetStatusMessage(B_TRANSLATE("Finishing installation.")); + + BString command; + command.SetToFormat("mkdir -p \"%s/system/cache/tmp\"", path.Path()); + if (system(command.String()) != 0) + return B_ERROR; + + command.SetToFormat("rm -f \"%s/home/Desktop/Installer\"", path.Path()); return system(command.String()); } @@ -489,10 +484,6 @@ WorkerThread::_PerformInstall(partition_id sourcePartitionID, CopyEngine engine(&reporter, &entryFilter); BList unzipEngines; - err = _LaunchInitScript(targetDirectory); - if (err != B_OK) - return _InstallationError(err); - // Create the default indices which should always be present on a proper // boot volume. We don't care if the source volume does not have them. // After all, the user might be re-installing to another drive and may @@ -579,6 +570,10 @@ WorkerThread::_PerformInstall(partition_id sourcePartitionID, if (err != B_OK) return _InstallationError(err); + err = _WriteBootSector(targetDirectory); + if (err != B_OK) + return _InstallationError(err); + err = _LaunchFinishScript(targetDirectory); if (err != B_OK) return _InstallationError(err); diff --git a/src/apps/installer/WorkerThread.h b/src/apps/installer/WorkerThread.h index acc27df69a..9a587cfcdd 100644 --- a/src/apps/installer/WorkerThread.h +++ b/src/apps/installer/WorkerThread.h @@ -39,7 +39,7 @@ public: void WriteBootSector(BMenu* dstMenu); private: - status_t _LaunchInitScript(BPath& path); + status_t _WriteBootSector(BPath& path); status_t _LaunchFinishScript(BPath& path); status_t _PerformInstall(partition_id sourcePartitionID, diff --git a/src/tests/apps/installer/CopyEngine.cpp b/src/tests/apps/installer/CopyEngine.cpp index 6dcf328eb1..13380dfc0e 100644 --- a/src/tests/apps/installer/CopyEngine.cpp +++ b/src/tests/apps/installer/CopyEngine.cpp @@ -55,34 +55,6 @@ CopyEngine::SetStatusMessage(char *status) } -void -CopyEngine::LaunchInitScript(BPath &path) -{ - BPath bootPath; - find_directory(B_BEOS_BOOT_DIRECTORY, &bootPath); - BString command("/bin/sh "); - command += bootPath.Path(); - command += "/InstallerInitScript "; - command += path.Path(); - SetStatusMessage("Starting Installation."); - system(command.String()); -} - - -void -CopyEngine::LaunchFinishScript(BPath &path) -{ - BPath bootPath; - find_directory(B_BEOS_BOOT_DIRECTORY, &bootPath); - BString command("/bin/sh "); - command += bootPath.Path(); - command += "/InstallerFinishScript "; - command += path.Path(); - SetStatusMessage("Finishing Installation."); - system(command.String()); -} - - void CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu) { diff --git a/src/tests/apps/installer/CopyEngine.h b/src/tests/apps/installer/CopyEngine.h index 7cd7671f13..f174e1e604 100644 --- a/src/tests/apps/installer/CopyEngine.h +++ b/src/tests/apps/installer/CopyEngine.h @@ -26,8 +26,6 @@ public: void SetPackagesList(BList *list); void SetSpaceRequired(off_t bytes) { fSpaceRequired = bytes; }; private: - void LaunchInitScript(BPath &path); - void LaunchFinishScript(BPath &path); void CopyFolder(BDirectory &srcDir, BDirectory &targetDir); InstallerWindow *fWindow;