;convert ModAS c_Prepare to user-startup
;derive Startup-sequence from a_Init throughout e_WB
failat 30
cd SYS:

; re-enable original Amiga-Startup
; disable ModAS completely

assign >NIL: EASys!_bin: exists
if not warn
 copy EASys!_bin:swipe T: CLONE QUIET
 copy EASys!_bin:CLIexchange T: CLONE QUIET
 copy EASys!_rexx:remoteed.rexx T: CLONE QUIET
endif

if $LANGUAGE eq "deutsch"
 echo "*ec*n*n*e[1m Startup-Sequence und user-startup rekonstruieren:*e[0m"
 echo "*n*n Fortsetzen?" NOLINE
else
 echo "*ec*n*n*e[1m Reconstruction of standard startup from ModAS*e[0m"
 echo "*n*n Continue?" NOLINE
endif

ask " [y/n] n "
if not warn
 skip functional
endif

if $LANGUAGE eq "deutsch"
 echo " Wirklich? ModAS ist nützlicher als Du denkst ;)" NOLINE
else
 echo " Really? ModAS is great ;)" NOLINE
endif

ask " [y/n] n "
if not warn
 skip functional
endif

LAB menu
if $LANGUAGE eq "deutsch"
 echo "*ec*n*n*e[1m Startup-Sequence und user-startup rekonstruieren:*e[0m"
 echo " [1] Aus den Backup Dateien der startup-sequence und der user-startup,"
 echo "     die vor der ModAS Installation automatisch erzeugt wurden?"
 echo " [2] Aus der derzeitigen ModAS Boot Sequenz. Wird benötigt, wenn"
 echo "     seit der ModAS Installation grundlegende Änderungen am Systemstart"
 echo "     durchgeführt wurden (z.B. durch Programminstallationen)."
 echo " [e] Exit "
 echo "*n Eingabe: " NOLINE
else
 echo "*ec*n*e[1m Reconstruct startup-sequence and user-startup:*e[0m"
 echo " [1] From startup-sequence and user-startup backup files,"
 echo "     which have been created before ModAS was installed?"
 echo " [2] From current ModAS boot sequence (needed when significant"
 echo "     changes have been done to the startup since ModAS"
 echo "     installation)"
 echo " [e] Exit"
 echo "*n Choice: " NOLINE
endif

set >NIL: input ?

if "$input" eq "e"
 skip functional
endif

if "$input" eq "1"
 execute SYS:StartSys/StartupStandard
 quit
endif

if not "$input" eq "2"
 skip menu back
endif

T:cliexchange MultiNotify KILL

;remove things coupled directly to modas first
delete sys:startsys/b_gui/#?_LOGIN QUIET
delete sys:startsys/b_gui/#?sayhello QUIET
delete sys:startsys/b_gui/#?User_env QUIET
delete sys:startsys/b_gui/#?BootScreenStart QUIET
delete sys:startsys/d_system/#?User_Icons QUIET
delete sys:startsys/d_system/#?User_WBstartup QUIET
delete sys:startsys/e_wb/#?ModAS_deamon QUIET
delete sys:startsys/e_wb/#?sayready QUIET
delete sys:startsys/e_wb/#?CleanUp QUIET
delete sys:startsys/b_gui/#?BootScreenClose QUIET

;convert startup-sequence
if exists T:SSeq_core
 delete T:SSeq_core T:SSeq_Begin T:SSeq_End QUIET
endif

copy s:startup-sequence t: CLONE QUIET
rx T:remoteed.rexx movetext T:startup-sequence "sTaRt" "~~;BEGIN ModAS" T:SSeq_Begin
rx T:remoteed.rexx movetext T:startup-sequence "~~;END ModAS" "§§##" T:SSeq_End

echo >T:tmpscript_a "failat 30"
list sys:startsys/a_Init/~(_#?) >>T:tmpscript_a FILES LFORMAT "type >>T:SSeq_core *"%s%s*"*n"
sort T:tmpscript_a to T:sseq_a

echo >T:tmpscript_a "failat 30"
list sys:startsys/b_GUI/~(_#?) >>T:tmpscript_a FILES LFORMAT "type >>T:SSeq_core *"%s%s*"*n"
sort T:tmpscript_a to T:sseq_b

echo >T:sseq_c "echo >>T:SSeq_core *"**nif exists s:user-startup**n execute s:user-startup**nendif**n*""

echo >T:tmpscript_a "failat 30"
list sys:startsys/d_System/~(_#?) >>T:tmpscript_a FILES LFORMAT "type >>T:SSeq_core *"%s%s*"*n"
sort T:tmpscript_a to T:sseq_d

echo >T:tmpscript_a "failat 30"
list sys:startsys/e_WB/~(_#?) >>T:tmpscript_a FILES LFORMAT "type >>T:SSeq_core *"%s%s*"*n"
sort T:tmpscript_a to T:sseq_e

join T:sseq_a T:sseq_b T:sseq_c T:sseq_d T:sseq_e AS T:conv_sseq.script
execute T:conv_sseq.script

join T:sseq_Begin T:sseq_core T:sseq_End AS T:NewSSeq
echo >>T:NewSSeq "*nEndCLI >NIL:"
rx T:remoteed.rexx movetext T:NewSSeq "ModAS" "1LiNe" T:Trash

delete T:sseq_#? T:tmpscript_a T:conv_sseq.script T:Trash FORCE QUIET

;convert User-Startup
if exists T:NewUserStartup
 delete T:NewUserStartup QUIET
endif

echo >T:tmpscript_a "failat 30"
list sys:startsys/c_prepare/~(_#?) >T:tmpscript_a FILES LFORMAT "execute T:tmpscript_b *"%s%s*" *"%n*""
sort T:tmpscript_a to T:conv_users.script

echo >T:tmpscript_b ".key file,name*nfailat 30"
echo >>T:tmpscript_b "echo >>T:NewUserStartup *";BEGIN <name>*"*ntype >>T:NewUserStartup *"<file>*"*necho >>T:NewUserStartup *";END <name>**n*"*n"

execute T:conv_users.script
delete T:conv_users.script T:tmpscript_a T:tmpscript_b QUIET

;Replace Startup Files now
if not exists s:user-startup.modas
 copy s:user-startup s:user-startup.modas CLONE QUIET
endif
copy T:NewUserStartup S:User-Startup CLONE QUIET

if not exists s:startup-sequence.modas
 copy s:startup-sequence s:startup-sequence.modas CLONE QUIET
endif
copy T:NewSSeq S:Startup-sequence CLONE QUIET

;Cleanup
delete T:tmpscript_a T:tmpscript_b T:NewUserStartup T:NewSSeq QUIET

assign profile: REMOVE
path SYS:StartSys REMOVE
path SYS:StartSys/bin REMOVE

;restart MultiNotify for Standard startup
copy SYS:StartSys/StartupStandard.MultiNotify ENVARC:MultiNotify.prefs CLONE QUIET
copy SYS:StartSys/StartupStandard.MultiNotify ENV:MultiNotify.prefs CLONE QUIET
run >NIL: EASys!_bin:MultiNotify

T:swipe >NIL: SYS:StartSys FORCE ALL QUIET
T:swipe >NIL: SYS:ShutDown FORCE ALL QUIET
delete SYS:StartSys.info SYS:ShutDown.info FORCE QUIET

delete SYS:StartSys/ModAS_activated FORCE QUIET
delete envarc:LoggedLast env:LoggedLast FORCE QUIET
delete envarc:LoggedPrevious env:LoggedPrevious FORCE QUIET

if $LANGUAGE eq "deutsch"
 echo "*n*n*e[1m Standard Startup rekonstruiert.*e[0m"
 echo "*n Da das neue StandardStartup vom installierten ModAS Startup"
 echo " erzeugt wurde, wird es länger als die ursprüngliche startup-sequence"
 echo " sein. Als Referenz zum ursprünglichen Startup wurde vor ModAS Installation"
 echo " automatisch folgende Kopie erzeugt:  S:Startup-sequence.before_ModAS"
 echo " sowie:  S:User-Startup.before_ModAS. Zu eventuellen Klärungen stehen"
 echo " diese beiden Dateien zur Verfügung."

 echo "*n Um wieder einen ModAS Startup zu erhalten, starte bitte"
 echo " wieder den ModAS Installer oder den Installer mit welchem"
 echo " ModAS installiert wurde.*n"
else
 echo "*n*n*e[1m Standard Startup reconstructed.*e[0m"
 echo "*n Since the new standard startup has been derived from the installed"
 echo " ModAS System, it may be longer than your original startup-sequence."
 echo " Consult S:Startup-sequence.before_ModAS - being a backup of your"
 echo " original startup file which was the base for creating ModAS."

 echo "*n To obtain ModAS Startup again, please restart the ModAS Installer"
 echo " or the Installer which included ModAS Installation again.*n"
endif

skip End

Lab functional
echo "*n*n*e[1m ModAS remains functional*e[0m*n"

Lab End
delete >NIL: T:swipe T:cliexchnage T:remoteed.rexx FORCE QUIET

