1
0
forked from ScoDoc/ScoDoc

WIP - shellchek config scripts

This commit is contained in:
viennet 2020-12-19 19:22:22 +01:00
parent 5f425da6c0
commit f89fa0bf68
16 changed files with 169 additions and 170 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash
# Version majeure de Debian (..., 9, 10) # Version majeure de Debian (..., 9, 10)
debian_version=$(cat /etc/debian_version) debian_version=$(cat /etc/debian_version)
debian_version=${debian_version%%.*} debian_version=${debian_version%%.*}
@ -24,28 +24,28 @@ export POSTGRES_SUPERUSER=postgres
export POSTGRES_USER=www-data export POSTGRES_USER=www-data
# psql command: if various versions installed, force the one we want: # psql command: if various versions installed, force the one we want:
if [ ${debian_version} = "10" ] if [ "${debian_version}" = "10" ]
then then
PSQL=/usr/lib/postgresql/11/bin/psql PSQL=/usr/lib/postgresql/11/bin/psql
elif [ ${debian_version} = "9" ] elif [ "${debian_version}" = "9" ]
then then
PSQL=/usr/lib/postgresql/9.6/bin/psql PSQL=/usr/lib/postgresql/9.6/bin/psql
elif [ ${debian_version} = "8" ] elif [ "${debian_version}" = "8" ]
then then
PSQL=/usr/lib/postgresql/9.4/bin/psql PSQL=/usr/lib/postgresql/9.4/bin/psql
elif [ ${debian_version} = "7" ] elif [ "${debian_version}" = "7" ]
then then
PSQL=/usr/lib/postgresql/9.1/bin/psql PSQL=/usr/lib/postgresql/9.1/bin/psql
elif [ ${debian_version} = "5" ] elif [ "${debian_version}" = "5" ]
then then
PSQL=/usr/lib/postgresql/8.3/bin/psql PSQL=/usr/lib/postgresql/8.3/bin/psql
elif [ ${debian_version} = "6" ] elif [ "${debian_version}" = "6" ]
then then
PSQL=/usr/lib/postgresql/8.4/bin/psql PSQL=/usr/lib/postgresql/8.4/bin/psql
else else
PSQL=/usr/lib/postgresql/8.1/bin/psql PSQL=/usr/lib/postgresql/8.1/bin/psql
fi fi
export PSQL
# tcp port for SQL server (under Debian 4, 5432 or 5433 for 8.1 if 7.4 also installed !) # tcp port for SQL server (under Debian 4, 5432 or 5433 for 8.1 if 7.4 also installed !)
# Important note: if changed, you should probably also change it in # Important note: if changed, you should probably also change it in
@ -53,7 +53,7 @@ fi
export POSTGRES_PORT=5432 export POSTGRES_PORT=5432
# Utilise par le script de reset du mot de passe: # Utilise par le script de reset du mot de passe:
if [ ${debian_version} -ge "7" ] if [ "${debian_version}" -ge "7" ]
then then
export ZOPE_VERSION=2.13 export ZOPE_VERSION=2.13
else else

View File

@ -5,10 +5,10 @@
source config.sh source config.sh
source utils.sh source utils.sh
check_uid_root $0 check_uid_root "$0"
echo 'Installation du demarrage automatique de ScoDoc (systemd)' echo 'Installation du demarrage automatique de ScoDoc (systemd)'
cp $SCODOC_DIR/config/etc/scodoc.service /etc/systemd/system cp "$SCODOC_DIR"/config/etc/scodoc.service /etc/systemd/system
systemctl enable scodoc.service systemctl enable scodoc.service
echo "A partir de maintenant, utiliser" echo "A partir de maintenant, utiliser"

View File

@ -11,6 +11,6 @@ source utils.sh
echo 'Creating postgresql database' echo 'Creating postgresql database'
# --- # ---
echo 'Creating postgresql database ' $db_name echo 'Creating postgresql database ' "$db_name"
createdb -E UTF-8 -p $POSTGRES_PORT -O $POSTGRES_USER $db_name createdb -E UTF-8 -p "$POSTGRES_PORT" -O "$POSTGRES_USER" "$db_name"

View File

@ -13,11 +13,11 @@
source config.sh source config.sh
source utils.sh source utils.sh
check_uid_root $0 check_uid_root "$0"
echo -n "Nom du departement (un mot sans ponctuation, exemple \"Info\"): " echo -n "Nom du departement (un mot sans ponctuation, exemple \"Info\"): "
read DEPT read -r DEPT
if [[ ! "$DEPT" =~ ^[A-Za-z0-9]+$ ]] if [[ ! "$DEPT" =~ ^[A-Za-z0-9]+$ ]]
then then
@ -31,9 +31,9 @@ export db_name=SCO$(to_upper "$DEPT")
cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg
if [ -e $cfg_pathname ] if [ -e "$cfg_pathname" ]
then then
echo 'Erreur: Il existe deja une configuration pour "'$DEPT'"' echo 'Erreur: Il existe deja une configuration pour "'"$DEPT"'"'
exit 1 exit 1
fi fi
@ -48,11 +48,11 @@ su -c ./create_database.sh $POSTGRES_SUPERUSER
su -c ./initialize_database.sh $POSTGRES_USER su -c ./initialize_database.sh $POSTGRES_USER
# ----------------------- Enregistre fichier config # ----------------------- Enregistre fichier config
echo "dbname="$db_name > $cfg_pathname echo "dbname=$db_name" > "$cfg_pathname"
# ----------------------- Force mise à jour # ----------------------- Force mise à jour
echo -n "Voulez vous mettre a jour ScoDoc (tres recommande) ? (y/n) [y] " echo -n "Voulez vous mettre a jour ScoDoc (tres recommande) ? (y/n) [y] "
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
(cd "$SCODOC_DIR/config"; ./upgrade.sh) (cd "$SCODOC_DIR/config"; ./upgrade.sh)

View File

@ -4,7 +4,7 @@
# ScoDoc: creation de la base de donnees d'utilisateurs # ScoDoc: creation de la base de donnees d'utilisateurs
# #
# Ce script prend en charge la creation de la base de donnees # Ce script prend en charge la creation de la base de donnees
# et doit être lancé par l'utilisateur unix root dans le repertoire .../config # et doit <EFBFBD>tre lanc<6E> par l'utilisateur unix root dans le repertoire .../config
# ^^^^^^^^^^^^^^^^^^^^^ # ^^^^^^^^^^^^^^^^^^^^^
# E. Viennet, Juin 2008 # E. Viennet, Juin 2008
# #
@ -12,7 +12,7 @@
source config.sh source config.sh
source utils.sh source utils.sh
check_uid_root $0 check_uid_root "$0"
# --- Ensure postgres user www-data exists # --- Ensure postgres user www-data exists
init_postgres_user init_postgres_user
@ -21,8 +21,8 @@ db_name=SCOUSERS
echo 'Creating postgresql database ' $db_name echo 'Creating postgresql database ' $db_name
su -c "createdb -E UTF-8 -O $POSTGRES_USER -p $POSTGRES_PORT $db_name" $POSTGRES_SUPERUSER su -c "createdb -E UTF-8 -O $POSTGRES_USER -p $POSTGRES_PORT $db_name" "$POSTGRES_SUPERUSER"
echo 'Initializing tables in database ' $db_name echo 'Initializing tables in database ' "$db_name"
echo su -c "$PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name < $SCODOC_DIR/misc/create_user_table.sql" $POSTGRES_USER echo su -c "$PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name < $SCODOC_DIR/misc/create_user_table.sql" "$POSTGRES_USER"
su -c "$PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name < $SCODOC_DIR/misc/create_user_table.sql" $POSTGRES_USER su -c "$PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name < $SCODOC_DIR/misc/create_user_table.sql" "$POSTGRES_USER"

View File

@ -17,7 +17,7 @@
source config.sh source config.sh
source utils.sh source utils.sh
check_uid_root $0 check_uid_root "$0"
echo echo
echo "Ce script supprime la base de donnees ScoDoc d'un departement" echo "Ce script supprime la base de donnees ScoDoc d'un departement"
@ -26,7 +26,7 @@ echo "Attention: le departement doit au prealable avoir ete supprime via l'inter
echo "faites le AVANT d'executer ce script !!!" echo "faites le AVANT d'executer ce script !!!"
echo echo
echo -n "Nom du departement a supprimer (un mot sans ponctuation, exemple \"Info\"): " echo -n "Nom du departement a supprimer (un mot sans ponctuation, exemple \"Info\"): "
read DEPT read -r DEPT
if [[ ! "$DEPT" =~ ^[A-Za-z0-9]+$ ]] if [[ ! "$DEPT" =~ ^[A-Za-z0-9]+$ ]]
then then
@ -38,26 +38,26 @@ export DEPT
cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg
if [ -e $cfg_pathname ] if [ -e "$cfg_pathname" ]
then then
# arret de ScoDoc # arret de ScoDoc
scodocctl stop scodocctl stop
# suppression de la base postgres # suppression de la base postgres
db_name=$(cat $cfg_pathname | sed '/^dbname=*/!d; s///;q') db_name=$(sed '/^dbname=*/!d; s///;q' < "$cfg_pathname")
echo "suppression de la base postgres $db_name" echo "suppression de la base postgres $db_name"
su -c "dropdb $db_name" $POSTGRES_SUPERUSER || terminate "ne peux supprimer base de donnees $db_name" su -c "dropdb $db_name" "$POSTGRES_SUPERUSER" || terminate "ne peux supprimer base de donnees $db_name"
# suppression du fichier de config # suppression du fichier de config
/bin/rm -f $cfg_pathname || terminate "ne peux supprimer $cfg_pathname" /bin/rm -f "$cfg_pathname" || terminate "ne peux supprimer $cfg_pathname"
# relance ScoDoc # relance ScoDoc
echo -n "Demarrer le serveur ScoDoc ? (y/n) [n]" echo -n "Demarrer le serveur ScoDoc ? (y/n) [n]"
read ans read -r ans
if [ "$(norm_ans "$ans")" = 'Y' ] if [ "$(norm_ans "$ans")" = 'Y' ]
then then
scodocctl start scodocctl start
fi fi
exit 0 exit 0
else else
echo 'Erreur: pas de configuration trouvee pour "'$DEPT'"' echo 'Erreur: pas de configuration trouvee pour "'"$DEPT"'"'
exit 1 exit 1
fi fi

View File

@ -6,7 +6,7 @@
# Avec option: # Avec option:
# -a : sauve aussi les bases de données # -a : sauve aussi les bases de données
# #
DEST_ADDRESS=emmanuel.viennet@univ-paris13.fr DEST_ADDRESS=emmanuel.viennet@gmail.com
INSTANCE_DIR=/opt/scodoc INSTANCE_DIR=/opt/scodoc
@ -36,7 +36,7 @@ while getopts ":d:aunh" opt; do
SEND_BY_MAIL=0 SEND_BY_MAIL=0
;; ;;
d) d)
DEPTS_TO_SAVE=$( join_by ' ' $DEPTS_TO_SAVE $OPTARG ) DEPTS_TO_SAVE=$( join_by ' ' "$DEPTS_TO_SAVE" "$OPTARG" )
;; ;;
h) h)
echo "Diagnostic installation ScoDoc" echo "Diagnostic installation ScoDoc"
@ -71,7 +71,7 @@ then
apt-get install sharutils apt-get install sharutils
fi fi
mkdir $TMP mkdir "$TMP"
# Files to copy: # Files to copy:
FILES="/etc/hosts /etc/debian_version /etc/apt /etc/apache2" FILES="/etc/hosts /etc/debian_version /etc/apt /etc/apache2"
@ -91,33 +91,33 @@ echo "left in ${TMP}"
# ------------------------------------- # -------------------------------------
copy_log() { copy_log() {
if [ -e $1 ] if [ -e "$1" ]
then then
cp $1 $TMP/scodoc_logs/ cp "$1" "$TMP"/scodoc_logs/
fi fi
} }
mkdir $TMP/scodoc_logs/ mkdir "$TMP"/scodoc_logs/
copy_log /opt/scodoc/instance/log/event.log copy_log /opt/scodoc/log/event.log
copy_log /opt/scodoc/instance/log/event.log.1 copy_log /opt/scodoc/log/event.log.1
copy_log /opt/scodoc/instance/log/notes.log copy_log /opt/scodoc/log/notes.log
copy_log /opt/scodoc/instance/log/notes.log.1 copy_log /opt/scodoc/log/notes.log.1
# ------------------------------------- # -------------------------------------
# Linux System Configuration # Linux System Configuration
# ------------------------------------- # -------------------------------------
iptables -L > $TMP/iptables.out iptables -L > "$TMP"/iptables.out
ip a > $TMP/ifconfig.out ip a > "$TMP"/ifconfig.out
ps auxww > $TMP/ps.out ps auxww > "$TMP"/ps.out
df -h > $TMP/df.out df -h > "$TMP"/df.out
dpkg -l > $TMP/dpkg.lst dpkg -l > "$TMP"/dpkg.lst
(cd /opt/scodoc/instance/Products/ScoDoc; svn status > $TMP/svn.status) (cd /opt/scodoc/Products/ScoDoc; svn status > "$TMP"/svn.status)
(cd /opt/scodoc/instance/Products/ScoDoc; svn diff > $TMP/svn.diff) (cd /opt/scodoc/Products/ScoDoc; svn diff > "$TMP"/svn.diff)
(cd /opt/scodoc/instance/Products/ScoDoc; svnversion > $TMP/svn.version) (cd /opt/scodoc/Products/ScoDoc; svnversion > "$TMP"/svn.version)
ls -laR /opt/scodoc/instance/Products/ScoDoc > $TMP/ls-laR ls -laR /opt/scodoc/Products/ScoDoc > "$TMP"/ls-laR
# ------------------------------------- # -------------------------------------
@ -126,7 +126,7 @@ ls -laR /opt/scodoc/instance/Products/ScoDoc > $TMP/ls-laR
(su postgres -c "psql -l") > "${TMP}/psql-l.out" (su postgres -c "psql -l") > "${TMP}/psql-l.out"
for dept in "${INSTANCE_DIR}"/var/scodoc/config/depts/*.cfg for dept in "${INSTANCE_DIR}"/var/scodoc/config/depts/*.cfg
do do
cnx=$(cat $dept) cnx=$(cat "$dept")
(su postgres -c "echo '\dt' | psql -d $cnx") > "${TMP}/psql-$(basename ${dept%%.*}).out" (su postgres -c "echo '\dt' | psql -d $cnx") > "${TMP}/psql-$(basename ${dept%%.*}).out"
done done
@ -137,14 +137,14 @@ done
# copy files: # copy files:
for f in $FILES for f in $FILES
do do
cp -R $f $TMP cp -R "$f" "$TMP"
done done
# ------------------------------------- # -------------------------------------
# Optionally save dept(s) database(s) # Optionally save dept(s) database(s)
# ------------------------------------- # -------------------------------------
DEPTS_TO_SAVE=$(echo ${DEPTS_TO_SAVE} | tr ' ' '\n' | sort | uniq) DEPTS_TO_SAVE=$(echo "${DEPTS_TO_SAVE}" | tr ' ' '\n' | sort | uniq)
# Dump database of a dept (eg "RT") # Dump database of a dept (eg "RT")
function dump_dept_db { function dump_dept_db {
@ -176,10 +176,10 @@ fi
# Archive all stuff to /tmp # Archive all stuff to /tmp
# ------------------------------------- # -------------------------------------
tar cfz $TMP.tgz $TMP tar cfz "$TMP".tgz "$TMP"
echo echo
echo "Fichier de diagnostic: $TMP.tgz" echo "Fichier de diagnostic: "$TMP".tgz"
echo echo
# If no mail, stop here # If no mail, stop here
@ -197,9 +197,9 @@ fi
#requires: basename,date,md5sum,sed,sendmail,uuencode #requires: basename,date,md5sum,sed,sendmail,uuencode
function fappend { function fappend {
echo "$2">>$1; echo "$2">>"$1";
} }
YYYYMMDD=`date +%Y%m%d` YYYYMMDD=$(date +%Y%m%d)
# CHANGE THESE # CHANGE THESE
TOEMAIL=$DEST_ADDRESS TOEMAIL=$DEST_ADDRESS
@ -212,45 +212,45 @@ MIMETYPE="application/gnutar" #if not sure, use http://www.webmaster-toolkit.com
# DON'T CHANGE ANYTHING BELOW # DON'T CHANGE ANYTHING BELOW
TMP="/tmp/tmpfil_123"$RANDOM; TMP="/tmp/tmpfil_123"$RANDOM;
BOUNDARY=`date +%s|md5sum` BOUNDARY=$(date +%s|md5sum)
BOUNDARY=${BOUNDARY:0:32} BOUNDARY=${BOUNDARY:0:32}
FILENAME=`basename $ATTACHMENT` FILENAME=$(basename "$ATTACHMENT")
rm -rf $TMP; rm -rf "$TMP"
cat $ATTACHMENT|uuencode --base64 $FILENAME>$TMP; uuencode --base64 "$FILENAME" < "$ATTACHMENT" >"$TMP"
sed -i -e '1,1d' -e '$d' $TMP;#removes first & last lines from $TMP sed -i -e '1,1d' -e '$d' "$TMP"; #removes first & last lines from "$TMP"
DATA=`cat $TMP` DATA=$(cat "$TMP")
rm -rf $TMP; rm -rf "$TMP";
fappend $TMP "From: $FREMAIL"; fappend "$TMP" "From: $FREMAIL";
fappend $TMP "To: $TOEMAIL"; fappend "$TMP" "To: $TOEMAIL";
fappend $TMP "Reply-To: $FREMAIL"; fappend "$TMP" "Reply-To: $FREMAIL";
fappend $TMP "Subject: $SUBJECT"; fappend "$TMP" "Subject: $SUBJECT";
fappend $TMP "Content-Type: multipart/mixed; boundary=\""$BOUNDARY"\""; fappend "$TMP" "Content-Type: multipart/mixed; boundary=\""$BOUNDARY"\"";
fappend $TMP ""; fappend "$TMP" "";
fappend $TMP "This is a MIME formatted message. If you see this text it means that your"; fappend "$TMP" "This is a MIME formatted message. If you see this text it means that your";
fappend $TMP "email software does not support MIME formatted messages."; fappend "$TMP" "email software does not support MIME formatted messages.";
fappend $TMP ""; fappend "$TMP" "";
fappend $TMP "--$BOUNDARY"; fappend "$TMP" "--$BOUNDARY";
fappend $TMP "Content-Type: text/plain; charset=ISO-8859-1; format=flowed"; fappend "$TMP" "Content-Type: text/plain; charset=ISO-8859-1; format=flowed";
fappend $TMP "Content-Transfer-Encoding: 7bit"; fappend "$TMP" "Content-Transfer-Encoding: 7bit";
fappend $TMP "Content-Disposition: inline"; fappend "$TMP" "Content-Disposition: inline";
fappend $TMP ""; fappend "$TMP" "";
fappend $TMP "$MSGBODY"; fappend "$TMP" "$MSGBODY";
fappend $TMP ""; fappend "$TMP" "";
fappend $TMP ""; fappend "$TMP" "";
fappend $TMP "--$BOUNDARY"; fappend "$TMP" "--$BOUNDARY";
fappend $TMP "Content-Type: $MIMETYPE; name=\"$FILENAME\""; fappend "$TMP" "Content-Type: $MIMETYPE; name=\"$FILENAME\"";
fappend $TMP "Content-Transfer-Encoding: base64"; fappend "$TMP" "Content-Transfer-Encoding: base64";
fappend $TMP "Content-Disposition: attachment; filename=\"$FILENAME\";"; fappend "$TMP" "Content-Disposition: attachment; filename=\"$FILENAME\";";
fappend $TMP ""; fappend "$TMP" "";
fappend $TMP "$DATA"; fappend "$TMP" "$DATA";
fappend $TMP ""; fappend "$TMP" "";
fappend $TMP ""; fappend "$TMP" "";
fappend $TMP "--$BOUNDARY--"; fappend "$TMP" "--$BOUNDARY--";
fappend $TMP ""; fappend "$TMP" "";
fappend $TMP ""; fappend "$TMP" "";
#cat $TMP>out.txt #cat "$TMP">out.txt
cat $TMP|sendmail -t -f none@example.com; cat "$TMP"|sendmail -t -f none@example.com;
rm $TMP; rm "$TMP";

View File

@ -15,15 +15,15 @@ then
fi fi
echo "Changing to directory " $SCODOC_DIR/config echo "Changing to directory " "$SCODOC_DIR"/config
cd $SCODOC_DIR/config cd "$SCODOC_DIR"/config || { echo "directory does not exist"; exit 1; }
echo "Stopping ScoDoc..." echo "Stopping ScoDoc..."
scodocctl stop scodocctl stop
# DROITS # DROITS
echo -n "Verification des droits: proprietaire www-data ? (y/n) [y] " echo -n "Verification des droits: proprietaire www-data ? (y/n) [y] "
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
echo 'changing owner to www-data' echo 'changing owner to www-data'
@ -31,7 +31,7 @@ then
fi fi
echo -n 'Suppression des backups des sources (*~) ? (y/n) [y] ' echo -n 'Suppression des backups des sources (*~) ? (y/n) [y] '
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
/bin/rm -f ../*~ ../*/*~ /bin/rm -f ../*~ ../*/*~
@ -40,7 +40,7 @@ fi
# SVN # SVN
echo -n "svn update ? (y/n) [y] " echo -n "svn update ? (y/n) [y] "
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
echo 'Updating from SVN...' echo 'Updating from SVN...'
@ -50,7 +50,7 @@ fi
# DEPARTEMENTS (maintenant inutile car dans /var) # DEPARTEMENTS (maintenant inutile car dans /var)
echo -n "Supprimer les (anciennes) configs de departements ? (y/n) [y] " echo -n "Supprimer les (anciennes) configs de departements ? (y/n) [y] "
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
echo "moving " depts/*.cfg "to /tmp" echo "moving " depts/*.cfg "to /tmp"
@ -59,7 +59,7 @@ fi
# .../var/ # .../var/
echo -n "Supprimer et recréer .../var (archives, photos, configs, ...) ? (y/n) [y] " echo -n "Supprimer et recréer .../var (archives, photos, configs, ...) ? (y/n) [y] "
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
echo "moving ../../../var/scodoc to /tmp" echo "moving ../../../var/scodoc to /tmp"
@ -73,7 +73,7 @@ fi
# LOGS ZOPE # LOGS ZOPE
echo -n "Effacer les logs de Zope et ScoDoc ? (y/n) [y] " echo -n "Effacer les logs de Zope et ScoDoc ? (y/n) [y] "
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
(cd ../../../log/; ./purge) (cd ../../../log/; ./purge)
@ -81,7 +81,7 @@ fi
# IMAGE Data.fs # IMAGE Data.fs
echo -n "Recopier le Data.fs original ? (y/n) [y] " echo -n "Recopier le Data.fs original ? (y/n) [y] "
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
echo "moving Data.fs to /tmp" echo "moving Data.fs to /tmp"

View File

@ -8,15 +8,16 @@
source config.sh source config.sh
source utils.sh source utils.sh
if [ $(id -nu) != $POSTGRES_USER ] if [ "$(id -nu)" != "$POSTGRES_USER" ]
then then
echo "$0: script must be runned as user $POSTGRES_USER" echo "$0: script must be runned as user $POSTGRES_USER"
exit 1 exit 1
fi fi
echo 'Initializing tables in database ' $db_name # shellcheck disable=SC2154
$PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name -f $SCODOC_DIR/misc/createtables.sql echo 'Initializing tables in database ' "$db_name"
$PSQL -U "$POSTGRES_USER" -p "$POSTGRES_PORT" "$db_name" -f "$SCODOC_DIR"/misc/createtables.sql
# Set DeptName in preferences: # Set DeptName in preferences:
echo "insert into sco_prefs (name, value) values ('DeptName', '"${DEPT}\'\) | $PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name echo "insert into sco_prefs (name, value) values ('DeptName', '"${DEPT}\'\) | $PSQL -U "$POSTGRES_USER" -p "$POSTGRES_PORT" "$db_name"

View File

@ -13,16 +13,14 @@ source utils.sh
check_uid_root $0 check_uid_root $0
PYTHON=/opt/zope213/bin/python
# ------------ Safety checks # ------------ Safety checks
if [ ${debian_version} != "10" ] if [ "${debian_version}" != "10" ]
then then
echo "Version du systeme Linux Debian incompatible" echo "Version du systeme Linux Debian incompatible"
exit 1 exit 1
fi fi
if [ $(arch) != "x86_64" ] if [ "$(arch)" != "x86_64" ]
then then
echo "Version du systeme Linux Debian incompatible (pas X86 64 bits)" echo "Version du systeme Linux Debian incompatible (pas X86 64 bits)"
exit 1 exit 1
@ -30,8 +28,8 @@ fi
# ------------ Permissions & directories # ------------ Permissions & directories
# source dir should be writable by scodoc to write bytecode files # source dir should be writable by scodoc to write bytecode files
chgrp www-data $SCODOC_DIR $SCODOC_DIR/ZopeProducts/* chgrp www-data "$SCODOC_DIR" "$SCODOC_DIR"/ZopeProducts/*
chmod g+w $SCODOC_DIR $SCODOC_DIR/ZopeProducts/* chmod g+w "$SCODOC_DIR" "$SCODOC_DIR"/ZopeProducts/*
chgrp -R www-data "${SCODOC_VAR_DIR}"/photos chgrp -R www-data "${SCODOC_VAR_DIR}"/photos
chmod -R g+w "${SCODOC_VAR_DIR}"/photos chmod -R g+w "${SCODOC_VAR_DIR}"/photos
@ -54,8 +52,8 @@ fi
for locname in en_US.UTF-8 en_US.ISO-8859-15 en_US.ISO-8859-1 for locname in en_US.UTF-8 en_US.ISO-8859-15 en_US.ISO-8859-1
do do
outname=$(echo ${locname//-/} | tr '[A-Z]' '[a-z]') outname=$(echo ${locname//-/} | tr 'A-Z' 'a-z')
if [ $(locale -a | egrep -i ^${outname}$ | wc -l) -lt 1 ] if [ "$(locale -a | grep -E -i ^${outname}$ | wc -l)" -lt 1 ]
then then
echo adding $locname echo adding $locname
echo "$locname ${locname##*.}" >> /etc/locale.gen echo "$locname ${locname##*.}" >> /etc/locale.gen
@ -87,7 +85,7 @@ apt-get -y install postgresql
apt-get -y install graphviz apt-get -y install graphviz
# ------------ INSTALL DES EXTENSIONS PYTHON (2.7) # ------------ INSTALL DES EXTENSIONS PYTHON (2.7)
# XXX to fix: pip in our env
apt-get -y install python-docutils apt-get -y install python-docutils
apt-get -y install python-jaxml apt-get -y install python-jaxml
apt-get -y install python-psycopg2 apt-get -y install python-psycopg2
@ -97,20 +95,21 @@ apt-get -y install python-cracklib # was python-crack
apt-get -y install python-icalendar apt-get -y install python-icalendar
apt-get -y install python-requests apt-get -y install python-requests
# XXX to fix: mx not needed anymore !
apt-get -y install python-egenix-mxtools python-egenix-mxdatetime apt-get -y install python-egenix-mxtools python-egenix-mxdatetime
# ------------ # ------------
SVNVERSION=$(cd ..; svnversion) SVNVERSION=$(cd ..; svnversion)
SVERSION=$(curl --silent http://scodoc.iutv.univ-paris13.fr/scodoc-installmgr/version?mode=install\&svn=$SVNVERSION) SVERSION=$(curl --silent http://scodoc.iutv.univ-paris13.fr/scodoc-installmgr/version?mode=install\&svn="$SVNVERSION")
echo $SVERSION > "${SCODOC_VERSION_DIR}/scodoc.sn" echo "$SVERSION" > "${SCODOC_VERSION_DIR}/scodoc.sn"
# ------------ POSTFIX # ------------ POSTFIX
echo echo
echo "ScoDoc a besoin de pouvoir envoyer des messages par mail." echo "ScoDoc a besoin de pouvoir envoyer des messages par mail."
echo -n "Voulez vous configurer la messagerie (tres recommande) ? (y/n) [y] " echo -n "Voulez vous configurer la messagerie (tres recommande) ? (y/n) [y] "
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
apt-get -y install postfix apt-get -y install postfix
@ -120,7 +119,7 @@ fi
echo echo
echo "Le firewall aide a proteger votre serveur d'intrusions indesirables." echo "Le firewall aide a proteger votre serveur d'intrusions indesirables."
echo -n "Voulez vous configurer un firewall minimal (ufw) ? (y/n) [n] " echo -n "Voulez vous configurer un firewall minimal (ufw) ? (y/n) [n] "
read ans read -r ans
if [ "$(norm_ans "$ans")" = 'Y' ] if [ "$(norm_ans "$ans")" = 'Y' ]
then then
echo 'Installation du firewall IP ufw (voir documentation Debian)' echo 'Installation du firewall IP ufw (voir documentation Debian)'
@ -145,16 +144,16 @@ a2enmod rewrite
echo echo
echo "La configuration du serveur web va modifier votre installation Apache pour supporter ScoDoc." echo "La configuration du serveur web va modifier votre installation Apache pour supporter ScoDoc."
echo -n "Voulez vous configurer le serveur web Apache maintenant (tres conseille) ? (y/n) [y] " echo -n "Voulez vous configurer le serveur web Apache maintenant (tres conseille) ? (y/n) [y] "
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
echo "Configuration d'Apache" echo "Configuration d'Apache"
server_name="" server_name=""
while [ -z $server_name ] while [ -z "$server_name" ]
do do
echo "Le nom de votre serveur doit normalement etre connu dans le DNS." echo "Le nom de votre serveur doit normalement etre connu dans le DNS."
echo -n "Nom complet de votre serveur (exemple: notes.univ.fr): " echo -n "Nom complet de votre serveur (exemple: notes.univ.fr): "
read server_name read -r server_name
done done
# --- CERTIFICATS AUTO-SIGNES # --- CERTIFICATS AUTO-SIGNES
echo echo
@ -162,7 +161,7 @@ then
echo "auto-signes, qui ne seront pas reconnus comme de confiance" echo "auto-signes, qui ne seront pas reconnus comme de confiance"
echo "par les navigateurs, mais offrent une certaine securite." echo "par les navigateurs, mais offrent une certaine securite."
echo -n 'Voulez vous generer des certificats ssl auto-signes ? (y/n) [y] ' echo -n 'Voulez vous generer des certificats ssl auto-signes ? (y/n) [y] '
read ans read -r ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
# attention: utilise dans scodoc-site-ssl.orig # attention: utilise dans scodoc-site-ssl.orig
@ -178,7 +177,7 @@ then
fi fi
# --- # ---
echo 'generation de /etc/apache2/sites-available/scodoc-site-ssl' echo 'generation de /etc/apache2/sites-available/scodoc-site-ssl'
cat $SCODOC_DIR/config/etc/scodoc-site-ssl-apache2.4.orig | sed -e "s:YOUR\.FULL\.HOST\.NAME:$server_name:g" > /etc/apache2/sites-available/scodoc-site-ssl.conf cat "$SCODOC_DIR"/config/etc/scodoc-site-ssl-apache2.4.orig | sed -e "s:YOUR\.FULL\.HOST\.NAME:$server_name:g" > /etc/apache2/sites-available/scodoc-site-ssl.conf
echo 'activation du site...' echo 'activation du site...'
a2ensite scodoc-site-ssl a2ensite scodoc-site-ssl
@ -188,7 +187,7 @@ then
then then
mv $fn $fn.bak mv $fn $fn.bak
fi fi
cp $SCODOC_DIR/config/etc/scodoc-site.orig $fn cp "$SCODOC_DIR"/config/etc/scodoc-site.orig $fn
if [ -z "$(grep Listen /etc/apache2/ports.conf | grep 443)" ] if [ -z "$(grep Listen /etc/apache2/ports.conf | grep 443)" ]
then then
@ -222,7 +221,7 @@ if [ "$(norm_ans "$ans")" != 'N' ]
then then
# ScoDoc 7.19+ uses systemd # ScoDoc 7.19+ uses systemd
echo 'Installation du demarrage automatique de ScoDoc (systemd)' echo 'Installation du demarrage automatique de ScoDoc (systemd)'
cp $SCODOC_DIR/config/etc/scodoc.service /etc/systemd/system cp "$SCODOC_DIR"/config/etc/scodoc.service /etc/systemd/system
systemctl enable scodoc.service systemctl enable scodoc.service
fi fi
@ -233,8 +232,8 @@ echo -n "Mises a jour hebdomadaires (tres recommande) ? (y/n) [y] "
read ans read ans
if [ "$(norm_ans "$ans")" != 'N' ] if [ "$(norm_ans "$ans")" != 'N' ]
then then
cp $SCODOC_DIR/config/etc/scodoc-updater.service /etc/systemd/system cp "$SCODOC_DIR"/config/etc/scodoc-updater.service /etc/systemd/system
cp $SCODOC_DIR/config/etc/scodoc-updater.timer /etc/systemd/system cp "$SCODOC_DIR"/config/etc/scodoc-updater.timer /etc/systemd/system
systemctl enable scodoc-updater.timer systemctl enable scodoc-updater.timer
systemctl start scodoc-updater.timer systemctl start scodoc-updater.timer
fi fi

View File

@ -8,7 +8,7 @@ PG_DUMPFILE=$1
# Check locale of installation. If invalid, reinitialize all system # Check locale of installation. If invalid, reinitialize all system
is_latin1=$(psql -l | grep postgres | grep iso88591 | wc -l) is_latin1=$(psql -l | grep postgres | grep iso88591 | wc -l)
if [ $is_latin1 -gt 1 ] if [ "$is_latin1" -gt 1 ]
then then
echo "Recreating postgres cluster using UTF-8" echo "Recreating postgres cluster using UTF-8"
@ -20,8 +20,8 @@ fi
# Drop all current ScoDoc databases, if any: # Drop all current ScoDoc databases, if any:
for f in $(psql -l --no-align --field-separator . | grep SCO | cut -f 1 -d.); do for f in $(psql -l --no-align --field-separator . | grep SCO | cut -f 1 -d.); do
echo dropping $f echo dropping "$f"
dropdb $f dropdb "$f"
done done
echo "Restoring postgres data..." echo "Restoring postgres data..."
psql -f "$PG_DUMPFILE" postgres psql -f "$PG_DUMPFILE" postgres

View File

@ -15,7 +15,7 @@ SCODOC_DIR="${INSTANCE_DIR}/Products/ScoDoc"
SCODOC_VAR_DIR="${INSTANCE_DIR}/var/scodoc" SCODOC_VAR_DIR="${INSTANCE_DIR}/var/scodoc"
source utils.sh source utils.sh
check_uid_root $0 check_uid_root "$0"
# Safety check # Safety check
echo "Ce script va remplacer les donnees de votre installation ScoDoc par celles" echo "Ce script va remplacer les donnees de votre installation ScoDoc par celles"
@ -28,7 +28,7 @@ echo
echo "TOUTES LES BASES POSTGRESQL SERONT EFFACEES !!!" echo "TOUTES LES BASES POSTGRESQL SERONT EFFACEES !!!"
echo echo
echo -n "Voulez vous poursuivre cette operation ? (y/n) [n]" echo -n "Voulez vous poursuivre cette operation ? (y/n) [n]"
read ans read -r ans
if [ ! "$(norm_ans "$ans")" = 'Y' ] if [ ! "$(norm_ans "$ans")" = 'Y' ]
then then
echo "Annulation" echo "Annulation"
@ -57,7 +57,7 @@ then
echo "Opening tgz archive..." echo "Opening tgz archive..."
tmp=$(mktemp -d) tmp=$(mktemp -d)
chmod a+rx "$tmp" chmod a+rx "$tmp"
cd "$tmp" cd "$tmp" || { echo "Fatal error: directory not available"; exit 1; }
tar xfz "$SRC" tar xfz "$SRC"
SRC=$(ls -1d "$tmp"/*) SRC=$(ls -1d "$tmp"/*)
IS_TMP=1 IS_TMP=1
@ -132,11 +132,11 @@ chmod -R 775 "$SCODOC_DIR"
# Remove tmp directory # Remove tmp directory
if [ $IS_TMP = "1" ] if [ $IS_TMP = "1" ]
then then
rm -rf $tmp rm -rf "$tmp"
fi fi
# Mise a jour BD ScoDoc # Mise a jour BD ScoDoc
cd $SCODOC_DIR/config cd "$SCODOC_DIR"/config || { echo "Fatal error: invalid directory"; exit 2; }
./upgrade.sh ./upgrade.sh
# #

View File

@ -10,6 +10,8 @@
# #
source utils.sh source utils.sh
check_uid_root "$0"
# Destination directory # Destination directory
if [ ! $# -eq 1 ] if [ ! $# -eq 1 ]
then then
@ -34,9 +36,6 @@ fi
INSTANCE_DIR=/opt/scodoc INSTANCE_DIR=/opt/scodoc
SCODOC_DIR="$INSTANCE_DIR/Products/ScoDoc" SCODOC_DIR="$INSTANCE_DIR/Products/ScoDoc"
source utils.sh
check_uid_root $0
echo "Stopping ScoDoc..." echo "Stopping ScoDoc..."
scodocctl stop scodocctl stop
@ -46,7 +45,7 @@ chown postgres "$DEST"
su -c "pg_dumpall > \"$DEST\"/scodoc.dump.txt" postgres su -c "pg_dumpall > \"$DEST\"/scodoc.dump.txt" postgres
if [ ! $? -eq 0 ] if [ ! $? -eq 0 ]
then then
echo "Error dumping postgresql database\nPlease check that SQL server is running\nAborting." printf "Error dumping postgresql database\nPlease check that SQL server is running\nAborting.\n"
exit 1 exit 1
fi fi
chown root "$DEST" chown root "$DEST"
@ -57,7 +56,7 @@ cp -rp "$INSTANCE_DIR/var" "$DEST"
# Depts db config (now in .../var) # Depts db config (now in .../var)
shopt -s nullglob shopt -s nullglob
if [ ! -z "$(echo ${SCODOC_DIR}/config/depts/*.cfg)" ] if [ -n "$(echo ${SCODOC_DIR}/config/depts/*.cfg)" ]
then then
echo "Copying legacy depts configs..." echo "Copying legacy depts configs..."
cp -rp "$SCODOC_DIR/config/depts" "$DEST" cp -rp "$SCODOC_DIR/config/depts" "$DEST"

View File

@ -4,7 +4,7 @@
# ScoDoc: reglage du mot de passe admin Zope # ScoDoc: reglage du mot de passe admin Zope
# (in Zope terminology, an emergency user) # (in Zope terminology, an emergency user)
# #
# Doit être lancé par l'utilisateur unix root dans le repertoire .../config # Doit <EFBFBD>tre lanc<6E> par l'utilisateur unix root dans le repertoire .../config
# ^^^^^^^^^^^^^^^^^^^^^ # ^^^^^^^^^^^^^^^^^^^^^
# E. Viennet, Juin 2008, Jul 2019 # E. Viennet, Juin 2008, Jul 2019
# #
@ -22,14 +22,14 @@ fi
echo "Creation d'un utilisateur d'urgence pour ScoDoc" echo "Creation d'un utilisateur d'urgence pour ScoDoc"
echo "(utile en cas de perte de votre mot de passe admin)" echo "(utile en cas de perte de votre mot de passe admin)"
if [ ${debian_version} != "10" ] if [ "${debian_version}" != "10" ]
then then
mdir=/opt/zope213/lib/python2.7/site-packages/Zope2-2.13.21-py2.7.egg/Zope2/utilities mdir=/opt/zope213/lib/python2.7/site-packages/Zope2-2.13.21-py2.7.egg/Zope2/utilities
else else
mdir=/opt/zope213/lib/python2.7/site-packages/Zope2/utilities mdir=/opt/zope213/lib/python2.7/site-packages/Zope2/utilities
fi fi
python $mdir/zpasswd.py $SCODOC_DIR/../../access python $mdir/zpasswd.py "$SCODOC_DIR"/../../access
echo echo
echo "redemarrer scodoc pour prendre en compte le mot de passe" echo "redemarrer scodoc pour prendre en compte le mot de passe"

View File

@ -1,20 +1,20 @@
#!/bin/bash #!/bin/bash
# Upgrade ScoDoc installation using SVN # Upgrade ScoDoc installation using GIT
# SVN must be properly configured and have read access to ScoDoc repository # GIT must be properly configured and have read access to ScoDoc repository
# This script STOP and RESTART ScoDoc and should be runned as root # This script STOP and RESTART ScoDoc and should be runned as root
# #
# Upgrade also the Linux system using apt. # Upgrade also the Linux system using apt.
# #
# Script for ScoDoc 7 (Debian 7, 8, 9, 10) # Script for ScoDoc 8 (10)
# #
# E. Viennet, sep 2013, mar 2017, jun 2019, aug 2020 # E. Viennet, sep 2013, mar 2017, jun 2019, aug 2020, dec 2020
cd /opt/scodoc/Products/ScoDoc/config cd /opt/scodoc/Products/ScoDoc/config || { echo "Invalid directory"; exit 1; }
source config.sh source config.sh
source utils.sh source utils.sh
check_uid_root $0 check_uid_root "$0"
if [ -z "$SCODOC_UPGRADE_RUNNING" ] if [ -z "$SCODOC_UPGRADE_RUNNING" ]
then then
@ -31,8 +31,8 @@ fi
scodocctl stop scodocctl stop
echo echo
echo "Using SVN to update $SCODOC_DIR..." echo "Using git to update $SCODOC_DIR..."
(cd "$SCODOC_DIR"; svn update) (cd "$SCODOC_DIR"; git checkout ScoDoc8; git pull origin master)
SVNVERSION=$(cd ..; svnversion) SVNVERSION=$(cd ..; svnversion)
@ -72,13 +72,13 @@ fi
# Check that no Zope "access" file has been forgotten in the way: # Check that no Zope "access" file has been forgotten in the way:
if [ -e $SCODOC_DIR/../../access ] if [ -e "$SCODOC_DIR"/../../access ]
then then
mv $SCODOC_DIR/../../access $SCODOC_DIR/../../access.bak mv "$SCODOC_DIR"/../../access "$SCODOC_DIR"/../../access.bak
fi fi
# Fix some permissions which may have been altered in the way: # Fix some permissions which may have been altered in the way:
chsh -s /bin/sh $POSTGRES_USER # www-data, nologin in Debian 9 chsh -s /bin/sh "$POSTGRES_USER" # www-data, nologin in Debian 9
chown root.www-data "$SCODOC_DIR" # important to create .pyc chown root.www-data "$SCODOC_DIR" # important to create .pyc
chmod 775 "${SCODOC_DIR}" chmod 775 "${SCODOC_DIR}"
chmod a+r "$SCODOC_DIR"/*.py chmod a+r "$SCODOC_DIR"/*.py
@ -141,7 +141,7 @@ echo "Executing post-upgrade script..."
"$SCODOC_DIR"/config/postupgrade.py "$SCODOC_DIR"/config/postupgrade.py
echo "Executing post-upgrade database script..." echo "Executing post-upgrade database script..."
su -c "$SCODOC_DIR/config/postupgrade-db.py" $POSTGRES_USER su -c "$SCODOC_DIR/config/postupgrade-db.py" "$POSTGRES_USER"
# #
echo echo

View File

@ -1,17 +1,17 @@
#!/bin/bash
# Misc utilities for ScoDoc install shell scripts # Misc utilities for ScoDoc install shell scripts
to_lower() { to_lower() {
echo $1 | tr "[:upper:]" "[:lower:]" echo "$1" | tr "[:upper:]" "[:lower:]"
} }
to_upper() { to_upper() {
echo $1 | tr "[:lower:]" "[:upper:]" echo "$1" | tr "[:lower:]" "[:upper:]"
} }
norm_ans() { norm_ans() {
x=$(to_upper $1 | tr O Y) x=$(to_upper "$1" | tr O Y)
echo ${x:0:1} echo "${x:0:1}"
} }
check_uid_root() { check_uid_root() {
@ -44,7 +44,7 @@ scodocctl() {
systemctl $1 scodoc systemctl $1 scodoc
else else
echo "(using legacy SystemV)" echo "(using legacy SystemV)"
/etc/init.d/scodoc $1 /etc/init.d/scodoc "$1"
fi fi
} }
@ -54,7 +54,7 @@ init_postgres_user() { # run as root
then then
# add database user # add database user
echo "Creating postgresql user $POSTGRES_USER" echo "Creating postgresql user $POSTGRES_USER"
su -c "createuser -p $POSTGRES_PORT --no-superuser --no-createdb --no-adduser --no-createrole ${POSTGRES_USER}" $POSTGRES_SUPERUSER su -c "createuser -p $POSTGRES_PORT --no-superuser --no-createdb --no-adduser --no-createrole ${POSTGRES_USER}" "$POSTGRES_SUPERUSER"
fi fi
} }
@ -69,8 +69,8 @@ gen_passwd() {
password="" password=""
while [ "$n" -le "$PASSWORD_LENGTH" ] while [ "$n" -le "$PASSWORD_LENGTH" ]
do do
password="$password${ALLOWABLE_ASCII:$(($RANDOM%${#ALLOWABLE_ASCII})):1}" password="$password${ALLOWABLE_ASCII:$((RANDOM%${#ALLOWABLE_ASCII})):1}"
n=$((n+1)) n=$((n+1))
done done
echo $password echo "$password"
} }