commit
9d35789a16
2 changed files with 257 additions and 0 deletions
@ -0,0 +1,173 @@ |
|||||||
|
#!/usr/bin/env perl |
||||||
|
|
||||||
|
#Создан: Пт 02 авг 2013 18:55:49 |
||||||
|
#Изменён: Вт 03 авг 2013 20:02:03 |
||||||
|
|
||||||
|
use LWP::Simple; # get() |
||||||
|
use File::Path; # rmtree() |
||||||
|
use File::Copy; # move() |
||||||
|
use File::Spec; # File->Spec |
||||||
|
|
||||||
|
# Autoflush |
||||||
|
local $| = 1; |
||||||
|
# Encode |
||||||
|
binmode STDOUT, ":utf8"; |
||||||
|
|
||||||
|
#---------------------------[ Settings ]--------------------------- |
||||||
|
|
||||||
|
# 2GIS start page |
||||||
|
$gisMainPage = "http://msk.2gis.ru"; |
||||||
|
# Directory for *.msi |
||||||
|
$downloadDir = "./updates/"; |
||||||
|
# Directory for 2GIS |
||||||
|
$dataDir = "./updates/gis/"; |
||||||
|
|
||||||
|
# Files to delete |
||||||
|
@exclude = ("MarkInstall", "TrayNotifyEXE", "UpdateServiceEXE"); |
||||||
|
|
||||||
|
# Program for unpack msi |
||||||
|
$p7zip{"linux"} = "7z"; |
||||||
|
$p7zip{"MSWin32"} = File::Spec->rel2abs("7zg.exe"); |
||||||
|
|
||||||
|
#------------------------------------------------------------------ |
||||||
|
|
||||||
|
# 2GisPage |
||||||
|
sub gis_getAllCities ($) { |
||||||
|
my @cities = (); |
||||||
|
|
||||||
|
my $page = get($_[0]); |
||||||
|
|
||||||
|
while ($page =~ m@.*href="http://(.*)\.2gis\.ru/" class="link ">(\w+)</a></li>@g) { |
||||||
|
push(@cities, $1); |
||||||
|
} |
||||||
|
|
||||||
|
return @cities; |
||||||
|
} |
||||||
|
|
||||||
|
# title, regexp, from page, to directory |
||||||
|
sub http_downloadFile ($$$$) { |
||||||
|
my $data = get($_[2]); |
||||||
|
|
||||||
|
while ($data =~ m/$_[1]/g) { |
||||||
|
print sprintf(" > Downloading: %-20s :: ", $_[0]); |
||||||
|
|
||||||
|
my $status = getstore($1, File::Spec->catfile(${_[3]},$2)); |
||||||
|
|
||||||
|
if (is_success($status)) { |
||||||
|
print "DONE\n"; |
||||||
|
} else { |
||||||
|
print "Error downloading file: $status\n"; |
||||||
|
} |
||||||
|
|
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
# startPage, directory |
||||||
|
sub gis_downloadUpdates ($$) { |
||||||
|
print "\n++ [ DOWNLOADING UPDATES ]\n"; |
||||||
|
|
||||||
|
my $webpage = shift; |
||||||
|
my $outdir = shift; |
||||||
|
|
||||||
|
if (-e $outdir or mkdir $outdir) { |
||||||
|
print "\n + Directory for files: $outdir\n\n"; |
||||||
|
} else { |
||||||
|
die "ERROR: Unable to create $outdir\n"; |
||||||
|
} |
||||||
|
|
||||||
|
# Download Shell |
||||||
|
http_downloadFile( |
||||||
|
"2GIS Shell", |
||||||
|
q@.*href="(http://download\.2gis\.ru/arhives/(2GISShell.*\.msi))".*@, |
||||||
|
"$webpage/how-get/download/", |
||||||
|
$outdir |
||||||
|
); |
||||||
|
|
||||||
|
# Download maps |
||||||
|
foreach $city (&gis_getAllCities($webpage)) { |
||||||
|
http_downloadFile( |
||||||
|
$city, |
||||||
|
q@.*href="(http://download\.2gis\.ru/arhives/(2GISData_.*\.msi))".*@, |
||||||
|
"http://$city.2gis.ru/how-get/download/", |
||||||
|
$outdir |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
# file, to dir |
||||||
|
sub msi_extract ($$) { |
||||||
|
print sprintf(" > Extracting %-60s :: ", File::Spec->rel2abs($_[0])); |
||||||
|
|
||||||
|
# 7z -y x file.msi /dir/ |
||||||
|
system($p7zip{$^O}, "-y", "x", $_[0], "-o$_[1]"); |
||||||
|
|
||||||
|
if ( $? == -1 ) { |
||||||
|
print "Failed: $!\n"; |
||||||
|
} elsif ( $? == 0 ) { |
||||||
|
print "DONE\n"; |
||||||
|
} else { |
||||||
|
printf "Command exited with value %d\n", $? >> 8; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
# from dir, to dir |
||||||
|
sub msi_extractAll ($$) { |
||||||
|
my $filesdir = shift; |
||||||
|
my $outdir = shift; |
||||||
|
|
||||||
|
print "\n++ [ EXTRACTING FILES ] \n\n"; |
||||||
|
|
||||||
|
print " + Clear data directory: $outdir\n" if |
||||||
|
rmtree($outdir); |
||||||
|
|
||||||
|
if (-e $outdir or mkdir $outdir) { |
||||||
|
print " + Create data directory: $outdir\n\n"; |
||||||
|
} else { |
||||||
|
die "ERROR: Unable to create $outdir\n"; |
||||||
|
} |
||||||
|
|
||||||
|
foreach $msiFile (glob(File::Spec->catfile($filesdir, "*.msi"))) { |
||||||
|
msi_extract($msiFile, $outdir); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
# directory |
||||||
|
sub gis_makeDistributive ($) { |
||||||
|
my $datadir = $_[0]; |
||||||
|
|
||||||
|
print "\n++ [ BUILDING DISTRIBUTIVE ] \n\n"; |
||||||
|
|
||||||
|
print " + Create directory: Plugins\n" if |
||||||
|
mkdir File::Spec->catfile($datadir, "Plugins"); |
||||||
|
print " + Create directory: DGisLan\n\n" if |
||||||
|
mkdir File::Spec->catfile($datadir, "Plugins", "DGisLan"); |
||||||
|
|
||||||
|
foreach $trash (@exclude) { |
||||||
|
if (unlink(File::Spec->catfile($datadir, $trash))) { |
||||||
|
print sprintf(" - Deleting file %-20s :: DONE\n", $trash); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
foreach $file (glob(File::Spec->catfile($datadir,"*"))) { |
||||||
|
next if (-d $file); |
||||||
|
|
||||||
|
if ($file =~ /^(.*)(?:\\|\/)(.*)_DGDAT$/) { |
||||||
|
move($file, File::Spec->catfile($1, "Data_$2.dgdat")); |
||||||
|
} elsif ($file =~ /^(.*)(?:\\|\/)(.*)Sgn$/) { |
||||||
|
move($file, File::Spec->catfile($1, "Plugins", "$2.dgxpi")); |
||||||
|
} elsif ($file =~ /^(.*)(?:\\|\/)(.*)_DGLAN$/) { |
||||||
|
move($file, File::Spec->catfile($1, "Plugins", "DGisLan", "$2.dglf")); |
||||||
|
} elsif ($file =~ /^(.*)EXE$/) { |
||||||
|
move($file, "$1.exe"); |
||||||
|
} else { |
||||||
|
$file =~ /^(.*)(?:\\|\/)(.*)(.{3})$/; |
||||||
|
move($file, File::Spec->catfile($1, "Plugins", "$2.$3")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
gis_downloadUpdates($gisMainPage, $downloadDir); |
||||||
|
msi_extractAll($downloadDir, $dataDir); |
||||||
|
gis_makeDistributive($dataDir); |
||||||
|
|
@ -0,0 +1,84 @@ |
|||||||
|
#!/bin/bash |
||||||
|
|
||||||
|
#Создан: Вт 06 авг 2013 22:07:30 |
||||||
|
#Изменён: Ср 07 авг 2013 00:22:45 |
||||||
|
|
||||||
|
#Стартовая страница |
||||||
|
GISPAGE="http://msk.2gis.ru/" |
||||||
|
#Директория для сохранения файлов *.msi |
||||||
|
DOWNLOADDIR="./updates/" |
||||||
|
#Директория для сохранения дистрибутива 2ГИС |
||||||
|
DATADIR="./updates/gis/" |
||||||
|
|
||||||
|
#Файл для сохранения адресов оболочки и доступных карт |
||||||
|
WGETLIST="./wgetlist.txt" |
||||||
|
|
||||||
|
#Загрузка оболочки 2ГИС и файлов карт |
||||||
|
download2GIS() { |
||||||
|
#Удаление файлов старше 14 дней в директории с обновлениями |
||||||
|
find $DOWNLOADDIR -type f -mtime +14 -exec rm -f {} \; |
||||||
|
|
||||||
|
#Создание директории для файлов карт |
||||||
|
\mkdir -v -p "$DOWNLOADDIR" |
||||||
|
|
||||||
|
#Оболочка 2ГИС |
||||||
|
\curl -s "${GISPAGE}how-get/download/" \ |
||||||
|
| \grep -E -o 'href="http://download\.2gis\.ru/arhives/2GISShell.*\.msi"' \ |
||||||
|
| cut -d '"' -f 2 > $WGETLIST |
||||||
|
|
||||||
|
#Карты всех доступных городов |
||||||
|
for url in `\curl -s $GISPAGE | \grep -E -o 'http://\w+\.2gis\.ru/" class' | \cut -d '"' -f 1`; do |
||||||
|
\curl -s "${url}how-get/download/" \ |
||||||
|
| \grep -E -o 'href="http://download\.2gis\.ru/arhives/2GISData_.*\.msi"' \ |
||||||
|
| cut -d '"' -f 2 >> $WGETLIST |
||||||
|
done |
||||||
|
|
||||||
|
\wget -t 10 -N -c -P $DOWNLOADDIR -i $WGETLIST |
||||||
|
|
||||||
|
#Удаление временного файла |
||||||
|
\rm -f $WGETLIST |
||||||
|
} |
||||||
|
|
||||||
|
#Сборка дистрибутива 2ГИС |
||||||
|
build2GIS() { |
||||||
|
#Удаление директории 2ГИС |
||||||
|
\rm -rf -v $DATADIR |
||||||
|
|
||||||
|
#Создание дерева директорий 2ГИС |
||||||
|
\mkdir -v -p "${DATADIR}/Plugins/DGisLan" |
||||||
|
|
||||||
|
#Распаковка файлов *.msi |
||||||
|
for file in $DOWNLOADDIR/*.msi; do |
||||||
|
\7z -y x "$file" -o$DATADIR |
||||||
|
done |
||||||
|
|
||||||
|
#Переименовывание файлов и организация структуры директорий 2ГИС |
||||||
|
for file in $DATADIR/*; do if test -f "$file"; then |
||||||
|
case "$file" in |
||||||
|
*_DGDAT) \mv -v "$file" "$DATADIR/Data_`echo -n $(basename $file) | sed 's/_DGDAT/.dgdat/'`";; |
||||||
|
*_DGLAN) \mv -v "$file" "$DATADIR/Plugins/DGisLan/`echo -n $(basename $file) | sed 's/_DGLAN/.dglf/'`";; |
||||||
|
*Sgn) \mv -v "$file" "$DATADIR/Plugins/`echo -n $(basename $file) | sed 's/Sgn/.dgxpi/'`";; |
||||||
|
*Dll) \mv -v "$file" "$DATADIR/Plugins/`echo -n $(basename $file) | sed 's/Dll/.dll/'`";; |
||||||
|
*Chm) \mv -v "$file" "$DATADIR/Plugins/`echo -n $(basename $file) | sed 's/Chm/.chm/'`";; |
||||||
|
*EXE) \mv -v "$file" "$DATADIR/`echo -n $(basename $file) | sed 's/EXE/.exe/'`";; |
||||||
|
esac |
||||||
|
fi |
||||||
|
done |
||||||
|
|
||||||
|
#Удаление лишних файлов |
||||||
|
\rm -f -v $DATADIR/MarkInstall |
||||||
|
\rm -f -v $DATADIR/TrayNotify.exe |
||||||
|
\rm -f -v $DATADIR/UpdateService.exe |
||||||
|
} |
||||||
|
|
||||||
|
#Разбор аргументов командной строки |
||||||
|
case "$1" in |
||||||
|
-h) printf "Использование: $0 [options] |
||||||
|
-h - вывод справки по использованию. |
||||||
|
-d - только загрузка файлов обновлений. |
||||||
|
-x - только распаковка обновлений.\n";; |
||||||
|
-d) download2GIS;; |
||||||
|
-x) build2GIS;; |
||||||
|
*) download2GIS; build2GIS;; |
||||||
|
esac |
||||||
|
|
Loading…
Reference in new issue