<b>REGISTER</b>

GFX-Sector - Scripte & Downloads


 
GFX-Sector » Coding Area » Scripte & Downloads » [BASH]Archiver Script » Hello Guest [Login|Register]
Last Post | First Unread Post Print Page | Recommend to a Friend | Add Thread to Favorites

Scripte & Downloads

Du hast ein tolles Script gefunden oder geschrieben und möchtest es mit uns teilen? Hier ist der richtige Ort dazu.
Post New Thread Post Reply

[BASH]Archiver Script

     Deutsche Version  English version
Author
Post « Previous Thread | Next Thread »

bpr bpr is a male
Spender


Avatar von bpr

Registration Date: 18.11.2007
Posts: 557
Location: London
Program: Zend Studio
Forums: Coding; International Section

Spacer
[BASH]Archiver Script

[BASH]Archiver Script

      

Hi,
ich habe ein script fuer mein team und mich geschrieben, damit wir die versionen von unserem css framework schneller einpacken koennen.
Das ganze ist jetzt nur in BASH vorhanden und fuer die MAC user, das haengt dadran, dass ich ein gewisses rar programm benutze, wenn man die rar funktion rausnehmen wuerde, wuerden auch die unix/linux user das programm voll nutzen koennen.

Es packt datein in 3 verschiedene archive ab:
zip
rar
tar.gz

Man hat folgende Optionen:
-a = dann werden alle archive erstellt
-v = es gibt eine erweiterte bericht erstattung

Jetzt muss ich das ganze nur nochmal fuer die windows user entwickeln : (


und wichtig, wenn jemand verbesserungs vorschlaege fuer den code hat, besonders bei der parameter uebergabe dann bitte sagen - waere sehr schoen : )

und fuer die die ueberhaupt nichts verstehen und dass das erstemal sehen, klickt einfach auf das gfx sector logo und lest nen anderen thread - erspart euch kopfschmerzen
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
#!/bin/bash
#for debuggin -x
#Written by bjoern schwabe
#Version 2.0
#developed for the speedcss team to build archives fast
#you may read the following lines carefully

#path to rar application
rarapp=/Applications/rar/

#command structure
#
#   dbuilder2.sh -param -output -input
#
#Options for archiv handling
#   -v          verbose, prints what its doing
#
#   -a          all, make all archives (rar, tar.gz, zip)
#

####################
#!!!!!DO NOT CHANGE ANYTHING BELOW THIS LINE!!!!!
####################
#Set defaults for params
v=0
a=0
r=0

#filling vars
#check if PARAM is given
if [ $1 ]; then
    param=$1
else
    param=0
fi

#check if INPUT is given
if [ $2 ]; then
    input=$2
else
    input=0
fi

#check if OUTPUT is given
if [ $3 ]; then
    output=$3
else
    output=0
fi

#Check param if they exsist
#check verbose
if [ $(echo $param | grep [v]) ]; then
    v=1
else
    v=0
fi

#check all
if [ $(echo $param | grep [a]) ]; then
    a=1
else
    a=0
fi

#check restart
if [ $(echo $param | grep [r]) ]; then
    r=1
else
    r=0
fi

#after restart do this! We need names and files!
if [ $r = 1 -o $input = 0 -o $output = 0 ]; then
    #input file config
    echo "Please type in your input file (CASE SENSETIVE)"
    read IN
    input=$IN
    if [ -e $input ]; then
        echo "You are now your $input"
    else
        echo "This File does not excist"
        ./dbuilder2.sh r
    fi
    #output config
    echo " Please type in your output file name"
    read OUT
    output=$OUT
    echo "You will have $output as output"
    
    #all or single
    echo "if you want to create zip, tar.gz, rar at once please enter a"
    read ALL
    if [ $ALL = a ]; then
        a=1
    else
        a=0
    fi
    echo "Lean back and enjoy watching..."
fi

#########################
#FUNCTIONS
#########################
#create zip
function czip()
{
    in=$1
    out=$2
    v=$3
    
    if [ $v = 1 ]; then
        echo "Creating ZIP archive"
        zip -rv $out.zip $in
        echo "$out.zip was successfully created"
    else
        zip -r $out.zip $in
    fi
}

#create tar.gz
function ctargz()
{
    in=$1
    out=$2
    v=$3
    if [ $v = 1 ]; then
        echo "TAR is in progress:"
        tar -cvf $out.tar $in
        echo "$out.tar was created"
        echo "Is going to GZIP $out.tar"
        gzip $out.tar
        echo "$out.tar.gz was successfully created"
    else
        tar -cf $out.tar $in
        gzip $out.tar
    fi
}

#create rar
function crar()
{
    in=$1
    out=$2
    v=$3
    if [ $v = 1 ]; then
        echo "RAR is in progress:"
        $rarapp/rar a $out.rar $in
        echo "$out.rar was successfully created"
    else
        $rarapp/rar a $out.rar $in
    fi
}

#make all
function call()
{
    in=$1
    out=$2
    v=$3
    if [ $v = 1 ]; then
        echo "Will make all archives"    
        czip $in $out $v
        ctargz $in $out $v
        crar $in $out $v
        echo "All archives are done."
    else  
        czip $in $out $v
        ctargz $in $out $v
        crar $in $out $v
    fi    
}

#restart
function restart()
{
    echo "Do you want to do more? y/n"
    read ARESTART
    if [ $ARESTART = y ]; then
        ./dbuilder2.sh r
    else
        echo "See you later..."
        exit
    fi
}

#print instructions
function instructions()
{
echo "#command structure"
echo "#"
echo "#   dbuilder2.sh -param -output -input"
echo "#"
echo "#Options for archiv handling"
echo "#   -v          verbose, prints what its doing"
echo "#"
echo "#   -a          all, make all archives (rar, tar.gz, zip)"
echo "#"
}


#########################
#System
#########################
if [ -e $input ]; then
    instructions
    echo "Welcome to dbuilder2, no warranty no garranty - usage on own purpose only"
    echo "written by bjoern schwabe for speedcss developers"
    echo "Please READ and UNDERSTAND the instructions"
    echo "You are using $input"
    echo "If this is wrong please restart the application otherwise continue"
    echo ""
    #check if it wants all
    if [ $a = 1 ];then
        call $input $output $v
    else
    #if not do every single and ask
    #zip
        echo "Do you want to create ZIP? y/n"
        read ZipAnswer
        if [ $ZipAnswer = y ]; then
            czip $input $output $v
        else
            echo "ZIP skipped"
        fi
        
     #targz   
        echo "Do you want to create TAR.GZ y/n"
        read TargzAnswer
        if [ $TargzAnswer = y ]; then
            ctargz $input $output $v
        else
            echo "TAR.GZ skipped"
        fi
        
     #rar   
        echo "Do you want to create RAR y/n"
        read RarAnswer
        if [ $RarAnswer = y ]; then
            crar $input $output $v
        else
            echo "RAR skipped"
        fi
    fi  #check all finish
    echo "Good Job, this is the end of the operation with: $input"
    restart
else    #check if file does exsist finish
    echo "File does not exsist"
    restart
fi




Thanks for this thread by the author

Until now 0 users have thanked



Freude
[BASH]Archiver Script 29.03.2010 10:08 bpr is offline Homepage of bpr Search for Posts by bpr

Ephraim
Super Moderator


Avatar von Ephraim

Registration Date: 17.03.2008
Posts: 4,357
Forums: (alle)

Spacer
      

muss sagen ein sehr gutes script
finde die überprüfungen die du eingebaut hast sehr nice

eine frage hab ich aber wieso nennst du die übergabeparamter erst in Zeile 108, 109 und 110 etc. um?
Würds als aller erstes nach dem #!/bin/bash ändern und dann direkt mit dem neuen namen weiterarbeiten dann müsstest du auch nicht in jeder funktion die namen neu bestimmen oder verpeil ich grad?

wie muss der chmod gesetzt sein? u+x?





danke julian <3
[BASH]Archiver Script 16.04.2010 22:25 Ephraim is offline Search for Posts by Ephraim

bpr bpr is a male
Spender


Avatar von bpr

Registration Date: 18.11.2007
Posts: 557
Location: London
Program: Zend Studio
Forums: Coding; International Section

Thread Starter Thread Started by bpr
Spacer
      

Danke,

naja, im nachenein finde ich das script nicht mehr so gut, ich haette es sowieso lieber gleich in C / C++machen sollen. Wie dem acuh sei,

Du darfst das mit den parametern nicht verwechseln, das $1 in einer funktion, sagt nur, dass das der erste parameter ist, der in den klammern von der funktion steht, der also in die funktion uebergeben wrid, das ist nicht von dem gesamten script.

bash scripting ist einfach haesslich!

ich werde wenn zeit dafuer ist, das ganze nochmal in c machen!

all the best,
bjoern : )




Freude
[BASH]Archiver Script 16.04.2010 22:32 bpr is offline Homepage of bpr Search for Posts by bpr

Ephraim
Super Moderator


Avatar von Ephraim

Registration Date: 17.03.2008
Posts: 4,357
Forums: (alle)

Spacer
      

bash halt großes Grinsen
am schönsten ist immernoch pascal ^^

hab das script nicht ausgeführt aber dachte halt das $1, $2, $3 ist:

./script.sh X Y Z

sozusagen das

$1=X
$2=Y
$3=Z

ist.
So wie ich das kenne nennt man diese Paramter direkt am Anfang um und arbeitet mit den neuen Namen weiter naja egal jetzt hehehe ^^

Deine Überprüfungen gefallen mir besonders gut von denen kann man gut lernen.





danke julian <3
[BASH]Archiver Script 16.04.2010 22:38 Ephraim is offline Search for Posts by Ephraim

quantum quantum is a male
Pfadfinder

Spender


Avatar von quantum

Registration Date: 29.12.2008
Posts: 721
Deviantart: xcracx

Spacer
      

Schich schick. Bash ist meiner Meinung nach ja eher für kurze scripts, die man kurz zusammenhacken kann. Dein Programm ist ja eher ausführlicher (auch wenn ich selbst schon sowas in Bash umgesetzt habe =/ ), deswegen würde ICH das eher in Python umsetzen => plattformunabhängig. Außerdem ist Bash imo hässlich ^^

Aber das hast du ja selbst schon bemerkt Zunge raus

Und zum lernen ist es in der Tat gut, du hast einen sauberen Stil, aber ich denke, das weist du Zunge raus



[BASH]Archiver Script 20.04.2010 17:54 quantum is offline Homepage of quantum Search for Posts by quantum

bpr bpr is a male
Spender


Avatar von bpr

Registration Date: 18.11.2007
Posts: 557
Location: London
Program: Zend Studio
Forums: Coding; International Section

Thread Starter Thread Started by bpr
Spacer
      

Danke "quantum" fuer deine antwort.
ich bin der meinung, dass bash ok ist bis 500 zeilen Rotes Gesicht aber ehrlich gesagt, wuerde ich auch gerne python koennen, habe jedoch einfach noch nciht die zeit gefunden es zu lernen : (




Freude
[BASH]Archiver Script 21.04.2010 13:33 bpr is offline Homepage of bpr Search for Posts by bpr
 
Spacer
   
GFX-Sector
unregistered


 hat kein Avatar


Spacer

Have you enjoyed this topic?


If you were enjoying this post and if you keen on reading more interesting stuff then do not hesitate to complete the free sign up.

After the free registration you will gain access to all areas and you will be able to communicate with other artists from all over the world.

In addition you will benefit from our Photoshop and coding section as well as from our huge (hundreds of gigabytes) free resource section where you can find everything you will need to be a successful (web) designer/artist.

Sign up now and enjoy the advantages as a registered member.

(This website will be ad-free after a complete free sign up.)

New Post 21.04.2010 13:33  
Tree Structure | Board Structure
Post New Thread Post Reply
GFX-Sector » Coding Area » Scripte & Downloads » [BASH]Archiver Script

Similar topics to [BASH]Archiver Script
Thread
[Javascript] Javascript: Hinweisfenster (Forum: Javascript Tutorials)
[Anderes] [S] Coder für Autotrade Script / Programm (Forum: Archiv)
SCRIPT vs. yex ` (Forum: 1on1-Archiv)
[Javascript] Lightbox 2 Javascript Gallery (Forum: Javascript Tutorials)
[SUCHE] Galerie Code/Script für Anfänger! (Forum: HTML, CSS)