#RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Fileversion=0.1 #AutoIt3Wrapper_Res_LegalCopyright=pyg for Framakey #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.13.13 (beta) Author: pyg @ framasoft dot net for Framasoft and Framakey Team License: GNU/GPL Script Function: Framaboot.exe will make your USB stick bootable (if syslinux config files are present) and allow you to choose the size of persistent disk (casper-rw) #ce ---------------------------------------------------------------------------- #include #include #include #include #include #include #include Dim $szDrive, $szDir, $szFName, $szExt, $description, $casper, $casperSize, $oldCasperSize, $free, $fs, $type, $volume, $wantedCasperSize, $wantedMakeBootable, $wantedCreateCasper $TestPath = _PathSplit(@ScriptFullPath, $szDrive, $szDir, $szFName, $szExt) ;_ArrayDisplay($TestPath,"Demo _PathSplit()") $casperPath="casper-rw" $ldlinuxPath="ldlinux.sys" $syslinuxPath="/syslinux/win32" $ddPath=$syslinuxPath&"/dd" Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Framaboot", 359, 282, 193, 125) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize") GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore") $LabelFramaboot = GUICtrlCreateLabel("Framaboot", 8, 0, 163, 42) GUICtrlSetFont($LabelFramaboot, 20, 400, 0, "Arial Black") $LabelDesc = GUICtrlCreateLabel("Framaboot permet", 8, 40, 389, 60) $GroupBoot = GUICtrlCreateGroup("Boot", 8, 104, 329, 49) $Makebootable = GUICtrlCreateCheckbox("Rendre le disque courant bootable", 16, 120, 225, 17) GUICtrlSetOnEvent($Makebootable, "MakebootableClick") GUICtrlCreateGroup("", -99, -99, 1, 1) $GroupCasper = GUICtrlCreateGroup("Disque persistant", 8, 160, 329, 65) $CreateCasper = GUICtrlCreateCheckbox("(re)créer un disque persistant (casper-rw) de", 16, 176, 225, 17) GUICtrlSetOnEvent($CreateCasper, "CreateCasperClick") $CasperSize = GUICtrlCreateInput("1200", 48, 195, 41, 21) GUICtrlSetOnEvent($CasperSize, "CasperSizeChange") $Mo = GUICtrlCreateLabel("Mo",95, 199, 200, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Go = GUICtrlCreateButton("Go !", 136, 240, 75, 25, 0) GUICtrlSetOnEvent($Go, "GoClick") $Label3 = GUICtrlCreateLabel("version : 0.1", 304, 8, 44, 14) GUICtrlSetFont($Label3, 6, 400, 0, "Arial") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Variables() SetVariables() While 1 Sleep(100) WEnd Func Variables() $volume=$szDrive $free = DriveSpaceFree( $volume ) $fs = DriveGetFileSystem( $volume ) $type = DriveGetType( $volume ) If FileExists($casperPath) Then $casper=true $oldCasperSize = Round(FileGetSize($casperPath)/1048576,0) Else $casper=false $oldCasperSize = 0 EndIf $description = "Framaboot permet de rendre votre clé Framakey Ubuntu-fr remix bootable"&@CRLF&"ainsi que de (re)créer un disque persistant."&@CRLF&@CRLF&"Attention : n'utilisez Framaboot que depuis votre clé USB !" $wantedCasperSize = GUICtrlRead($CasperSize) $wantedMakeBootable = BitAnd(GUICtrlRead($MakeBootable),$GUI_CHECKED) $wantedCreateCasper = BitAnd(GUICtrlRead($CreateCasper),$GUI_CHECKED) EndFunc Func SetVariables() GUICtrlSetData($LabelDesc, $description) ;If $casper=true Then GUICtrlSetData($Mo, "Mo ("& Round($free+$oldCasperSize-50,0)&"Mo disponibles)") ;Endif GUICtrlSetData($Makebootable, "Rendre le disque '"&$volume&"' bootable") EndFunc Func Checklist() if $wantedCreateCasper AND Not Number($wantedCasperSize) Then MsgBox(0, "Taille invalide", "Indiquez une taille en Mo pour le disque persistant") return False EndIf if $wantedCreateCasper=false AND $wantedMakeBootable=False Then MsgBox(0, "Aucune action demandée", "Vous n'avez demandée aucune action.") return False EndIf ; removable ? if ($type<>"Removable") Then MsgBox(0, "Type de disque non supporté", "Il semblerait que Framaboot ne soit pas executé depuis une clé USB."&@CRLF&"Pour des raisons de sécurité, la procédure va s'arrêter ici !") return false EndIf ;size $wantedCasperSize = GuiCtrlRead($casperSize) if $wantedCreateCasper AND ($wantedCasperSize > $free+$oldCasperSize-50) Then MsgBox(0, "Taille trop importante", "Indiquez une taille inférieure pour le disque persistant") return False EndIf Return True EndFunc Func Warning() $warning = "Les actions suivantes vont être effectuées :" & @CRLF If (FileExists($casperPath) AND ($wantedCreateCasper)) Then $warning &= "- suppression du disque persistant casper-rw actuel (toutes les données seront supprimées)" & @CRLF EndIf If ($wantedCreateCasper) Then $warning &= "- création d'un disque persistant de "&Round($wantedCasperSize,0)&"Mo" & @CRLF EndIf If ($wantedMakeBootable) Then $warning &= "- création d'un secteur de boot sur le disque "&$volume&" ("&DriveGetLabel($volume)&")" & @CRLF EndIf #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Default Button=Second, Icon=Question If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(292,"Confirmation",$warning) Select Case $iMsgBoxAnswer = 6 ;Yes Return True Case $iMsgBoxAnswer = 7 ;No Return False EndSelect #EndRegion --- CodeWizard generated code End --- EndFunc Func CasperCreate() if FileExists($casperPath) Then FileDelete($casperPath) EndIf ShellExecuteWait($volume&$ddPath&"/dd.exe"," if=/dev/zero of=../../../casper-rw bs=1M count="&$wantedCasperSize&" --progress",$ddPath) ShellExecuteWait($volume&$ddPath&"/mkfs.ext2.exe"," -F ../../../casper-rw",$ddPath) if FileExists($casperPath) Then MsgBox(0, "Création disque persistant", "La création du disque persistant est terminée.") Else MsgBox(0, "Création disque persistant", "La création du disque persistant a échouée.") EndIf EndFunc Func BootCreate() if FileExists($ldlinuxPath) Then FileDelete($ldlinuxPath) EndIf ShellExecuteWait($volume&$syslinuxPath&"/syslinux.exe"," -ma "&$volume) if FileExists($ldlinuxPath) Then MsgBox(0, "Création boot", "La création du boot est terminée.") Else MsgBox(0, "Création boot", "La création du boot a échouée.") EndIf EndFunc Func CasperSizeChange() EndFunc Func CreateCasperClick() If (BitAnd(GUICtrlRead($CreateCasper),$GUI_CHECKED)) AND FileExists($casperPath) Then MsgBox(0, "Disque persistant déjà présent", "Un disque persistant (fichier "&$casperPath&") est déjà présent."&@CRLF&"Pensez à sauvegarder son contenu avant de le recréer, car l'intégralité des données (documents et configuration) sera supprimée.") EndIf EndFunc Func Form1Close() exit EndFunc Func Form1Maximize() EndFunc Func Form1Minimize() EndFunc Func Form1Restore() EndFunc Func GoClick() Variables() SetVariables() $checklist = Checklist() if $checklist=false Then Return False Else ; Avertissement If Warning()=false Then Return False EndIf ; désactivation bouton GUICtrlSetState($Go, $GUI_DISABLE) ; création du casper-rw if $wantedCreateCasper Then CasperCreate() EndIf ; création du boot If $wantedMakeBootable Then BootCreate() EndIf ; finalisation ;sleep(2000) MsgBox(0,"Fin", "La procédure est terminée !") GUICtrlSetState($Go, $GUI_ENABLE) Variables() SetVariables() EndIf EndFunc Func MakebootableClick() EndFunc