Page MenuHomeDevCentral

new-site-in-source-templates-generator

Authored By
dereckson
Nov 23 2014, 21:27
Size
1 KB
Referenced Files
None
Subscribers
None

new-site-in-source-templates-generator

#!/bin/sh
#
# Nasqueron Tools helper script
#
# Handles a new site on wikimedia/write/sourcetemplatesgenerator
#
# Usage: new-site-in-source-templates-generator http://www.domain.tld/ ClassNameForDomain
#
BASE=/home/dereckson/dev/nasqueron/tools
DIR=$BASE/packages/source-templates-generator
TEMPLATE=$BASE/support/ClassExtendingPage.tmpl
INDEX=$DIR/pages/index.dat
EDITOR=nano
# Helper function
uppers=ABCDEFGHIJKLMNOPQRSTUVWXYZ
lowers=abcdefghijklmnopqrstuvwxyz
strtolower () {
# -- technosaurus, http://stackoverflow.com/a/8952274/1930997
i=0
while ([ $i -lt ${#1} ]) do
CUR=${1:$i:1}
case $uppers in
*$CUR*)CUR=${uppers%$CUR*};OUTPUT="${OUTPUT}${lowers:${#CUR}:1}";;
*)OUTPUT="${OUTPUT}$CUR";;
esac
i=$((i+1))
done
echo "${OUTPUT}"
}
# Checks arguments
if [ $# -eq 2 ]; then
if [ $(echo $1 | grep -E "^https?://.*?/$") ]; then
URL=$1
else
echo "Not a valid URL: $1"
echo "Expected format: http://www.domain.tld/"
exit 2
fi
CLASS=$2
CLASSFILE=$DIR/pages/`echo $CLASS | tr [A-Z] [a-z]`.php
else
echo "Usage: $0 http://www.domain.tld/ ClassNameForDomain"
exit 1
fi
# Generates content
#Creates the class file from template
cat $TEMPLATE | sed "s/%%class%%/$CLASS/g" | sed "s!%%url%%!$URL!g" > $CLASSFILE
#Adds the class to index.dat
printf "%s\t%s" $URL $CLASS >> $INDEX
sort $INDEX -o $INDEX
#Launches editor, then shows the Git state of the repository
$EDITOR $CLASSFILE
cd $DIR
git status

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
206
Default Alt Text
new-site-in-source-templates-generator (1 KB)

Event Timeline