-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbygfoot-update
executable file
·953 lines (800 loc) · 24.5 KB
/
bygfoot-update
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
#!/bin/bash
####################################################
# Bygfoot Football Manager #
# AUTHOR: Gyozo Both (gyboth@bygfoot.com) #
# http://bygfoot.sourceforge.net #
####################################################
# Skript that updates src packages of the Bygfoot Football Manager
# using wget to retrieve patches from the homepage
# version number
version="2.0.0"
# the bygfoot release version the script is shipped with
relversion=UNKNOWN_VERSION
# the current release version on the server
packversion=
# exit codes
EXITOK=0
EXITNOPROG=1
EXITNOREV=2
EXITABORT=3
EXITWGETFAIL=4
EXITUSR=6
EXITNEWSCRIPT=7
EXITCOUNTRY=8
EXITDEBIAN=10
# variables
# a variable we sometimes read something into
tempvar=
# the directory containing the Bygfoot src package
packdir=
# a directory we can write to and read from
tmpdir=
# destination for the country files
countrydir=
# the Bygfoot package type, stable or unstable
type_stable=stable
type_unstable=unstable
type=
# the current revision number of the user's package
revnr=
# revision numbers fetched from the homepage
newrevnr=
# number of new revisions found
found=0
# the arguments for the script
args="$*"
# which cvs version to get
cvs_version1=bygfoot-unstable
cvs_version2=bygfoot2-unstable
cvs_version=
# whether we use zenity
use_zenity=
# The file we redirect dialog output to
input_file=$PWD/bygfoot-update-dialog.tmp
# The file containing all output
log_file=$PWD/bygfoot-update.log
# options
# whether all new patches should be applied automatically
apply_all=0
# whether we should skip some queries and assume standard values
auto=0
# whether we recompile automatically after patching
recompile=0
# whether we check for auxiliary programs and
# newer update script versions
check=1
# SourceForge.Net username (for cvs checkout)
cvs_user=
# whether we show the log file before terminating
# if so, the file doesn't get deleted by cleanup()
show_log=0
# operation modes
# source update
mode_src=0
# country file download
mode_country=1
# package download
mode_pack=2
# get cvs version
mode_cvs=3
mode=
# print a help text
function print_help()
{
cat <<END
Usage: bygfoot-update [OPTIONS]
Note: You can call bygfoot-update without any options.
MAIN OPTIONS:
-c|--country-files Download some official team names of well known teams
-n|--new-package Download the latest complete package
-b|--cvs Get CVS version
AUXILIARY OPTIONS:
Global:
-A|--auto Assume [y] for all prompts
-h|--help Print help and exit
-l|--show-log Don't clear the log file before exiting;
show its contents instead.
-t|--temp-dir DIR Set temp directory to DIR
-v|--version Print version information and exit
-Z|--no-zenity Don't use zenity even if the version installed
is usable
directory
Relevant for package download mode:
-t|--temp-dir DIR Set download destination directory
to DIR (same as temp directory)
-T|--type TYPE Download latest TYPE package, TYPE
being either 'stable' or 'unstable'.
Relevant for CVS mode:
-B|--branch BRANCH Which CVS branch to get; currently 1 or 2
for the 1.8 or 2.0 branch.
-U|--username NAME Your SourceForge.Net username used for
checking out, or A for anonymous checkout.
END
}
# print program version
function print_version()
{
cat <<END
bygfoot-update: A bash script keeping your Bygfoot Football Manager up-to-date.
Version $version.
See the file UPDATE for some more information.
Call bygfoot-update -h|--help for usage information.
END
}
# print output to stdout and the log file
function my_echo()
{
echo "$@" 2>> $log_file | tee -a $log_file
}
# show log file before exiting if the option is set
function my_exit()
{
if [ $show_log -eq 1 ]; then
if [ -r $log_file ]; then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update Log" --text-info --filename=$log_file
else
dialog --title "Bygfoot Online Update" --textbox $log_file 22 75
fi
else
echo "** WARNING: log file $log_file not readable."
fi
fi
cleanup
exit $1
}
# parse arguments
function parse_args()
{
TEMP=`getopt -o aAbcB:C:hlnNp:rRt:T:uU:vZ --long apply-all,\
auto,branch:,country-files,country-dir:,cvs,,help,new-package,no-check,\
package-dir:,recompile,no-recompile,show-log,temp-dir:,type:,update,username:\
version,no-zenity -- $*`
if [ $? != 0 ]; then
my_echo "** b-u: There was an error parsing the arguments."
my_echo "** b-u: The arguments will be ignored."
return
fi
eval set -- "$TEMP"
while true; do
case "$1" in
-a|--apply-all) apply_all=1; shift ;;
-A|--auto) auto=1; apply_all=1; shift ;;
-b|--cvs) mode=$mode_cvs; shift ;;
-B|--branch) set_branch $2; shift 2 ;;
-c|--country-files) mode=$mode_country; shift ;;
-C|--country-dir) pushd $2 &> /dev/null; countrydir=$PWD; popd &> /dev/null; shift 2 ;;
-h|--help) print_help; exit $EXITOK ;;
-l|--show-log) show_log=1; shift ;;
-n|--new-package) mode=$mode_pack; shift ;;
-N|--no-check) check=0; shift ;;
-p|--package-dir) pushd $2 &> /dev/null; packdir=$PWD; popd &> /dev/null; shift 2 ;;
-r|--recompile) recompile=1; shift ;;
-R|--no-recompile) recompile=-1; shift ;;
-t|--temp-dir) pushd $2 &> /dev/null; tmpdir=$PWD; popd &> /dev/null; shift 2 ;;
-T|--type) type=$2; shift 2 ;;
-u|--update) mode=$mode_src; shift ;;
-U|--username) cvs_user=$2; shift 2 ;;
-v|--version) print_version; exit $EXITOK ;;
-Z|--no-zenity) use_zenity=0; shift ;;
--) shift; break ;;
esac
done
}
# clean up in the temp dir
function cleanup()
{
my_echo
my_echo "** b-u: Removing output file $input_file."
rm -rfv $input_file 2>> $log_file | tee -a $log_file
if [ ! -z $tmpdir ]; then
if [ $mode -ne $mode_pack ]; then
my_echo "** b-u: Cleaning up in the temp directory."
rm -rfv 2>> $log_file | tee -a $log_file
fi
fi
if [ $show_log -eq 0 ]; then
my_echo "** b-u: Removing log file $log_file."
rm -rfv $log_file
fi
}
# wget something, exit if it doesn't work
function my_wget()
{
if ! wget -v $1 2>> $log_file | tee -a $log_file; then
my_echo
my_echo "** b-u: wget failure."
my_exit $EXITWGETFAIL
fi
}
# wrapper for zenity
function my_zenity()
{
zenity "$@" 1> $input_file
exitval=$?
if [ $exitval -eq 255 ]; then
my_echo "** b-u: zenity error."
read a
elif [ $exitval -eq 1 ]; then
my_echo "** b-u: User abort."
my_exit $EXITUSR
fi
}
# check for high enough version of zenity
function check_zenity()
{
my_echo -n "** b-u: checking for zenity..."
if ! which zenity &> /dev/null; then
my_echo " not installed. I'm going to use dialog."
else
zenver=$(zenity --version)
zenver1=$(echo $zenver |sed "s/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1/g")
zenver2=$(echo $zenver |sed "s/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\2/g")
zenver3=$(echo $zenver |sed "s/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/g")
if [ $zenver1 -ge 2 -a $zenver2 -ge 9 -a $zenver3 -ge 0 ]; then
my_echo " $zenver1.$zenver2.$zenver3 found."
use_zenity=1
else
my_echo " $zenver1.$zenver2.$zenver3 not good enough. I'm going to use dialog."
use_zenity=0
fi
fi
}
# check for the programs needed
function check_progs()
{
if [ $check -eq 0 ]; then
return
fi
my_echo
for i in sed tar bzip2 wget patch svn; do
my_echo -n "** b-u: checking for $i... "
if which $i &> /dev/null; then
my_echo "ok"
else
my_echo "failed"
my_echo
my_echo "** WARNING: Didn't find working $i, maybe it's not in your PATH."
my_echo "** WARNING: You might not be able to use all bygfoot-update features."
read a
fi
done
if [ -z $use_zenity ]; then
check_zenity
fi
}
function read_input()
{
if [ $? -eq 1 ];then
my_echo "** b-u: User abort."
my_exit $EXITUSR
fi
if [ -r $input_file ]; then
tempvar=$(cat $input_file)
else
tempvar=
fi
my_echo "** b-u: User input: $tempvar"
my_echo
}
# get team definitions
function get_team_defs()
{
if [ ! -d teams ]; then
mkdir teams
fi
pushd teams &> /dev/null
rm -vf team_defs 2>> $log_file | tee -a $log_file
my_wget http://bygfoot.sourceforge.net/revisions/team_defs
while read key value; do
if [ ! -z $key ]; then
if [ $key = "end_section" ]; then
file_name=$(echo $uri | sed "s/.*\(team_.*bz2\)/\1/g" | sed "s/\.bz2//g")
def_name=$(echo $file_name | sed "s/team_//g" | sed "s/\..*//g")
if [ -e $file_name.xml ]; then
mv $file_name.xml $file_name.xml.old
fi
if [ -e $file_name.png ]; then
mv $file_name.png $file_name.png.old
fi
my_wget $uri
tar xfj $file_name.bz2
rm -rfv $file_name.bz2 2>> $log_file | tee -a $log_file
echo $PWD
read a
if [ -d $country ]; then
pushd $country &> /dev/null
team_found=0
for league in league*xml; do
for team in "$team_name1" "$team_name2"; do
if grep "<team_name>$team</team_name>" $league &> /dev/null; then
team_found=1
cp -f $league $league.bak
my_echo " + Adding $team to $league..."
perl -0777 -pe "s+(team_name\>$team\</team_name\>)[\n\t ]*\<def_file\>[^\<]*\</def_file\>[\n\t ]*+\1\n+g" $league.bak | perl -0777 -pe "s+([\t ]*)(\<team_name\>$team\</team_name\>)+\1\2\n\1\<def_file\>$def_name\</def_file>+g" > $league
fi
done
done
if [ $team_found -eq 0 ]; then
echo " ** $team_name1 / $team_name2 not found in any of the leagues! **"
fi
popd &> /dev/null
else
my_echo "Country directory $country not found."
fi
team_name1=
team_name2=
uri=
country=
else
case $key in
uri) uri=$value ;;
team_name1) team_name1="$value" ;;
team_name2) team_name2="$value" ;;
country) country=$(find .. -type d -name $value | tail -n 1);;
esac
fi
fi
done < team_defs
rm -vf team_defs 2>> $log_file | tee -a $log_file
popd &> /dev/null
}
# get country files with official team names
function get_country_files()
{
my_echo
my_echo "** b-u: Fetching official team names and"
my_echo "** b-u: team definitions files."
pushd $countrydir &>/dev/null
my_wget http://bygfoot.sourceforge.net/revisions/official_names
while read -d : oldname && read newname
do
if [ "$oldname" = "League" ]; then
DIRNAME=$(find . -type d -name $newname | tail -n 1)
if [ ! $DIRNAME = "" ]; then
my_echo " + Adding official team names to $DIRNAME..."
fi
else
if [ ! $DIRNAME = "" ]; then
oldname="${oldname## }"
newname="${newname%% }"
perl -i -pe "s?>$oldname<?>$newname<?g" $DIRNAME/league*.xml
fi
fi
done < official_names
rm -vf official_names 2>> $log_file | tee -a $log_file
get_team_defs
popd &> /dev/null
my_echo "** b-u: done."
my_exit $EXITCOUNTRY
}
# get the paths for a temp directory and
# the location of the user's bygfoot src package
function get_paths()
{
if [ $mode -eq $mode_src ]; then
if [ -z $packdir ]; then
if [ $auto -eq 0 ]; then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Select source package directory" \
--file-selection --directory
else
dialog --title "Bygfoot Online Update" \
--inputbox "Source package directory" 22 80 $PWD 2> $input_file
fi
read_input
pushd $tempvar &> /dev/null; packdir=$PWD; popd &> /dev/null
else
packdir=$PWD
fi
my_echo
my_echo "** b-u: Package dir set to"
my_echo "** b-u: $packdir"
fi
fi
if [ $mode -ne $mode_country ]; then
if [ -z $tmpdir ]; then
if [ $auto -eq 0 ]; then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Select temporary directory" \
--file-selection --directory
else
dialog --title "Bygfoot Online Update" \
--inputbox "Temporary directory\n(you need read/write permissions there)" \
22 80 /tmp 2> $input_file
fi
read_input
if [ ! -z $tempvar ]; then
pushd $tempvar &> /dev/null ; tmpdir=$PWD; popd &> /dev/null
else
tmpdir=/tmp
fi
else
tmpdir=/tmp
fi
my_echo
my_echo "** b-u: Temp dir set to"
my_echo "** b-u: $tmpdir"
fi
fi
if [ $mode -eq $mode_country ]; then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --info \
--text="If you use the binary version of Bygfoot, you should specify './support_files/definitions' as country dir. If you use an installed version, you should specify '$HOME/.bygfoot-X/definitions' (X being the version number you use)."
else
dialog --title "Bygfoot Online Update" --msgbox "If you use the binary version of Bygfoot, you should specify './support_files/definitons' as country dir. If you use an installed version, you should specify '$HOME/.bygfoot-X/definitions' (X being the version number you use)." \
22 80 2> $input_file
fi
if [ -z $countrydir ]; then
if [ $auto -eq 0 ]; then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Definitions dir (right click to show hidden)" \
--file-selection --directory
else
dialog --title "Bygfoot Online Update" \
--inputbox "Directory containing definitions directory" \
22 80 $HOME/.bygfoot/definitions 2> $input_file
fi
read_input
if [ ! -z $tempvar ]; then
pushd $tempvar &> /dev/null; countrydir=$PWD; popd &> /dev/null
else
countrydir=$HOME/.bygfoot/definitions
fi
else
countrydir=$HOME/.bygfoot/definitions
fi
my_echo
my_echo "** b-u: Country dir set to"
my_echo "** b-u: $countrydir"
fi
fi
}
# find out revision number and type
function get_rev_type()
{
echo
if [ ! -e $packdir/revision_number ]; then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --error \
--text="I couldn't find the file containing your current revision number and type ($packdir/revision_number)."
else
dialog --title "Bygfoot Online Update" --msgbox \
"I couldn't find the file containing your current revision number and type ($packdir/revision_number).\nFailure." \
22 80 2> $input_file
fi
read_input
my_exit $EXITNOREV
fi
type=$(cat $packdir/revision_number | sed s/[0-9]*//g)
revnr=$(cat $packdir/revision_number | sed s/[a-z]*//g)
my_echo "** b-u: Your current revision is: $type $revnr."
}
function apply_rev()
{
my_echo
my_echo "** b-u: Applying patch revision_$type$newrevnr"
cd $packdir
if [ -e $newrevdir/prepatch ]; then
$newrevdir/prepatch 2>> $log_file | tee -a $log_file
fi
patch -p1 < $newrevdir/patch* 2>> $log_file | tee -a $log_file
if [ -e $newrevdir/postpatch ]; then
$newrevdir/postpatch 2>> $log_file | tee -a $log_file
fi
cd $tmpdir/bygfoot-update-tmp
}
# fetch a revision archive from the homepage and
# patch the src package
function get_revision()
{
local newrevdir=$tmpdir/bygfoot-update-tmp/revision_$type$newrevnr
my_echo
my_echo "** b-u: Retrieving revision_$type$newrevnr.tar.bz2."
my_wget http://bygfoot.sourceforge.net/revisions/$type/revision_$type$newrevnr.tar.bz2
mkdir $newrevdir
cd $newrevdir
tar xfjv ../revision_$type$newrevnr.tar.bz2 2>> $log_file | tee -a $log_file
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Patch README" --text-info --filename=README
else
dialog --title "Bygfoot Online Update" --textbox README 22 75
fi
if [ $apply_all -eq 0 ]; then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --list \
--text="Apply patch? (You can't apply newer ones if you don't apply this one because they depend on each other." \
--radiolist --column "" --column "" --column "" \
TRUE 1 Yes \
FALSE 2 No \
FALSE 3 All
else
dialog --title "Bygfoot Online Update" --menu \
"Apply patch?\n(You can't apply newer ones if you don't apply this one because they depend on each other.)" \
22 80 10 \
1 Yes \
2 No \
3 All 2> $input_file
fi
read_input
if [ ! -z $tempvar ]; then
if [ $tempvar -eq 3 ]; then
apply_all=1
elif [ $tempvar -ne 1 ]; then
my_echo
my_echo "** b-u: User abort."
my_exit $EXITUSR
fi
fi
fi
apply_rev
}
# look for new revisions
function get_revs()
{
my_echo
cd $tmpdir
my_echo "** b-u: Cleaning up old update directories and creating a new one..."
rm -rfv bygfoot-update-tmp 2>> $log_file | tee -a $log_file
mkdir -v bygfoot-update-tmp 2>> $log_file | tee -a $log_file
cd bygfoot-update-tmp
my_echo
my_echo "** b-u: Fetching revision list..."
my_wget http://bygfoot.sourceforge.net/revisions/$type/revisions_$type
for i in $(cat revisions_$type); do
my_echo
newrevnr=$(echo $i | sed s/'[a-z_]*\([0-9]*\).*'/'\1'/g)
if [ $newrevnr -gt $revnr ]; then
found=$[found + 1]
get_revision
else
my_echo "** b-u: $i is older than your revision..."
fi
done
}
# clean up etc.
function update_end()
{
my_echo
if [ $found -ge 1 ]; then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --info \
--text="$found new revisions found. Your new revision number should be $[revnr + found]. Have a look at the files README, ChangeLog and ReleaseNotes to see the changes that were made."
else
dialog --title "Bygfoot Online Update" --msgbox "$found new revisions found.\nYour new revision number should be $[revnr + found].\nHave a look at the files README, ChangeLog and ReleaseNotes to see the changes that were made." 2> $input_file
fi
if [ $recompile -eq 0 -a $auto -eq 0 ]; then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --question --text="Would you like me to execute 'configure && make' ?"
else
dialog --title "Bygfoot Online Update" --yesno "Would you like me to execute 'configure && make' ?" 22 80 2> $input_file
fi
read_input
fi
if [ $recompile -ne -1 ]; then
cd $packdir
./configure && make 2>> $log_file | tee -a $log_file
fi
else
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --info \
--text="No new revisions found.\nYour package seems to be up-to-date."
else
dialog --title "Bygfoot Online Update" --msgbox "No new revisions found.\nYour package seems to be up-to-date." 22 80 2> $input_file
fi
fi
my_echo
my_echo "** b-u: done."
my_exit $EXITOK
}
# set cvs branch from command line option
function set_branch()
{
if [ $1 -eq 1 ]; then
cvs_version=$cvs_version1;
else
cvs_version=$cvs_version2;
fi
}
# ask for the package type (stable/unstable)
function get_type()
{
if [ ! -z $type ]; then
return
fi
if [ $auto -ne 1 ];then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --list \
--text="Specify package type:" \
--radiolist --column "" --column "" --column "" \
TRUE 1 Stable \
FALSE 2 Unstable
else
dialog --title "Bygfoot Online Update" --menu "Specify package type" \
22 80 10 \
1 "Stable" \
2 "Unstable" 2> $input_file
fi
read_input
if [ $tempvar -eq 2 ]; then
type=$type_unstable
else
type=$type_stable
fi
else
type=$type_stable
fi
}
function get_latest_versions()
{
pushd $tmpdir &> /dev/null
rm -rfv bygfoot-update-tmp 2>> $log_file | tee -a $log_file
mkdir -v bygfoot-update-tmp
cd bygfoot-update-tmp
my_wget http://bygfoot.sourceforge.net/packages/$type/versions
packlist=`cat versions`
if [ $auto -eq 1 ]; then
return
fi
if [ $use_zenity -eq 1 ]; then
zencmd="zenity --title=Bygfoot_Online_Update --list --text=Select_package.Your_version_is_$relversion(as_far_as_I_know). --radiolist --print-column 2"
zencmd="$zencmd --column - --column - --column Package"
cnt=1
for package in $packlist; do
if [ $cnt -eq 1 ]; then
zencmd="$zencmd TRUE $cnt $package"
else
zencmd="$zencmd FALSE $cnt $package"
fi
cnt=$[cnt + 1];
done
selected_package=$($zencmd)
if [ $? -eq 1 ];then
my_echo "** b-u: User abort."
my_exit $EXITUSR
fi
else
dialcmd="dialog --title Bygfoot_Online_Update --menu Select_package.Your_version_is_$relversion(as_far_as_I_know). 22 80 10"
for package in $packlist; do
dialcmd="$dialcmd $package -"
done
$dialcmd 2> $input_file
read_input
selected_package=$tempvar
fi
}
function get_new_package()
{
my_wget http://bygfoot.sourceforge.net/packages/$type/$selected_package
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --info \
--text="You can find the package $selected_package in the directory $PWD."
else
dialog --title "Bygfoot Online Update" \
--msgbox "You can find the package $selected_package\nin the directory $PWD." \
22 80 2> $input_file
fi
my_echo "** b-u: Done."
my_exit $EXITOK
}
# download a bygfoot package
function get_package()
{
get_type
get_latest_versions
get_new_package
}
function get_mode()
{
if [ ! -z $mode ]; then
return
fi
if [ $auto -eq 1 ]; then
mode=$mode_src
return
fi
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --list \
--text="Main Menu" \
--radiolist --column "" --column "" --column "" \
TRUE 1 "Download the latest Bygfoot release" \
FALSE 2 "Get official team names and team definitions" \
FALSE 3 "Get CVS version (11+ MB)"
else
dialog --title "Bygfoot Online Update" --menu "Main Menu" 22 80 10 \
1 " Download the latest Bygfoot release" \
2 " Get official team names and team definitions" \
3 " Get CVS version (11+ MB)" 2> $input_file
fi
read_input
if [ -z $tempvar ]; then
mode=$mode_pack
return
fi
if [ $tempvar -eq 1 ]; then
mode=$mode_pack
elif [ $tempvar -eq 2 ]; then
mode=$mode_country
else
mode=$mode_cvs
fi
}
function get_cvs()
{
if [ -z $cvs_version ];then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --list \
--text="Specify CVS version" \
--radiolist --column "" --column "" --column "" \
FALSE 1 " 1.8 branch" \
TRUE 2 " 2.0 branch"
else
dialog --title "Bygfoot Online Update" --menu "Specify CVS version" 22 80 10 \
1 " 1.8 branch" \
2 " 2.0 branch" 2> $input_file
fi
read_input
if [ $tempvar -eq 2 ]; then
cvs_version=$cvs_version2
else
cvs_version=$cvs_version1
fi
fi
if [ -z $cvs_user ];then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --entry \
--text="If you'd like to check out as a developer, enter your SourceForge.net username. Leave empty to check out anonymously."
else
dialog --title "Bygfoot Online Update" --inputbox "If you'd like to check out as a developer, enter your\nSourceForge.net username. Press RETURN to download anonymously." 22 80 2> $input_file
fi
read_input
if [ -z $tempvar ]; then
cvs_command="svn co https://bygfoot.svn.sourceforge.net/svnroot/bygfoot bygfoot/trunk/bygfoor/trunk"
else
cvs_command="svn --username=$tempvar co https://bygfoot.svn.sourceforge.net/svnroot/bygfoot bygfoot/trunk/bygfoor/trunk"
fi
else
if [ $cvs_user = "A" ]; then
cvs_command="svn co https://bygfoot.svn.sourceforge.net/svnroot/bygfoot bygfoot/trunk/bygfoor/trunk"
else
cvs_command="svn --username=$cvs_user co https://bygfoot.svn.sourceforge.net/svnroot/bygfoot bygfoot/trunk/bygfoor/trunk"
fi
fi
cd $tmpdir
$cvs_command checkout $cvs_version 2>> $log_file | tee -a $log_file
if [ $recompile -eq 0 -a $auto -eq 0 ]; then
if [ $use_zenity -eq 1 ]; then
my_zenity --title="Bygfoot Online Update" --question \
--text="Would you like me to execute 'autogen.sh && make' ?"
else
dialog --title "Bygfoot Online Update" \
--yesno "Would you like me to execute 'autogen.sh && make' ?" 22 80 2> $input_file
fi
read_input
fi
if [ $recompile -ne -1 ]; then
cd $cvs_version
./autogen.sh && make 2>> $log_file | tee -a $log_file
fi
my_exit $EXITOK
}
parse_args $*
print_version
echo "Bygfoot Online Update $version log file" > $log_file
echo "Don't forget to remove this file if you don't need it anymore." >> $log_file
check_progs
get_mode
get_paths
# what to do when user presses Ctrl-C
trap 'my_echo; my_echo "** b-u: User abort." & my_exit $EXITABORT' 2
if [ $mode -eq $mode_country ]; then
get_country_files
elif [ $mode -eq $mode_pack ]; then
get_package
elif [ $mode -eq $mode_cvs ]; then
get_cvs
else
get_rev_type
get_revs
update_end
fi