Benutzer:Andreas Plank/Wiki-Skripte: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(→Extension herunterladen und extrahieren: +extensions +backup date nach modification date des Ordners) |
(→Extension herunterladen und extrahieren: +prompt extension list & matching test +documentation) |
||
Zeile 31: | Zeile 31: | ||
EXTURL[UserMerge]=https://extdist.wmflabs.org/dist/extensions/UserMerge-REL1_31-a641f0c.tar.gz | EXTURL[UserMerge]=https://extdist.wmflabs.org/dist/extensions/UserMerge-REL1_31-a641f0c.tar.gz | ||
EXTURL[Variables]=https://extdist.wmflabs.org/dist/extensions/Variables-REL1_31-872663b.tar.gz | EXTURL[Variables]=https://extdist.wmflabs.org/dist/extensions/Variables-REL1_31-872663b.tar.gz | ||
+ | |||
+ | ### Variables End | ||
+ | |||
+ | # get extensionList | ||
+ | extensionList="" | ||
+ | for thisExt in "${!EXTURL[@]}"; | ||
+ | do | ||
+ | [[ -z ${extensionList// /} ]] && extensionList="$thisExt" || extensionList="$extensionList $thisExt" | ||
+ | # test if extension matches in URL | ||
+ | if [[ ${EXTURL[$thisExt]} != *${thisExt}* ]];then | ||
+ | echo -e "\033[0;31m# WARNING ${thisExt} does not match in ${EXTURL[$thisExt]}\033[0m" | ||
+ | fi | ||
+ | done | ||
+ | |||
+ | # prompt before starting | ||
+ | echo -e "\033[0;32m##########################\033[0m" | ||
+ | echo -e "\033[0;32m# Extract ${#EXTURL[@]} Extensions ...\033[0m" | ||
+ | echo -e "\033[0;32m# $extensionList\033[0m" | ||
+ | echo -e "\033[0;32m# ... to $wikiExtPath ?\033[0m" | ||
+ | echo -en "\033[0;32m# yes or no (default: no)\033[0m " | ||
+ | |||
+ | read yesno | ||
+ | if [[ -z ${yesno// /} ]];then yesno="no"; fi | ||
+ | case $yesno in | ||
+ | [yY]|[yY][eE][sS]) | ||
+ | echo "# continue ..." | ||
+ | ;; | ||
+ | [nN]|[nN][oO]) | ||
+ | echo "### Stop"; | ||
+ | exit 1 | ||
+ | ;; | ||
+ | *) | ||
+ | if [[ -z ${yesno// /} ]];then | ||
+ | echo -e "\033[0;32m### Stop\033[0m" | ||
+ | else | ||
+ | echo "### Wrong input „${yesno}“ (Stop)" | ||
+ | fi | ||
+ | exit 1 | ||
+ | ;; | ||
+ | esac | ||
i_ext=1 | i_ext=1 |
Version vom 12. Juli 2018, 10:25 Uhr
Extension herunterladen und extrahieren
BASH Skript zum Herunterladen von Extensions in das Benutzerverzeichnis ~/tmp
und extrahieren in den Wiki-Ordner $wikiExtPath
#!/bin/bash
# description: What does it do? dowload and extract a standard Wiki extension
# EXTURL stores the extension name and the download URL you can find the tar.gz URL e.g. at
# https://www.mediawiki.org/wiki/Special:ExtensionDistributor/MassEditRegex
# https://www.mediawiki.org/wiki/Special:ExtensionDistributor?extdistname=MassEditRegex&extdistversion=REL1_31
# requires: ~/tmp
### Variables Start
wikiExtPath=/apps/mediawiki/www/extensions/
declare -A EXTURL # associative array
# find the tar.gz URL e.g. at https://www.mediawiki.org/wiki/Special:ExtensionDistributor/MassEditRegex
# EXTURL[CategoryTree]=https://extdist.wmflabs.org/dist/extensions/CategoryTree-REL1_31-c24e5ed.tar.gz
# EXTURL[Cite]=https://extdist.wmflabs.org/dist/extensions/Cite-REL1_31-20e26df.tar.gz
EXTURL[CodeMirror]=https://extdist.wmflabs.org/dist/extensions/CodeMirror-REL1_31-a435d54.tar.gz
# EXTURL[ConfirmEdit]=https://extdist.wmflabs.org/dist/extensions/ConfirmEdit-REL1_31-b52469c.tar.gz
EXTURL[DismissableSiteNotice]=https://extdist.wmflabs.org/dist/extensions/DismissableSiteNotice-REL1_31-73a6b72.tar.gz
EXTURL[Echo]=https://extdist.wmflabs.org/dist/extensions/Echo-REL1_31-ed7f8f4.tar.gz
# EXTURL[Gadgets]=https://extdist.wmflabs.org/dist/extensions/Gadgets-REL1_31-bac29ae.tar.gz
# EXTURL[InputBox]=https://extdist.wmflabs.org/dist/extensions/InputBox-REL1_31-dfec261.tar.gz
EXTURL[MassEditRegex]=https://extdist.wmflabs.org/dist/extensions/MassEditRegex-REL1_31-fcc91e5.tar.gz
EXTURL[MsCalendar]=https://extdist.wmflabs.org/dist/extensions/MsCalendar-REL1_31-4cb0d01.tar.gz
# EXTURL[MsUpload]=https://extdist.wmflabs.org/dist/extensions/MsUpload-REL1_31-2e2efd5.tar.gz
EXTURL[Nuke]=https://extdist.wmflabs.org/dist/extensions/Nuke-REL1_31-c6ec842.tar.gz
EXTURL[Thanks]=https://extdist.wmflabs.org/dist/extensions/Thanks-REL1_31-a845a46.tar.gz
EXTURL[UserMerge]=https://extdist.wmflabs.org/dist/extensions/UserMerge-REL1_31-a641f0c.tar.gz
EXTURL[Variables]=https://extdist.wmflabs.org/dist/extensions/Variables-REL1_31-872663b.tar.gz
### Variables End
# get extensionList
extensionList=""
for thisExt in "${!EXTURL[@]}";
do
[[ -z ${extensionList// /} ]] && extensionList="$thisExt" || extensionList="$extensionList $thisExt"
# test if extension matches in URL
if [[ ${EXTURL[$thisExt]} != *${thisExt}* ]];then
echo -e "\033[0;31m# WARNING ${thisExt} does not match in ${EXTURL[$thisExt]}\033[0m"
fi
done
# prompt before starting
echo -e "\033[0;32m##########################\033[0m"
echo -e "\033[0;32m# Extract ${#EXTURL[@]} Extensions ...\033[0m"
echo -e "\033[0;32m# $extensionList\033[0m"
echo -e "\033[0;32m# ... to $wikiExtPath ?\033[0m"
echo -en "\033[0;32m# yes or no (default: no)\033[0m "
read yesno
if [[ -z ${yesno// /} ]];then yesno="no"; fi
case $yesno in
[yY]|[yY][eE][sS])
echo "# continue ..."
;;
[nN]|[nN][oO])
echo "### Stop";
exit 1
;;
*)
if [[ -z ${yesno// /} ]];then
echo -e "\033[0;32m### Stop\033[0m"
else
echo "### Wrong input „${yesno}“ (Stop)"
fi
exit 1
;;
esac
i_ext=1
for thisExt in "${!EXTURL[@]}";
do
# go to local tmp user directory
if ! [[ -d ~/tmp ]];then mkdir ~/tmp; echo "# Created user directory ~/tmp";fi
cd ~/tmp
echo "### Step $i_ext of ${#EXTURL[@]}"
echo "# Download $thisExt to `pwd`…"
wget --no-verbose "${EXTURL[$thisExt]}"
if [[ -d "${wikiExtPath}${thisExt}" ]];then
# last modification timed as backup date e.g. MassEditRegex_2017-09-22
modDate=$(stat -c %y "${wikiExtPath}${thisExt}")
modDate=${modDate%% *} # remove from 1st space to the end in date time: 2017-09-22 00:12:10.000000000 +0200
thisBackupPath="${wikiExtPath}${thisExt}_${modDate}"
echo "# Back up $thisExt to ${thisBackupPath} …"
mv "${wikiExtPath}${thisExt}" "${thisBackupPath}";
fi
echo "# Extract tar archive ${EXTURL[$thisExt]##*/} to ${wikiExtPath} …"
tar -xzf "${EXTURL[$thisExt]##*/}" -C "${wikiExtPath}"
i_ext=$(( i_ext + 1 ))
done