meta données pour cette page
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente | |||
dokuwiki:automated-updates [2020/12/14 02:09] ztrulphcs supprimée |
— (Version actuelle) | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Automatic translation-chek update crontab ===== | ||
- | |||
- | I have a cron job that is responsible for updating the | ||
- | [[doku>: | ||
- | page on [[doku> | ||
- | |||
- | Each day, this cron job updates a DokuWiki git repository clone, | ||
- | checks the DokuWiki site to guess if it is safe to send a page there, | ||
- | runs the checklanguage.php tests, and sends the page. | ||
- | |||
- | This page documents how I do this. | ||
- | |||
- | ===== File layout ===== | ||
- | |||
- | I always keep my cronjobs and their needed files in a separate directory. | ||
- | In this case, this is the '' | ||
- | |||
- | In this directory, there are : | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | The cronjob must be able to write to : | ||
- | * '' | ||
- | * '' | ||
- | * ''/ | ||
- | |||
- | < | ||
- | MyCrontabDir | ||
- | ├── doc/ | ||
- | │ ├── documentation.src | ||
- | │ ├── documentation.txt | ||
- | │ └── Makefile | ||
- | ├── dw-update-tr* | ||
- | └── helper/ | ||
- | ├── checklanguage.php | ||
- | ├── dokuwiki/ | ||
- | │ ├── bin/ | ||
- | │ ├── checklanguage.php | ||
- | │ ├── conf/ | ||
- | │ ├── COPYING | ||
- | │ ├── _cs/ | ||
- | │ ├── data/ | ||
- | │ ├── doku.php | ||
- | │ ├── feed.php | ||
- | │ ├── .git/ | ||
- | │ ├── .gitignore | ||
- | │ ├── .htaccess.dist | ||
- | │ ├── inc/ | ||
- | │ ├── index.php | ||
- | │ ├── install.php | ||
- | │ ├── lib/ | ||
- | │ ├── README | ||
- | │ └── _test/ | ||
- | ├── dw-creds | ||
- | ├── saptdvhf* | ||
- | └── tmp/ | ||
- | └── resultat | ||
- | |||
- | 12 directories, | ||
- | </ | ||
- | |||
- | ===== commands needed by this script ===== | ||
- | |||
- | * bash | ||
- | * test, mkdir, cp, rm, .... | ||
- | * curl | ||
- | * sed | ||
- | * awk | ||
- | * md5sum | ||
- | * git | ||
- | * php | ||
- | |||
- | ===== preventing the script to run ===== | ||
- | |||
- | At DokuWiki, it is possible to prevent my own crontab to work ! Yes remote | ||
- | control is available... | ||
- | |||
- | The cron job uses a dedicated dokuwiki account to send the page. Disabling this account will prevent the cron job to work. current account is '' | ||
- | |||
- | Another solution is to modify, the script on the dokuwiki page. The cronjob tests if there was a modification before sending its result page. | ||
- | For example, on DokuWiki page, adding a line just below "''<? | ||
- | that reads | ||
- | < | ||
- | will prevent my own cronjob to run. If this line is removed and the script | ||
- | comes back to the exact version it was, then my cronjob will run again. | ||
- | |||
- | Isn't that beautiful ? | ||
- | |||
- | ===== The script dw-update-tr ===== | ||
- | |||
- | The script that glues all this together is not very complicated. There are 2 things to note about it, tough. | ||
- | |||
- | It sets TZ variable in a form that is suitable to both the system it is running on, and "php -d ' | ||
- | |||
- | Before actually running the php test and sending the result page to dokuwiki, it | ||
- | tries to download the checklanguage.php script from dokuwiki. If the downloaded | ||
- | (or not downloaded) script md5sum is different from a known md5sum, then | ||
- | obviously, the script on the page has been modified (or removed), and the | ||
- | script should not run nor send itself to DokuWiki site. | ||
- | |||
- | **NB**\\ | ||
- | Even when successful, the cron job will print things to stderr, mainly because | ||
- | helper/ | ||
- | |||
- | <file bash dw-update-tr> | ||
- | #! /bin/bash | ||
- | set -e # stop at first error | ||
- | |||
- | IFS=' | ||
- | ' | ||
- | PATH=/ | ||
- | myself=${0} | ||
- | case " | ||
- | (/*) : ;; | ||
- | (*) myself=$PWD/ | ||
- | esac | ||
- | |||
- | here=${myself%/ | ||
- | mkdir -p " | ||
- | # export ALL_PROXY=yourproxy.example.com: | ||
- | #export TZ=' | ||
- | export TZ=' | ||
- | |||
- | pageid=playground: | ||
- | pageid=teams: | ||
- | |||
- | cd " | ||
- | rm -f checklanguage.php | ||
- | git pull | ||
- | |||
- | # Now, check that the page still exists and that code has not changed | ||
- | # 1st grep the url of the codeblock that contains checklanguage.php | ||
- | |||
- | set -- $( | ||
- | { | ||
- | curl -s https:// | ||
- | } | sed -ne '/ | ||
- | ) | ||
- | # then download the code and compute its md5sum | ||
- | set -- $( | ||
- | { | ||
- | curl -s \ | ||
- | " | ||
- | | ||
- | : | ||
- | } | { | ||
- | md5sum || | ||
- | : | ||
- | } | ||
- | ) | ||
- | # check md5sum of the script is acceptable | ||
- | case " | ||
- | (8774f57c1db518f00c31f37ddc1ec002 | ab6b15cba28a30c0bb827d3912609b7f | b9ec3070fd0e00c4c9adf6b873538699 | 8abf956295de1363af1d26e8b6deae39 | d27024fc625536d934092d4645f07376 ) | ||
- | : | ||
- | ;; | ||
- | (*) | ||
- | exit 1 | ||
- | ;; | ||
- | esac | ||
- | |||
- | # OK ! let's go marco. | ||
- | ln ../ | ||
- | php -d " | ||
- | |||
- | " | ||
- | -p " | ||
- | -i " | ||
- | https:// | ||
- | </ | ||
- | |||
- | ===== The crontab command ===== | ||
- | |||
- | < | ||
- | 50 6 * * * /bin/true / | ||
- | </ | ||
- | |||
- | ===== Archive ===== | ||
- | |||
- | Here is the archive that contains everything : {{update-dokuwiki-translation-check.tar.bz2}} | ||
- | |||
- | Untar it whereever it pleases you, all paths are relative. | ||
- | |||
- | Once it is untarred, there remains 2 things to do | ||
- | - get a dokuwiki git repository clone in the helper directory. See [[doku> | ||
- | cd update-dokuwiki-translation-check/ | ||
- | git clone git:// | ||
- | </ | ||
- | - create a file that contains dokuwiki login and password suitable to send pages to DokuWiki site. You should really create a dedicated account on [[doku> | ||
- | cd update-dokuwiki-translation-check/ | ||
- | ./saptdvhf create-ident-file dw-creds | ||
- | </ | ||
- | |||