1#!/bin/sh 2 3die() { echo >&2 "$@"; exit 1; } 4 5( [ $# -ge 1 ] && [ $# -le 3 ] ) || die "Syntax: $0 [-n] <campaignd version> <port number>" 6 7set -o errexit 8set -o nounset 9 10run="" 11 12[ "$1" = "-n" ] && { run=echo; shift; } 13VERSION="$1" 14PORT="$2" 15 16prefix="$HOME/campaignd" 17 18if [ ! -d "$prefix" ]; then 19 die "FATAL: campaignd prefix \`$prefix\` missing!" 20fi 21 22instance="$prefix/$VERSION" 23control_fifo="$instance/socket" 24server_cfg="$instance/server.cfg" 25 26if [ "$run" = "echo" ]; then 27 server_cfg=/dev/null 28else 29 set -x 30fi 31 32$run mkdir "$instance" 33$run mkdir "$instance/data" 34$run mkdir "$instance/logs" 35$run mknod "$control_fifo" p 36 37$run ln -sf "../COPYING.txt" "$instance/COPYING.txt" 38$run ln -sf "$instance/current.log" "$HOME/$VERSION.log" 39 40# Create the initial configuration for a server in read-only mode. 41$run cat > "$server_cfg" <<EOF 42compress_level=9 43control_socket="$control_fifo" 44port=$PORT 45stats_exempt_ips="192.168.*,127.0.0.1" 46read_only=yes 47[server_info] 48 feedback_url_format="https://r.wesnoth.org/t\$topic_id" 49[/server_info] 50[campaigns] 51[/campaigns] 52EOF 53 54set +x 55 56if [ "$run" != "echo" ]; then 57 echo '************************************************************************' 58 echo "Instance created. To disable read-only mode for officially opening it " 59 echo "up to users, run \`send_campaignd_command $VERSION readonly no\` after " 60 echo "starting it for the first time." 61 echo '************************************************************************' 62fi 63