Initial checkin.

Signed-off-by: Thomas Hochstein <thh@thh.name>
This commit is contained in:
Thomas Hochstein 2022-01-29 10:22:11 +01:00
commit 30132626b8
68 changed files with 5497 additions and 0 deletions

123
sbin/create-functions.sh Normal file
View file

@ -0,0 +1,123 @@
#!/bin/sh
#
# $Id: create-functions.sh 290 2011-06-20 00:45:51Z alba $
#
set_mysql_vars()
{
moderated_group="$1"
# news.newusers.questions => nnq
moderated_group_abbr=$( echo "${moderated_group}" |
sed 's#\([a-zA-Z]\)[a-zA-Z]*\([^a-zA-Z]\|$\)#\1#g' )
if [ -z "${moderated_group_abbr}" ]; then
echo "${moderated_group} is not a valid newsgroup"
exit 1
fi
# news.newusers.questions => news/newusers/questions
www_dir=$( echo "${moderated_group}" | tr . / )
# news.newusers.questions => news-newusers-questions
mysql_db=$( echo "${moderated_group}" | tr . - )
mysql_password=$( "${HUHU_DIR}/bin/new-passwd.pl" )
mysql_table="${moderated_group_abbr}"
mysql_username="${mysql_db}"
length=$( echo "${mysql_username}" | wc -c )
if [ "${length}" -gt 16 ]; then
# http://dev.mysql.com/doc/refman/4.1/en/user-names.html
# MySQL user names can be up to 16 characters long.
mysql_username="${moderated_group_abbr}"
fi
export today=$( date +%Y-%m-%d )
export year=$( date +%Y )
}
create_mysql()
{
local cmd="DROP USER '${mysql_username}'@'localhost'"
if echo "${cmd}" | mysql
then echo "${cmd} succeeded."
else echo "${cmd} failed."
fi
mysqladmin create "${mysql_db}"
(
echo "CREATE USER '${mysql_username}'@'localhost' IDENTIFIED BY '${mysql_password}';"
echo 'GRANT ALL ON `'${mysql_db}'`.* TO '"'${mysql_username}'@'localhost';"
) | mysql
sed "s/@sample@/${mysql_table}/g" \
< "${HUHU_DIR}/samples/mysql/create.sql" |
mysql "${mysql_db}"
echo "mysql_db=${mysql_db}"
echo "mysql_table=${mysql_table}"
echo "mysql_username=${mysql_username}"
echo "mysql_password=${mysql_password}"
}
clean_new_home()
{
cd "${1}" || exit 1
# remove .svn or _svn directories copied from skeleton
find . -type d -name '[._]svn' -exec rm -rf {} \+
# remove backup files
find . -type f -name '*~' -exec rm {} \+
# property svn:executable is used to set the executable bit, so keep
# u-permissions intact
find . -type f -exec chmod o-rwx,g-rwx {} \+
}
install_file()
{
permissions="$1"
src="$2"
dst="${user_home}/${src}"
# template file was copied from skeleton by useradd
# set safe permissions before we write sensitive contents into it
chmod "${permissions}" "${dst}"
awk '{
gsub(/@HUHU_DIR@/, ENVIRON["HUHU_DIR"]);
gsub(/@HUHU_WWW_BASE_DIR@/, ENVIRON["HUHU_WWW_BASE_DIR"]);
gsub(/@HUHU_WWW_BASE_URL@/, ENVIRON["HUHU_WWW_BASE_URL"]);
gsub(/@MODERATED_GROUP_ABBR@/, ENVIRON["moderated_group_abbr"]);
gsub(/@MODERATED_GROUP@/, ENVIRON["moderated_group"]);
gsub(/@MYSQL_DB@/, ENVIRON["mysql_db"]);
gsub(/@MYSQL_PASSWORD@/, ENVIRON["mysql_password"]);
gsub(/@MYSQL_TABLE@/, ENVIRON["mysql_table"]);
gsub(/@MYSQL_USERNAME@/, ENVIRON["mysql_username"]);
gsub(/@SUBMISSION_EMAIL@/, ENVIRON["user_name"] "@" ENVIRON["HUHU_EMAIL_DOMAIN"]);
gsub(/@TODAY@/, ENVIRON["today"]);
gsub(/@YEAR@/, ENVIRON["year"]);
gsub(/@USER_HOME@/, ENVIRON["user_home"]);
gsub(/@USER_ID@/, ENVIRON["user_id"]);
gsub(/@USER_NAME@/, ENVIRON["user_name"]);
gsub(/@WWW_DIR@/, ENVIRON["www_dir"]);
print $0;
}' "${skel_dir}/${src}" > "${dst}"
}
create_www_home()
{
[ -n "${HUHU_WWW_BASE_DIR:-}" ] || return
[ -n "${www_dir:-}" ] || return
local dir="${HUHU_WWW_BASE_DIR}/${www_dir}/stats"
[ -d "${dir}" ] || mkdir -p "${dir}"
dir="${HUHU_WWW_BASE_DIR}/${www_dir}"
(
cd "${dir}"
ln -s "${HUHU_DIR}/cgi-bin/modtable.pl"
ln -s "${HUHU_DIR}/cgi-bin/public.pl"
)
}

12
sbin/create-mysql.sh Normal file
View file

@ -0,0 +1,12 @@
#!/bin/sh
#
# $Id: create-mysql.sh 179 2009-11-07 15:19:03Z root $
#
export "LANG=C"
export "LC_ALL=C"
set -o nounset
set -o errexit
. "${HUHU_DIR}/sbin/create-functions.sh"
set_mysql_vars "$1"
create_mysql

View file

@ -0,0 +1,74 @@
#!/bin/sh -x
#
# $Id: create-procmail-user.sh 290 2011-06-20 00:45:51Z alba $
#
export "LANG=C"
export "LC_ALL=C"
set -o nounset
set -o errexit
if [ -z "${1:-}" ]; then
echo "USAGE: create-procmail-user.sh <moderated_group>"
exit 0
fi
. "${HUHU_DIR}/sbin/create-functions.sh"
set_mysql_vars "$1"
create_mysql
# mysql_username may be an abbreviation, so use mysql_db
user_name="${mysql_db}"
skel_dir="${HUHU_DIR}/etc/skel"
if [ ! -d ${skel_dir} ]; then
echo "Skeleton directory \$HUHU_DIR/etc/skel does not exist."
exit 1
fi
user_home="${HUHU_HOME_BASE_DIR:-/home}/"$( echo "${user_name}" | sed 's#[-.]#/#g' )
user_home_parent="${user_home%/*}"
[ -d "${user_home_parent}" ] || mkdir -p "${user_home_parent}"
useradd --home "${user_home}" --create-home --skel "${skel_dir}" "${user_name}"
user_home=$( awk -F: "/^${user_name}:/ { print \$6 }" /etc/passwd )
if [ ! -d "${user_home}" ]; then
echo "Home directory of user ${user_name} does not exist."
exit 1
fi
user_id=$( awk -F: "/^${user_name}:/ { print \$3 }" /etc/passwd )
clean_new_home "${user_home}"
create_www_home
export moderated_group moderated_group_abbr
export mysql_db mysql_password mysql_table mysql_username
export user_home user_id user_name www_dir
if [ -n "${HUHU_EMAIL_DOMAIN:-}" ]; then
if [ -n "${HUHU_EMAIL_LIST:-}" -a -w "${HUHU_EMAIL_LIST:-}" ]; then
echo "${user_name}@${HUHU_EMAIL_DOMAIN}" >> "${HUHU_EMAIL_LIST}"
fi
if [ -n "${HUHU_POSTFIX_ALIAS:-}" -a -w "${HUHU_POSTFIX_ALIAS:-}" ]; then
echo "${user_name}@${HUHU_EMAIL_DOMAIN} ${user_name}" >> "${HUHU_POSTFIX_ALIAS}"
fi
fi
install_file 600 .bashrc
install_file 600 .cshrc
install_file 600 etc/private.conf
install_file 600 etc/samples/apache-digest.conf
install_file 600 etc/samples/crontab
install_file 600 etc/samples/summary.txt
install_file 600 .forward
install_file 600 .my.cnf
install_file 600 .procmailrc
install_file 644 etc/htdigest
install_file 644 etc/public.conf
install_file 644 etc/samples/huhu-directory.html
install_file 755 bin/poster.sh
install_file 755 bin/read-mail.sh
install_file 755 bin/statistics.sh
install_file 755 etc/htdigest.sh
crontab -u "${user_name}" "${user_home}/etc/samples/crontab"