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
#!/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
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?
Registration Date: 18.11.2007
Posts: 557
Location: London
Program: Zend Studio
Forums: Coding; International Section
Thread Starter
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!
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
Und zum lernen ist es in der Tat gut, du hast einen sauberen Stil, aber ich denke, das weist du
Registration Date: 18.11.2007
Posts: 557
Location: London
Program: Zend Studio
Forums: Coding; International Section
Thread Starter
Danke "quantum" fuer deine antwort.
ich bin der meinung, dass bash ok ist bis 500 zeilen
aber ehrlich gesagt, wuerde ich auch gerne python koennen, habe jedoch einfach noch nciht die zeit gefunden es zu lernen : (
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.)