Move dev executables from util/ to bin/dev/

This commit is contained in:
Hypolite Petovan 2018-04-07 09:00:52 -04:00
parent 59d42e9681
commit 2d9f32c3df
6 changed files with 1 additions and 1 deletions

View file

@ -0,0 +1,241 @@
#!/usr/bin/python
#
# Script to convert Friendica internal template files into Smarty template files
# Copyright 2013 Zach Prezkuta
# Licensed under GPL v3
import os, re, string
import sys, getopt
ldelim = '{{'
rdelim = '}}'
addheader = True
def fToSmarty(matches):
match = matches.group(0)
if match == '$j':
return match
match = string.replace(match, '[', '')
match = string.replace(match, ']', '')
ldel = ldelim
rdel = rdelim
if match.find("'") > -1:
match = string.replace(match, "'", '')
ldel = "'" + ldel
rdel = rdel + "'"
elif match.find('"') > -1:
match = string.replace(match, '"', '')
ldel = '"' + ldel
rdel = rdel + '"'
return ldel + match + rdel
def fix_element(element):
# Much of the positioning here is important, e.g. if you do element.find('if ') before you do
# element.find('endif'), then you may get some multiply-replaced delimiters
if element.find('endif') > -1:
element = ldelim + '/if' + rdelim
return element
if element.find('if ') > -1:
element = string.replace(element, '{{ if', ldelim + 'if')
element = string.replace(element, '{{if', ldelim + 'if')
element = string.replace(element, ' }}', rdelim)
element = string.replace(element, '}}', rdelim)
return element
if element.find('else') > -1:
element = ldelim + 'else' + rdelim
return element
if element.find('endfor') > -1:
element = ldelim + '/foreach' + rdelim
return element
if element.find('for ') > -1:
element = string.replace(element, '{{ for ', ldelim + 'foreach ')
element = string.replace(element, '{{for ', ldelim + 'foreach ')
element = string.replace(element, ' }}', rdelim)
element = string.replace(element, '}}', rdelim)
return element
if element.find('endinc') > -1:
element = ''
return element
if element.find('inc ') > -1:
parts = element.split(' ')
element = ldelim + 'include file="'
# We need to find the file name. It'll either be in parts[1] if the element was written as {{ inc file.tpl }}
# or it'll be in parts[2] if the element was written as {{inc file.tpl}}
if parts[0].find('inc') > -1:
first = 0
else:
first = 1
if parts[first+1][0] == '$':
# This takes care of elements where the filename is a variable, e.g. {{ inc $file }}
element += ldelim + parts[first+1].rstrip('}') + rdelim
else:
# This takes care of elements where the filename is a path, e.g. {{ inc file.tpl }}
element += parts[first+1].rstrip('}')
element += '"'
if len(parts) > first + 1 and parts[first+2] == 'with':
# Take care of variable substitutions, e.g. {{ inc file.tpl with $var=this_var }}
element += ' ' + parts[first+3].rstrip('}')[1:]
element += rdelim
return element
def convert(filename, tofilename, php_tpl):
if addheader:
header = ldelim + "*\n *\tAUTOMATICALLY GENERATED TEMPLATE\n *\tDO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN\n *\n *" + rdelim + "\n"
tofilename.write(header)
for line in filename:
newline = ''
st_pos = 0
brack_pos = line.find('{{')
if php_tpl:
# If php_tpl is True, this script will only convert variables in quotes, like '$variable'
# or "$variable". This is for .tpl files that produce PHP scripts, where you don't want
# all the PHP variables converted into Smarty variables
pattern1 = re.compile(r"""
([\'\"]\$\[[a-zA-Z]\w*
(\.
(\d+|[a-zA-Z][\w-]*)
)*
(\|[\w\$:\.]*)*
\][\'\"])
""", re.VERBOSE)
pattern2 = re.compile(r"""
([\'\"]\$[a-zA-Z]\w*
(\.
(\d+|[a-zA-Z][\w-]*)
)*
(\|[\w\$:\.]*)*
[\'\"])
""", re.VERBOSE)
else:
# Compile the pattern for bracket-style variables, e.g. $[variable.key|filter:arg1:arg2|filter2:arg1:arg2]
# Note that dashes are only allowed in array keys if the key doesn't start
# with a number, e.g. $[variable.key-id] is ok but $[variable.12-id] isn't
#
# Doesn't currently process the argument position key 'x', i.e. filter:arg1:x:arg2 doesn't get
# changed to arg1|filter:variable:arg2 like Smarty requires
#
# Filter arguments can be variables, e.g. $variable, but currently can't have array keys with dashes
# like filter:$variable.key-name
pattern1 = re.compile(r"""
(\$\[[a-zA-Z]\w*
(\.
(\d+|[a-zA-Z][\w-]*)
)*
(\|[\w\$:\.]*)*
\])
""", re.VERBOSE)
# Compile the pattern for normal style variables, e.g. $variable.key
pattern2 = re.compile(r"""
(\$[a-zA-Z]\w*
(\.
(\d+|[a-zA-Z][\w-]*)
)*
(\|[\w\$:\.]*)*
)
""", re.VERBOSE)
while brack_pos > -1:
if brack_pos > st_pos:
line_segment = line[st_pos:brack_pos]
line_segment = pattern2.sub(fToSmarty, line_segment)
newline += pattern1.sub(fToSmarty, line_segment)
end_brack_pos = line.find('}}', brack_pos)
if end_brack_pos < 0:
print "Error: no matching bracket found"
newline += fix_element(line[brack_pos:end_brack_pos + 2])
st_pos = end_brack_pos + 2
brack_pos = line.find('{{', st_pos)
line_segment = line[st_pos:]
line_segment = pattern2.sub(fToSmarty, line_segment)
newline += pattern1.sub(fToSmarty, line_segment)
newline = newline.replace("{#", ldelim + "*")
newline = newline.replace("#}", "*" + rdelim)
tofilename.write(newline)
def help(pname):
print "\nUsage:"
print "\t" + pname + " -h\n\n\t\t\tShow this help screen\n"
print "\t" + pname + " -p directory\n\n\t\t\tConvert all .tpl files in directory to\n\t\t\tSmarty templates in directory/smarty3/\n"
print "\t" + pname + "\n\n\t\t\tInteractive mode\n"
#
# Main script
#
path = ''
try:
opts, args = getopt.getopt(sys.argv[1:], "hp:", ['no-header'])
for opt, arg in opts:
if opt == '-h':
help(sys.argv[0])
sys.exit()
elif opt == '-p':
path = arg
elif opt == '--no-header':
addheader = False
except getopt.GetoptError:
help(sys.argv[0])
sys.exit(2)
if path == '':
path = raw_input('Path to template folder to convert: ')
if path[-1:] != '/':
path = path + '/'
outpath = path + 'smarty3/'
if not os.path.exists(outpath):
os.makedirs(outpath)
files = os.listdir(path)
for a_file in files:
if a_file == 'htconfig.tpl':
php_tpl = True
else:
php_tpl = False
filename = os.path.join(path,a_file)
ext = a_file.split('.')[-1]
if os.path.isfile(filename) and ext == 'tpl':
f = open(filename, 'r')
newfilename = os.path.join(outpath,a_file)
outf = open(newfilename, 'w')
print "Converting " + filename + " to " + newfilename
convert(f, outf, php_tpl)
outf.close()
f.close()

107
bin/dev/make_credits.py Executable file
View file

@ -0,0 +1,107 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This script will collect the contributors to friendica and its translations from
* the git log of the friendica core and addons repositories
* the translated messages.po from core and the addons.
The collected names will be saved in /util/credits.txt which is also parsed from
yourfriendica.tld/credits.
The output is not perfect, so remember to open a fresh (re)created credits.txt file
in your fav editor to check for obvious mistakes and doubled entries.
Initially written by Tobias Diekershoff for the Friendica Project. Released under
the terms of the AGPL version 3 or later, same as Friendica.
"""
from sys import argv
import os, glob, subprocess
# a list of names to not include, those people get into the list by other names
# but they use different names on different systems and automatical mapping does
# not work in some cases.
dontinclude = ['root', 'friendica', 'bavatar', 'tony baldwin', 'Taek', 'silke m',
'leberwurscht', 'abinoam', 'fabrixxm', 'FULL NAME', 'Hauke Zuehl',
'Michal Supler', 'michal_s', 'Manuel Pérez', 'rabuzarus', 'Alberto Díaz']
# this script is in the /util sub-directory of the friendica installation
# so the friendica path is the 0th argument of calling this script but we
# need to remove the name of the file and the name of the directory
path = os.path.abspath(argv[0].split('util/make_credits.py')[0])
print('> base directory is assumed to be: '+path)
# a place to store contributors
contributors = ["Andi Stadler", "Ratten", "Vít Šesták 'v6ak'"]
# get the contributors
print('> getting contributors to the friendica core repository')
p = subprocess.Popen(['git', 'shortlog', '--no-merges', '-s'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
c = iter(p.stdout.readline, b'')
for i in c:
name = i.decode().split('\t')[1].split('\n')[0]
if not name in contributors and name not in dontinclude:
contributors.append(name)
n1 = len(contributors)
print(' > found %d contributors' % n1)
# get the contributors to the addons
try:
os.chdir(path+'/addon')
# get the contributors
print('> getting contributors to the addons')
p = subprocess.Popen(['git', 'shortlog', '--no-merges', '-s'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
c = iter(p.stdout.readline, b'')
for i in c:
name = i.decode().split('\t')[1].split('\n')[0]
if not name in contributors and name not in dontinclude:
contributors.append(name)
except FileNotFoundError:
print(' > no addon directory found ( THE LIST OF CONTRIBUTORS WILL BE INCOMPLETE )')
n2 = len(contributors)
print(' > found %d new contributors' % (n2-n1))
print('> total of %d contributors to the repositories of friendica' % n2)
os.chdir(path)
# get the translators
print('> getting translators')
intrans = False
for f in glob.glob(path+'/view/lang/*/messages.po'):
i = open(f, 'r')
l = i.readlines()
i.close()
for ll in l:
if intrans and ll.strip()=='':
intrans = False;
if intrans and ll[0]=='#':
name = ll.split('# ')[1].split(',')[0].split(' <')[0]
if not name in contributors and name not in dontinclude:
contributors.append(name)
if "# Translators:" in ll:
intrans = True
# get the translators from the addons
for f in glob.glob(path+'/addon/*/lang/*/messages.po'):
i = open(f, 'r')
l = i.readlines()
i.close()
for ll in l:
if intrans and ll.strip()=='':
intrans = False;
if intrans and ll[0]=='#':
name = ll.split('# ')[1].split(',')[0].split(' <')[0]
if not name in contributors and name not in dontinclude:
contributors.append(name)
if "# Translators:" in ll:
intrans = True
# done with the translators
n3 = len(contributors)
print(' > found %d translators' % (n3-n2))
print('> found a total of %d contributors and translators' % n3)
contributors.sort(key=str.lower)
f = open(path+'/util/credits.txt', 'w')
f.write("\n".join(contributors))
f.close()
print('> list saved to util/credits.txt')

50
bin/dev/minifyjs.sh Executable file
View file

@ -0,0 +1,50 @@
#!/bin/bash
command -v uglifyjs >/dev/null 2>&1 || { echo >&2 "I require UglifyJS but it's not installed. Aborting."; exit 1; }
MINIFY_CMD=uglifyjs
JSFILES=(
"view/js/acl.js"
"view/js/ajaxupload.js"
"view/js/country.js"
"view/js/main.js"
"vendor/asset/base64/base64.min.js"
"view/theme/frost/js/acl.js"
"view/theme/frost/js/jquery.divgrow-1.3.1.f1.js"
"view/theme/frost/js/main.js"
"view/theme/frost/js/theme.js"
"view/theme/frost-mobile/js/acl.js"
"view/theme/frost-mobile/js/jquery.divgrow-1.3.1.f1.js"
"view/theme/frost-mobile/js/main.js"
"view/theme/frost-mobile/js/theme.js"
"view/theme/decaf-mobile/js/theme.js"
)
JSFILES2=(
"library/colorbox/jquery.colorbox.js"
)
for i in ${JSFILES[@]}
do
MINFILE=${i%%.js}.min.js
echo "Minifying $i into $MINFILE"
rm $MINFILE
$MINIFY_CMD -o $MINFILE $i
done
for i in ${JSFILES2[@]}
do
MINFILE=${i%%.js}-min.js
echo "Minifying $i into $MINFILE"
rm $MINFILE
$MINIFY_CMD -o $MINFILE $i
done
for i in ${JSFILES3[@]}
do
MINFILE=${i%%_src.js}.js
echo "Minifying $i into $MINFILE"
rm $MINFILE
$MINIFY_CMD -o $MINFILE $i
done

64
bin/dev/updatetpl.py Executable file
View file

@ -0,0 +1,64 @@
#!/usr/bin/python
#
# Script to update Smarty template files from all internal templates
# Copyright 2013 Zach Prezkuta
# Licensed under GPL v3
import os
import sys, getopt
import subprocess
def help(pname):
print "\nUsage:"
print "\t" + pname + " -h\n\n\t\t\tShow this help screen\n"
print "\t" + pname + " -p directory\n\n\t\t\tConvert all .tpl files in top-level\n\t\t\tFriendica directory to Smarty templates\n"
print "\t" + pname + "\n\n\t\t\tInteractive mode\n"
#
# Main script
#
path = ''
try:
opts, args = getopt.getopt(sys.argv[1:], "hp:")
for opt, arg in opts:
if opt == '-h':
help(sys.argv[0])
sys.exit()
elif opt == '-p':
path = arg
except getopt.GetoptError:
help(sys.argv[0])
sys.exit(2)
if path == '':
path = raw_input('Path to top-level Friendica directory: ')
if path[-1:] != '/':
path = path + '/'
tplpaths = ['view/']
names = os.listdir(path + 'view/')
for name in names:
if os.path.isdir(path + 'view/' + name):
if name != 'smarty3' and name != 'theme':
tplpaths.append('view/' + name + '/')
names = os.listdir(path + 'view/theme/')
for name in names:
if os.path.isdir(path + 'view/theme/' + name):
tplpaths.append('view/theme/' + name + '/')
fnull = open(os.devnull, "w")
for tplpath in tplpaths:
print "Converting " + path + tplpath
subprocess.call(['python', path + 'util/friendica-to-smarty-tpl.py', '-p', path + tplpath], stdout = fnull)
fnull.close()

102
bin/dev/vagrant_provision.sh Executable file
View file

@ -0,0 +1,102 @@
#!/bin/bash
#Script to setup the vagrant instance for running friendica
#
#DO NOT RUN on your physical machine as this won't be of any use
#and f.e. deletes your /var/www/ folder!
echo "Friendica configuration settings"
sudo apt-get update
# Install virtualbox guest additions
sudo apt-get install virtualbox-guest-x11
#Selfsigned cert
echo ">>> Installing *.xip.io self-signed SSL"
SSL_DIR="/etc/ssl/xip.io"
DOMAIN="*.xip.io"
EXTRADOMAIN="friendica.local"
PASSPHRASE="vaprobash"
SUBJ="
C=US
ST=Connecticut
O=Vaprobash
localityName=New Haven
commonName=$DOMAIN
subjectAltName=DNS:$EXTRADOMAIN
organizationalUnitName=
emailAddress=
"
sudo mkdir -p "$SSL_DIR"
sudo openssl genrsa -out "$SSL_DIR/xip.io.key" 4096
sudo openssl req -new -subj "$(echo -n "$SUBJ" | tr "\n" "/")" -key "$SSL_DIR/xip.io.key" -out "$SSL_DIR/xip.io.csr" -passin pass:$PASSPHRASE
sudo openssl x509 -req -days 365 -in "$SSL_DIR/xip.io.csr" -signkey "$SSL_DIR/xip.io.key" -out "$SSL_DIR/xip.io.crt"
#Install apache2
echo ">>> Installing Apache2 webserver"
sudo apt-get install -y apache2
sudo a2enmod rewrite actions ssl
sudo cp /vagrant/bin/dev/vagrant_vhost.sh /usr/local/bin/vhost
sudo chmod guo+x /usr/local/bin/vhost
sudo vhost -s 192.168.22.10.xip.io -d /var/www -p /etc/ssl/xip.io -c xip.io -a friendica.local
sudo a2dissite 000-default
sudo service apache2 restart
#Install php
echo ">>> Installing PHP7"
sudo apt-get install -y php libapache2-mod-php php-cli php-mysql php-curl php-gd php-mbstring php-xml imagemagick php-imagick php-zip
sudo systemctl restart apache2
#Install mysql
echo ">>> Installing Mysql"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password root"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password root"
sudo apt-get install -qq mysql-server
# enable remote access
# setting the mysql bind-address to allow connections from everywhere
sed -i "s/bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
# adding grant privileges to mysql root user from everywhere
# thx to http://stackoverflow.com/questions/7528967/how-to-grant-mysql-privileges-in-a-bash-script for this
MYSQL=`which mysql`
Q1="GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;"
Q2="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}"
$MYSQL -uroot -proot -e "$SQL"
# add a separate database user for friendica
$MYSQL -uroot -proot -e "CREATE USER 'friendica'@'localhost' identified by 'friendica';"
$MYSQL -uroot -proot -e "GRANT ALL PRIVILEGES ON friendica.* TO 'friendica'@'localhost';"
$MYSQL -uroot -proot -e "FLUSH PRIVILEGES"
systemctl restart mysql
#configure rudimentary mail server (local delivery only)
#add Friendica accounts for local user accounts, use email address like vagrant@friendica.local, read the email with 'mail'.
debconf-set-selections <<< "postfix postfix/mailname string friendica.local"
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Local Only'"
sudo apt-get install -y postfix mailutils libmailutils-dev
sudo echo -e "friendica1: vagrant\nfriendica2: vagrant\nfriendica3: vagrant\nfriendica4: vagrant\nfriendica5: vagrant" >> /etc/aliases && sudo newaliases
#make the vagrant directory the docroot
sudo rm -rf /var/www/
sudo ln -fs /vagrant /var/www
# install deps with composer
sudo apt install unzip
cd /var/www
php bin/composer.phar install
# initial config file for friendica in vagrant
cp /vagrant/util/htconfig.vagrant.php /vagrant/.htconfig.php
# create the friendica database
echo "create database friendica DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | $MYSQL -u root -proot
# import test database
$MYSQL -uroot -proot friendica < /vagrant/friendica_test_data.sql
# create cronjob - activate if you have enough memory in you dev VM
echo "*/10 * * * * cd /vagrant; /usr/bin/php bin/worker.php" >> friendicacron
sudo crontab friendicacron
sudo rm friendicacron
# friendica needs write access to /tmp
sudo chmod 777 /tmp

177
bin/dev/vagrant_vhost.sh Executable file
View file

@ -0,0 +1,177 @@
#!/usr/bin/env bash
# Run this as sudo!
# I move this file to /usr/local/bin/vhost and run command 'vhost' from anywhere, using sudo.
#
# Show Usage, Output to STDERR
#
function show_usage {
cat <<- _EOF_
Create a new vHost in Ubuntu Server
Assumes /etc/apache2/sites-available and /etc/apache2/sites-enabled setup used
-d DocumentRoot - i.e. /var/www/yoursite
-h Help - Show this menu.
-s ServerName - i.e. example.com or sub.example.com
-a ServerAlias - i.e. *.example.com or another domain altogether
-p File path to the SSL certificate. Directories only, no file name.
If using an SSL Certificate, also creates a port :443 vhost as well.
This *ASSUMES* a .crt and a .key file exists
at file path /provided-file-path/your-server-or-cert-name.[crt|key].
Otherwise you can except Apache errors when you reload Apache.
Ensure Apache's mod_ssl is enabled via "sudo a2enmod ssl".
-c Certificate filename. "xip.io" becomes "xip.io.key" and "xip.io.crt".
Example Usage. Serve files from /var/www/xip.io at http(s)://192.168.33.10.xip.io
using ssl files from /etc/ssl/xip.io/xip.io.[key|crt]
sudo vhost -d /var/www/xip.io -s 192.168.33.10.xip.io -p /etc/ssl/xip.io -c xip.io
_EOF_
exit 1
}
#
# Output vHost skeleton, fill with userinput
# To be outputted into new file
#
function create_vhost {
cat <<- _EOF_
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName $ServerName
$ServerAlias
DocumentRoot $DocumentRoot
<Directory $DocumentRoot>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog \${APACHE_LOG_DIR}/$ServerName-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined
</VirtualHost>
_EOF_
}
function create_ssl_vhost {
cat <<- _EOF_
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName $ServerName
$ServerAlias
DocumentRoot $DocumentRoot
<Directory $DocumentRoot>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog \${APACHE_LOG_DIR}/$ServerName-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined
SSLEngine on
SSLCertificateFile $CertPath/$CertName.crt
SSLCertificateKeyFile $CertPath/$CertName.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
BrowserMatch "MSIE [2-6]" \\
nokeepalive ssl-unclean-shutdown \\
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
_EOF_
}
#Sanity Check - are there two arguments with 2 values?
if [ "$#" -lt 4 ]; then
show_usage
fi
CertPath=""
#Parse flags
while getopts "d:s:a:p:c:h" OPTION; do
case $OPTION in
h)
show_usage
;;
d)
DocumentRoot=$OPTARG
;;
s)
ServerName=$OPTARG
;;
a)
Alias=$OPTARG
;;
p)
CertPath=$OPTARG
;;
c)
CertName=$OPTARG
;;
*)
show_usage
;;
esac
done
# If alias is set:
if [ "$Alias" != "" ]; then
ServerAlias="ServerAlias "$Alias
else
ServerAlias=""
fi
# If CertName doesn't get set, set it to ServerName
if [ "$CertName" == "" ]; then
CertName=$ServerName
fi
if [ ! -d $DocumentRoot ]; then
mkdir -p $DocumentRoot
#chown USER:USER $DocumentRoot #POSSIBLE IMPLEMENTATION, new flag -u ?
fi
if [ -f "$DocumentRoot/$ServerName.conf" ]; then
echo 'vHost already exists. Aborting'
show_usage
else
create_vhost > /etc/apache2/sites-available/${ServerName}.conf
# Add :443 handling
if [ "$CertPath" != "" ]; then
create_ssl_vhost >> /etc/apache2/sites-available/${ServerName}.conf
fi
# Enable Site
cd /etc/apache2/sites-available/ && a2ensite ${ServerName}.conf
service apache2 reload
fi