diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-02-23 19:57:08 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-02-23 19:57:08 +0100 |
commit | 60d328e2558e982d441f64b54e089b0e1f6b70f9 (patch) | |
tree | 2698bfdd5a890a29ddb89fe272091bd09e4600c2 /modules/private/buildbot/projects/immaeEu | |
parent | 52549f2e115c72958b2a8471a1ae61ccd93583d6 (diff) | |
download | Nix-60d328e2558e982d441f64b54e089b0e1f6b70f9.tar.gz Nix-60d328e2558e982d441f64b54e089b0e1f6b70f9.tar.zst Nix-60d328e2558e982d441f64b54e089b0e1f6b70f9.zip |
Add gsm cells download script
Diffstat (limited to 'modules/private/buildbot/projects/immaeEu')
-rw-r--r-- | modules/private/buildbot/projects/immaeEu/__init__.py | 66 | ||||
-rwxr-xr-x | modules/private/buildbot/projects/immaeEu/scripts/lacells_download | 163 |
2 files changed, 226 insertions, 3 deletions
diff --git a/modules/private/buildbot/projects/immaeEu/__init__.py b/modules/private/buildbot/projects/immaeEu/__init__.py index f29eb14..ad29531 100644 --- a/modules/private/buildbot/projects/immaeEu/__init__.py +++ b/modules/private/buildbot/projects/immaeEu/__init__.py | |||
@@ -24,6 +24,8 @@ class E(): | |||
24 | COURS_TARBALL_URL = "https://release.immae.eu/cours" | 24 | COURS_TARBALL_URL = "https://release.immae.eu/cours" |
25 | IMMAE_EU_RELEASE_PATH = "/var/lib/buildbot/outputs/immaeEu" | 25 | IMMAE_EU_RELEASE_PATH = "/var/lib/buildbot/outputs/immaeEu" |
26 | NORMALESUP_RELEASE_PATH = "/var/lib/buildbot/outputs/recherche" | 26 | NORMALESUP_RELEASE_PATH = "/var/lib/buildbot/outputs/recherche" |
27 | GSMCELLS_RELEASE_PATH = "/var/lib/ftp/release.immae.eu/gsm_cells" | ||
28 | GSMCELLS_RELEASE_URL = "https://release.immae.eu/gsm_cells" | ||
27 | 29 | ||
28 | # master.cfg | 30 | # master.cfg |
29 | SECRETS_FILE = os.getcwd() + "/secrets" | 31 | SECRETS_FILE = os.getcwd() + "/secrets" |
@@ -61,19 +63,45 @@ def configure(c): | |||
61 | c['schedulers'].append(hook_scheduler("ImmaeEu", timer=1)) | 63 | c['schedulers'].append(hook_scheduler("ImmaeEu", timer=1)) |
62 | c['schedulers'].append(hook_scheduler("Normalesup", timer=1)) | 64 | c['schedulers'].append(hook_scheduler("Normalesup", timer=1)) |
63 | c['schedulers'].append(hook_scheduler("Cours", timer=1)) | 65 | c['schedulers'].append(hook_scheduler("Cours", timer=1)) |
64 | c['schedulers'].append(force_scheduler("force_immae_eu", ["ImmaeEu_build", "Normalesup_build", "Cours_build"])) | 66 | c['schedulers'].append(schedulers.Nightly(name="GSMCells-weekly", |
67 | builderNames=["GSMCells_build"], dayOfWeek=6, hour=3)) | ||
68 | c['schedulers'].append(force_scheduler("force_immae_eu", [ | ||
69 | "ImmaeEu_build", "Normalesup_build", "Cours_build", | ||
70 | ])) | ||
71 | c['schedulers'].append(schedulers.ForceScheduler( | ||
72 | name="GSMCells-force", label="Force build", | ||
73 | buttonName="Force build", | ||
74 | reason=util.StringParameter(name="reason", label="Reason", default="Force build"), | ||
75 | codebases=[ | ||
76 | util.CodebaseParameter("", | ||
77 | branch=util.FixedParameter(name="branch", default=""), | ||
78 | revision=util.FixedParameter(name="revision", default=""), | ||
79 | repository=util.FixedParameter(name="repository", default=""), | ||
80 | project=util.FixedParameter(name="project", default=""), | ||
81 | ), | ||
82 | ], | ||
83 | username=util.FixedParameter(name="username", default="Web button"), | ||
84 | builderNames=["GSMCells_build"] | ||
85 | )) | ||
65 | 86 | ||
66 | c['builders'].append(immae_eu_factory()) | 87 | c['builders'].append(immae_eu_factory()) |
67 | c['builders'].append(normalesup_factory()) | 88 | c['builders'].append(normalesup_factory()) |
68 | c['builders'].append(cours_factory()) | 89 | c['builders'].append(cours_factory()) |
90 | c['builders'].append(gsm_cells_factory()) | ||
69 | 91 | ||
70 | c['services'].append(SlackStatusPush( | 92 | c['services'].append(SlackStatusPush( |
71 | name="slack_status_immae_eu_project", | 93 | name="slack_status_immae_eu_project", |
72 | builders=["ImmaeEu_build", "Normalesup_build", "Cours_build"], | 94 | builders=[ |
95 | "ImmaeEu_build", "Normalesup_build", "Cours_build", | ||
96 | "GSMCells_build" | ||
97 | ], | ||
73 | serverUrl=open(E.SECRETS_FILE + "/slack_webhook", "r").read().rstrip())) | 98 | serverUrl=open(E.SECRETS_FILE + "/slack_webhook", "r").read().rstrip())) |
74 | c['services'].append(XMPPStatusPush( | 99 | c['services'].append(XMPPStatusPush( |
75 | name="xmpp_status_immae_eu_project", | 100 | name="xmpp_status_immae_eu_project", |
76 | builders=["ImmaeEu_build", "Normalesup_build", "Cours_build"], | 101 | builders=[ |
102 | "ImmaeEu_build", "Normalesup_build", "Cours_build", | ||
103 | "GSMCells_build" | ||
104 | ], | ||
77 | recipients=E.XMPP_RECIPIENTS, | 105 | recipients=E.XMPP_RECIPIENTS, |
78 | password=open(E.SECRETS_FILE + "/notify_xmpp_password", "r").read().rstrip())) | 106 | password=open(E.SECRETS_FILE + "/notify_xmpp_password", "r").read().rstrip())) |
79 | 107 | ||
@@ -158,3 +186,35 @@ def normalesup_factory(): | |||
158 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.NORMALESUP_RELEASE_PATH))) | 186 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.NORMALESUP_RELEASE_PATH))) |
159 | 187 | ||
160 | return util.BuilderConfig(name="Normalesup_build", workernames=["generic-worker-immae-eu"], factory=factory) | 188 | return util.BuilderConfig(name="Normalesup_build", workernames=["generic-worker-immae-eu"], factory=factory) |
189 | |||
190 | def gsm_cells_factory(): | ||
191 | path_env = { | ||
192 | "PATH": os.environ["BUILDBOT_PATH_GSMCells"] + ":${PATH}", | ||
193 | "IN_BUILDBOT": "yes", | ||
194 | } | ||
195 | master_env = { | ||
196 | "HTACCESS": ''' | ||
197 | Options +FollowSymLinks | ||
198 | IndexIgnore * | ||
199 | ''' | ||
200 | } | ||
201 | for k, v in os.environ.items(): | ||
202 | if k.startswith("BUILDBOT_GSM_CELLS_"): | ||
203 | path_env[k[len("BUILDBOT_GSM_CELLS_"):]] = v | ||
204 | |||
205 | script = os.environ["BUILDBOT_PROJECT_DIR"] + "/scripts/lacells_download" | ||
206 | factory = util.BuildFactory() | ||
207 | factory.addStep(steps.ShellCommand(name="download files", | ||
208 | logEnviron=False, haltOnFailure=True, command=[script], env=path_env)) | ||
209 | factory.addStep(steps.ShellCommand(name="give read access to all files", | ||
210 | logEnviron=False, haltOnFailure=True, | ||
211 | command="chmod a+r lacells.db", env=path_env)) | ||
212 | factory.addStep(steps.FileUpload(workersrc="lacells.db", | ||
213 | masterdest=(E.GSMCELLS_RELEASE_PATH+"/lacells.db"), url=(E.GSMCELLS_RELEASE_URL+"/lacells.db"))) | ||
214 | factory.addStep(steps.MasterShellCommand(command="touch {}/.duplicity-ignore".format(E.GSMCELLS_RELEASE_PATH))) | ||
215 | factory.addStep(steps.MasterShellCommand(command='echo "$HTACCESS" > {}/.htaccess'.format(E.GSMCELLS_RELEASE_PATH), | ||
216 | env=master_env)) | ||
217 | factory.addStep(steps.MasterShellCommand(command="ln -sf lacells.db {}/lacells.db.new".format(E.GSMCELLS_RELEASE_PATH))) | ||
218 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.GSMCELLS_RELEASE_PATH))) | ||
219 | |||
220 | return util.BuilderConfig(name="GSMCells_build", workernames=["generic-worker-immae-eu"], factory=factory) | ||
diff --git a/modules/private/buildbot/projects/immaeEu/scripts/lacells_download b/modules/private/buildbot/projects/immaeEu/scripts/lacells_download new file mode 100755 index 0000000..1193cf3 --- /dev/null +++ b/modules/private/buildbot/projects/immaeEu/scripts/lacells_download | |||
@@ -0,0 +1,163 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # FLG - Fast Lacells.db Generator | ||
4 | # | ||
5 | # Simple script to quickly download and generate lacells.db for LocalGSMBackend by n76 | ||
6 | # https://github.com/n76/Local-GSM-Backend | ||
7 | # Uses Mozilla Location Service, OpenCellID and radiocells.org databases as source | ||
8 | # Based on lacells-creator by wvengen and n76 | ||
9 | # | ||
10 | # Licensed under GPLv3 or later | ||
11 | # (C)2016 Sebastian Obrusiewicz | ||
12 | # sobrus@o2.pl | ||
13 | |||
14 | if [ -z "$IN_BUILDBOT" ]; then | ||
15 | #DEFAULT_CONFIG_BEGIN | ||
16 | ENABLE_OCI=1 #enable OpenCellID data source | ||
17 | ENABLE_MOZ=1 #enable Mozilla Location Services (MLS) data source | ||
18 | ENABLE_RCO=0 #enable radiocells.org data source (it can be quite slow) | ||
19 | |||
20 | # See https://en.wikipedia.org/wiki/Mobile_country_code | ||
21 | # 208 France | ||
22 | MCC="" #contry codes separated with "|", for example "260|262". Leave dot+asterisk ".*" for all countries | ||
23 | RCO_SRC_FILE="fr.sqlite" #radiocells.org source database file, set "openbmap.sqlite" for entire world database, see https://radiocells.org/downloads for smaller country specific files, for example "pl.sqlite" for Poland | ||
24 | RADIO="" #you can remove LTE if your phone does not support it | ||
25 | TOKEN="" #your OCID token, required to download from OpenCellID. Get your free token at https://opencellid.org/ | ||
26 | fi | ||
27 | TMPDIR='.' #for temporary files only, use disk if you don't have enough RAM, AND remember to have enough disk space in /var/tmp for sqlite temporary files | ||
28 | KEEP_FILES=1 #whether to keep (1) or delete (0) the CSV files after processing | ||
29 | |||
30 | #do not edit following variables, unless you know what you're doing | ||
31 | EMPTY=',,,,,,,,,,,,,' #dummy empty file for disabled sources | ||
32 | OCI_FILE=$TMPDIR"/ocid.csv" #opencellid temporary file | ||
33 | MOZ_FILE=$TMPDIR"/mozilla.csv" #mozilla temporary file | ||
34 | RCO_FILE=$TMPDIR"/rco.csv" #radiocells.org temporary file | ||
35 | #DEFAULT_CONFIG_END | ||
36 | |||
37 | #USER_CONFIG_BEGIN | ||
38 | BINDIR=$( dirname "$(readlink -f "$0")" ) #" | ||
39 | if [[ -f "${BINDIR}/config" ]]; then | ||
40 | . "${BINDIR}/config" | ||
41 | fi | ||
42 | #USER_CONFIG_END | ||
43 | |||
44 | function manage_backup | ||
45 | { | ||
46 | file=$1 | ||
47 | if [ -s $file ] | ||
48 | then | ||
49 | if [ $KEEP_FILES == "1" ] | ||
50 | then | ||
51 | gzip -kf $file | ||
52 | fi | ||
53 | elif [ -s $file".gz" ] && [ "${file##*.}" == "csv" ] | ||
54 | then | ||
55 | echo "Using" $file".gz backup file" | ||
56 | gzip -dkf $file".gz" | ||
57 | fi | ||
58 | } | ||
59 | |||
60 | |||
61 | function download_ocid | ||
62 | { | ||
63 | URL="https://opencellid.org/ocid/downloads?token=${TOKEN}&type=full&file=cell_towers.csv.gz" | ||
64 | if [ $ENABLE_OCI == "1" ] | ||
65 | then | ||
66 | wget -qO- "$URL" | gunzip | egrep "^($RADIO),($MCC)," > $OCI_FILE | ||
67 | manage_backup $OCI_FILE | ||
68 | else | ||
69 | echo $EMPTY > $OCI_FILE | ||
70 | fi | ||
71 | } | ||
72 | |||
73 | function download_mozilla | ||
74 | { | ||
75 | if [ $ENABLE_MOZ == "1" ] | ||
76 | then | ||
77 | NW=`date -u "+%Y-%m-%d"` | ||
78 | wget -qO- "https://d17pt8qph6ncyq.cloudfront.net/export/MLS-full-cell-export-${NW}T000000.csv.gz" | gunzip | egrep "^($RADIO),($MCC)," > $MOZ_FILE | ||
79 | manage_backup $MOZ_FILE | ||
80 | else | ||
81 | echo $EMPTY > $MOZ_FILE | ||
82 | fi | ||
83 | } | ||
84 | |||
85 | function download_radiocells | ||
86 | { | ||
87 | if [ $ENABLE_RCO == "1" ] | ||
88 | then | ||
89 | RCO_SELECT="SELECT technology, mcc, mnc, area, cid, NULL, longitude, latitude, 1000 accuracy, measurements, NULL, NULL, NULL, NULL FROM cell_zone;" | ||
90 | wget -qO- "https://cdn.radiocells.org/"$RCO_SRC_FILE > $TMPDIR"/"$RCO_SRC_FILE | ||
91 | sqlite3 -header -csv $TMPDIR"/"$RCO_SRC_FILE "$RCO_SELECT" | egrep "^($RADIO),($MCC)," > $RCO_FILE | ||
92 | rm $TMPDIR"/"$RCO_SRC_FILE | ||
93 | manage_backup $RCO_FILE | ||
94 | else | ||
95 | echo $EMPTY > $RCO_FILE | ||
96 | fi | ||
97 | } | ||
98 | |||
99 | echo "Downloading data" | ||
100 | |||
101 | download_ocid & | ||
102 | OP=$! | ||
103 | download_mozilla & | ||
104 | MO=$! | ||
105 | download_radiocells & | ||
106 | RO=$! | ||
107 | |||
108 | wait $OP | ||
109 | wait $MO | ||
110 | wait $RO | ||
111 | |||
112 | if [ -s $MOZ_FILE ] && [ -s $OCI_FILE ] && [ -s $RCO_FILE ] | ||
113 | then | ||
114 | |||
115 | manage_backup lacells.db | ||
116 | rm lacells.db | ||
117 | |||
118 | echo "Generating database" | ||
119 | |||
120 | sqlite3 lacells.db <<-SQL | ||
121 | PRAGMA synchronous = OFF; | ||
122 | PRAGMA journal_mode = OFF; | ||
123 | |||
124 | CREATE TEMP TABLE cells_import (radio TEXT,mcc INTEGER,mnc INTEGER,lac INTEGER,cid INTEGER,unit STRING,longitude NUMERIC,latitude NUMERIC,accuracy INTEGER,samples INTEGER,changeable BOOLEAN,created INTEGER,updated INTEGER, avgSignal INTEGER); | ||
125 | CREATE TABLE cells (mcc INTEGER,mnc INTEGER,lac INTEGER,cid INTEGER,longitude REAL,latitude REAL,altitude REAL,accuracy REAL,samples INTEGER); | ||
126 | |||
127 | .header on | ||
128 | .mode csv | ||
129 | |||
130 | .import "$OCI_FILE" cells_import | ||
131 | .import "$MOZ_FILE" cells_import | ||
132 | .import "$RCO_FILE" cells_import | ||
133 | |||
134 | UPDATE cells_import SET samples=1 WHERE samples IS NULL OR samples < 1; | ||
135 | |||
136 | INSERT INTO cells | ||
137 | SELECT mcc, mnc, lac, cid, | ||
138 | sum(longitude * samples) / sum(samples) as longitude, | ||
139 | sum(latitude * samples) / sum(samples) as latitude, | ||
140 | -1 as altitude, | ||
141 | sum(accuracy * samples) / sum(samples) as accuracy, | ||
142 | sum(samples) as samples | ||
143 | FROM cells_import | ||
144 | GROUP BY mcc, mnc, lac, cid; | ||
145 | |||
146 | DROP TABLE cells_import; | ||
147 | |||
148 | UPDATE cells SET accuracy=500 WHERE accuracy < 500; | ||
149 | UPDATE cells SET accuracy=100000 WHERE accuracy > 100000; | ||
150 | |||
151 | CREATE INDEX _idx1 ON cells (mcc, mnc, lac, cid); | ||
152 | CREATE INDEX _idx2 ON cells (lac, cid); | ||
153 | |||
154 | VACUUM; | ||
155 | SQL | ||
156 | |||
157 | else | ||
158 | echo "Download error" | ||
159 | fi | ||
160 | |||
161 | rm $OCI_FILE | ||
162 | rm $MOZ_FILE | ||
163 | rm $RCO_FILE | ||