fb:porticula NoPaste
fstab
| Uploader: |  JoPa | 
| Datum/Zeit: | 29.06.2014 13:54:23 | 
Hinweis: Dieser Quelltext ist Bestandteil des Projekts Linux Fstab Pfad hinzufügen, zu dem es auf FreeBASIC-Portal.de eine Projektseite gibt.
Warnung: Es steht bereits eine neuere Version des Quelltexts zur Verfügung. Die hier vorliegende alte Version könnte Fehler enthalten, die in der neuen Version vielleicht ausgebessert wurden.
declare function parameter(x as string,t as integer) as string
dim device as string
dim optionen as string
dim dump as string
dim pass as string
dim mountpoint as string
dim devicepa as string
dim UUID as string
dim fsTyp as string
dim fsline as string
'--Version:0.2
'hier nach Parametern, Einstellungen suchen und an die Variable übergeben
optionen=parameter("-o ", 0)
dump=parameter("-d ", 0)
pass=parameter("-p ", 0)
mountpoint=parameter("-m", 0)
'falls keine Parameter eingegeben wurden, werden diese auf den Standard gestellt
if optionen="" then optionen="default"
if pass="" then pass="1"
if dump="" then dump="0"
if mountpoint="" then mountpoint="/"                                    'root
if parameter("--help", 0)="1" then
    print
    print "---------------------------addfstab Version 0.1-------------------------"
    print "addfstap Hilfe Beispiele:"
    print "    ./addfstab /dev/sda1 -o default,compress,ssd -d 1 -p 2"
    print
    print "um die /etc/fstab zu überschreiben"
    print "    ./addfstab /dev/sda1 -newfstab"
    print
    print "um die Zeile zur Datei hinzuzufügen"
    print "    ./addfstab /dev/sda1 -addfstab"
    print: print "Options:"
    print "   -d            dump"
    print "   -p            pass"
    print "   -o            optionen"
    print "   -addfstab         die Partition wird am Ende der Fstab eingetragen"
    print "   -newfstab         die Partition wird in die Fstab eingetragen"
    print "             dabei wird die fstab überschrieben"
    print
    print "für weiter Hilfen siehe fstab"
    print "ohne Parameter wird folgendes als Standart erstellt"
    print "               default           0         1"
    print
    'print "-------------------------------------------------------------------------"
    end
endif
'System nach Laufwerken suchen und an die Datei device.tmp übergeben
shell ("blkid -o device >/tmp/device.tmp")
open "/tmp/device.tmp" for input as #1
    do
        input #1, device
        if parameter(device, 1)="1" then                                'wenn das zu speichernde Laufwerk gefunden wird dann
            shell ("blkid -o udev " & device & " >/tmp/devicepa.tmp")    'Informationen zur Partition auslesen
            open "/tmp/devicepa.tmp" for input as #2                    'öffne Datei
                do
                    input #2, devicepa
                    if left(devicepa, 11)= "ID_FS_UUID=" then           'UUID auslesen
                        UUID=right(devicepa, len(devicepa)-11)
                    Endif
                    if left(devicepa, 11)= "ID_FS_TYPE=" then           'Dateisystem erkennen(ntfs, ext2, ext3, Reiserfs, usw.
                        fsTyp=right(devicepa, len(devicepa)-11)
                    endif
                loop until eof(2)
            close #2
            exit do                                                     'do;loop vorzeitig verlassen, hat nur Geschwindigkeits-
        endif                                                           'vorteile
    loop until eof(1)
close #1
'Bildschirmausgabe
print "UUID="& UUID & " "& mountpoint & "   " & fsTyp & "       "& optionen & "     " & dump &" " & pass
'zur fstab hinzufügen
if parameter("-addfstab", 0)="1" or parameter("-newfstab", 0)="1" then
    name "/etc/fstab", "/etc/fstab-old"
    open "/etc/fstab" for output as #4
    open "/etc/fstab-old" for input as #3
        do
            line input #3,fsline
            if parameter("-addfstab", 0)="1" then print #4, fsline
        loop until eof(3)
        print #4, "#"; device
        print #4, "UUID="& UUID & " " & mountpoint & "  " & fsTyp & "       "& optionen & "     " & dump &" " & pass
    close #3
    close #4
endif
function parameter(x as string, t as integer) as string
dim i as integer
dim ia as integer
dim ie as integer
do
            i=i+1
            if x = mid(command$, i, len(x)) then
                if x = "--help" then return "1"
                if x = "-addfstab" then return "1"
                if x = "-newfstab" then return "1"
                if t = 1 then return "1"
                i=i+1
                ia=i
                do
                    if mid(command$, i+2, 1)="" or mid(command$, i+2, 1)=" " then
                        ie=i
                        return mid(command$,ia+2, ie-ia)
                        exit do
                    endif
                    i=i+1
                loop until i>=len(command$)
            endif
        loop until i>=len(command$) or ie<>0
end function
	
 Wer ist online?
 Wer ist online? Buchempfehlung
 Buchempfehlung
 FreeBASIC-Chat
 FreeBASIC-Chat
 FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!
			FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!


