Main Page

From wiki
Revision as of 07:39, 30 October 2025 by Sysop (talk | contribs) (→‎check)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

CompGen e.V. Semantic MediaWiki Playgrounds

Discourse-Thema

Discourse - mediawiki-playgrounds

Wiki-Migration

Wiki-Migration 2024-10-23

Auswahl der Namen

Wikipush Experimente

WikiUser Einrichtung

Beispiel für https://www.semantic-mediawiki.org

cd $HOME/.mediawiki-japi
cat ${USER}_smw.ini 
#Mediawiki JAPI credentials for smw
#Tue Oct 06 13:20:42 CEST 2020
scriptPath=/w
url=https://www.semantic-mediawiki.org
wikiId=smw
version=MediaWiki 1.31.10

Wikipush Test

wikipush -s smw -t Zeus -p Demo:Berlin Property:Has_Wikidata_item_ID Berlin
copying 2 pages from smw to Zeus
1/2 (  50%): copying ... Property:Has_Wikidata_item_ID✅
2/2 ( 100%): copying ... Berlin✅

siehe

Installation

Setup

siehe Setup Special:Version

setup_wikis script

see also https://github.com/WolfgangFahl/genwiki2024/blob/main/genwiki/playground.py

Usage

./setup_wikis -h
setup_wikis -h
Usage: setup_wikis [OPTIONS]
Options:
  -h, --help         Show this help message
  -c, --clean        Clean the Docker environment
  --check            Check the status of selected wikis
  -d, --debug        Enable debug output
  --patch            Patch all wikis
  -p, --passwords    Show the sysop passwords of the wikis
  -s, --setup        Setup the selected wikis
  -v, --version      Show version information
  -w, --wiki NAME    Specify the wiki to operate on (use 'all' for all wikis)

check

setup_wikis -w Zeus --check
Checking Zeus wiki on ports 9186/9187:
checking docker access for mediawiki versions ['1.39.10']
1:checking 1.39.10 ...
mediawiki webserver container Zeus-mw:✅
mediawiki database container Zeus-db:✅
port binding 9186= expected  port 9186?:✅
Checking http://playground-mw.bitplan.com/Zeus/index.php?title=Special:Version ...
Special Version accessible ...:✅
Mediawiki Version 1.39.8= expected  1.39.10?:❌
✅

source code

#!/bin/bash
# Setup script for Wiki Playgrounds
# generated by playground.py
# https://github.com/WolfgangFahl/genwiki2024/blob/main/genwiki/playground.py
# $Header: /home/wf/bin/RCS/setup_wikis,v 1.13 2025/02/18 06:47:36 wf Exp wf $

host="playground-mw.bitplan.com"
base_port=9100

# Color definitions
blue='\033[0;34m'
red='\033[0;31m'
green='\033[0;32m'
endColor='\033[0m'

# Function to display colored messages
color_msg() {
  local l_color="$1"
  local l_msg="$2"
  echo -e "${l_color}$l_msg${endColor}"
}

# Function to display errors
error() {
  local l_msg="$1"
  color_msg $red "Error:" 1>&2
  color_msg $red "\t$l_msg" 1>&2
  exit 1
}

# Function to display negative messages
negative() {
  local l_msg="$1"
  color_msg $red "❌:$l_msg"
}

# Function to display positive messages
positive() {
  local l_msg="$1"
  color_msg $green "✅:$l_msg"
}

# Function to display usage information
# Sort usage options alphabetically with -h first
usage() {
    script=$(basename $0)
    echo "Usage: $script [OPTIONS]"
    echo "Options:"
    echo "  -h, --help         Show this help message"
    echo "  -b, --bash NAME    Bash into the container for the specified god"
    echo "  -c, --clean        Clean the Docker environment"
    echo "  --check            Check the status of selected wikis"
    echo "  -d, --debug        Enable debug output"
    echo "  -fp, --fix-permissions Fix permissions for all containers"
    echo "  --patch            Patch all wikis"
    echo "  -p, --passwords    Show the sysop passwords of the wikis"
    echo "  -s, --setup        Setup the selected wikis"
    echo "  -v, --version      Show version information"
    echo "  -w, --wiki NAME    Specify the wiki to operate on (use 'all' for all wikis)"
    exit 1
}


set -e  # Exit on error

declare -a gods=(
    "Aglaea" "Amicitia" "Anteros" "Ares" "Aristaeus" "Artemis" "Bia" 
    "Britomartis" "Carpo" "Charon" "Deimos" "Demeter" "Despoina" 
    "Eileithyia" "Eirene" "Enyo" "Eos" "Eris" "Eunomia" "Euphrosyne" 
    "Hades" "Hebe" "Helios" "Hemera" "Hephaestus" "Hera" "Hermaphroditus" 
    "Hestia" "Himeros" "Hypnos" "Iris" "Kratos" "Momus" "Nike" "Panacea" 
    "Phobos" "Phosphorus" "Plutus" "Poseidon" "Telesphorus" "Thalia" 
    "Thallo" "Thanatos" "Zeus"
)

# Function to fix permissions in all containers
fix_permissions() {
    for god in "${selected_gods[@]}"; do
        local container_name="${god}-mw"
        echo "🔧 Fixing permissions for container: $container_name"
        docker exec "$container_name" bash -c "
            chown -R www-data:www-data /var/www/html &&
            chmod -R g+w /var/www/html/images &&
            chmod -R g+w /var/www/html/cache" \
        && positive "Permissions fixed for $container_name" \
        || negative "Failed to fix permissions for $container_name"
    done
}

#
# clean up the docker env
#
clean_docker() {
   echo "⚠️  WARNING: This will remove all Docker containers, images, and volumes"
   read -p "Are you sure you want to continue? (y/N) " -n 1 -r
   echo
   if [[ $REPLY =~ ^[Yy]$ ]]; then
       echo "🗑️  Cleaning up Docker environment..."
       docker kill $(docker ps -q) 2>/dev/null || true
       docker rm $(docker ps -aq) 2>/dev/null || true
       docker rmi $(docker images -q) 2>/dev/null || true
       docker volume rm $(docker volume ls -qf dangling=true) 2>/dev/null || true
       docker system prune --force

       echo "🗑️  Removing MediaWiki configurations..."
       rm -rf $HOME/.pymediawikidocker/*

       echo "✅ Cleanup complete"
   else
       echo "Cleanup cancelled"
   fi
}

# Function to calculate port for a specific god
get_port_offset() {
    local target_god="$1"
    local offset=0
    for god in "${gods[@]}"; do
        if [ "$god" = "$target_god" ]; then
            echo $offset
            return
        fi
        offset=$((offset + 2))
    done
}

# Function to bash into a container by god name
bash_into_container() {
    local god_name="$1"
    local container_name="${god_name}-mw"

    # Check if the container exists
    if docker ps -a --format '{{.Names}}' | grep -q "^${container_name}$"; then
        # Check if the container is running
        if docker ps --format '{{.Names}}' | grep -q "^${container_name}$"; then
            echo "🐚 Opening bash shell in $container_name..."
            docker exec -it "$container_name" bash
        else
            error "Container $container_name exists but is not running"
        fi
    else
        error "Container $container_name does not exist"
    fi
}

#
# show the passwords
#
show_passwords() {
   for god in "${selected_gods[@]}"; do
       local script="$HOME/.pymediawikidocker/$god/addSysopUser.sh"
       if [ -f "$script" ]; then
           echo -n "$god: "
	   awk -F'"' '/--sysop/ {print $2 " " $4}' "$script"
       fi
   done
}

# Function to patch a specific setting in LocalSettings.php
patch_setting() {
   local god=$1
   local setting=$2
   local value=$3
   local script="/var/www/html/LocalSettings.php"
   docker exec "$god-mw" bash -c "sed -i 's#^\\\$$setting = .*#\\\$$setting = \"$value\";#' $script" || return 1
}

# 
# path a single wiki
#
patch_wiki() {
   local god=$1
   local script_path="/$god"
   local article_path="/$god/index.php?title=\\\\\$1"
   local server="http://$host"

   patch_setting "$god" "wgScriptPath" "$script_path"
   patch_setting "$god" "wgArticlePath" "$article_path"
   patch_setting "$god" "wgServer" "$server"

   # Run grep and capture the result
   result=$(docker exec "$god-mw" bash -c "grep 'wgArt\|wgScriptPath\|wgServer\|wgArticlePath' /var/www/html/LocalSettings.php")
   color_msg $blue "$result"

   # Check if grep returned anything and output result
   if [[ -n "$result" ]]; then
      positive "Patched $god wiki settings successfully."
   else
      negative "Failed to patch $god wiki settings."
   fi
}

#
# patch selected wikis
#
patch_wikis() {
   for god in "${selected_gods[@]}"; do
       if [ -d "$HOME/.pymediawikidocker/$god" ]; then
           patch_wiki "$god"
       fi
   done
}

#
# check selected wikis
# 
check_wikis() {
   for god in "${selected_gods[@]}"; do
       local mw_port=$base_port
       local sql_port=$((base_port + 1))
       local script_path="/$god"

       echo "Checking $god wiki on ports $mw_port/$sql_port:"
       mwcluster --check --container_name $god --version_list 1.39.10 \
         --base_port $mw_port --sql_base_port $sql_port --host $host \
         --script_path $script_path \
         --article_path "$god/index.php?title=\$1" \
       | tee /dev/tty | grep "Special Version accessible" | grep -q "✅" \
       && echo "✅" || echo "❌"

       base_port=$((base_port + 2))
   done
}

#
# setup a wiki per god
#
setup_wikis() {

for god in "${selected_gods[@]}"; do
    mw_port=$base_port
    sql_port=$((base_port + 1))
    
    if [ -d "$HOME/.pymediawikidocker/$god" ]; then
        echo "⏭️  $god wiki already exists, skipping..."
    else
        echo "🏗️  Setting up $god wiki..."
	profiwiki -rp -fu -cn "$god" -bp $mw_port -sp $sql_port --all -f \
	  --article_path "$god/index.php?title=\$1" \
          --host $host
    fi
    base_port=$((base_port + 2))
done
}

# Default to all gods if no wiki name is provided
selected_gods=("${gods[@]}")
while [[ $# -gt 0 ]]; do
  case $1 in
    -b|--bash)
    if [ -z "$2" ]; then
        error "Missing god name argument"
    fi
    bash_into_container "$2"
    exit 0
    ;;
    --clean) clean_docker; exit 0 ;;
    --check) check_wikis; exit 0 ;;
    -d|--debug) set -x;;
    -fp|--fix-permissions) fix_permissions; exit 0 ;;
    -h|--help) usage ;;
    --patch) patch_wikis; exit 0 ;;
    -p|--passwords) show_passwords; exit 0 ;;
    -s|--setup) setup_wikis; exit 0 ;;
    -w|--wiki)
     if [ -z "$2" ]; then
         error "Missing wiki name argument"
     fi
     god_name="$2"
     shift
     base_port=9100
     if [[ "$god_name" == "all" ]]; then
        selected_gods=("${gods[@]}")
     else
        selected_gods=("$god_name")
        # Calculate correct base_port for single god
        for god in "${gods[@]}"; do
            if [ "$god" = "$god_name" ]; then
                break
            fi
            base_port=$((base_port + 2))
        done
     fi
    ;;
    --version) echo "Version: $VERSION"; exit 0 ;;
    *) error "Unknown option: $1" ;;
  esac
  shift
done