Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 93 additions & 33 deletions install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,39 +1,102 @@
#!/bin/sh

# careful, not really tested
# ... needs more testing

#
# careful, not really tested _
# ... needs more testing (_)
# | .
# . |L /| . _
# _ . |\ _| \--+._/| . (_)
# / ||\| Y J ) / |/| ./
# J |)'( | ` F`.'/ _
# -<| F __ .-< (_)
# | / .-'. `. /-. L___ _____ ____ _____ _____
# J \ < \ | | O\|.-' _ / ___ \ | _ \ / ____| __ \
# _J \ .- \/ O | | \ |F (_) / / / /___ ___ ____ | |_) | (___ | | | |
# '-F -<_. \ .-' `-' L__ / / / / __ \/ _ \/ __ \| _ < \___ \| | | |
#__J _ _. >-' )._. |-' / /__/ / /_/ / __/ / / /| |_) |____) | |__| |
#`-|.' /_. \_| F \_____/ .___/\___/_/ /_/ |____/|_____/|_____/
# /.- . _.< ======/ /======================================
# /' /.' .' `\ /_/ Wicap Install
# /L /' |/ _.-'-\
# /'J ___.---'\|
# |\ .--' V | `. `
# |/`. `-. `._)
# / .-.\
# \ ( `\
# Configuration
basedir=/var/www
target=usr/local/wicap-php
dest=${basedir}/${target}
rrdtool=/usr/local/bin/rrdtool
source=$(dirname `readlink -f "$0"`)/source
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El primer detalle que tuve que para correrlo tenia que estar en el mismo directorio del guión install.sh, para esto declare la variable ${source}.

# check permissions
#
check_permissions (){
uid=$(/usr/bin/id -ur)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aquí tengo una duda, el guión lo va ejecutar el usuario root o un grupo de usuarios privilegiados?, de ser así tal vez se podría comparar /usr/bin/id -g con cero, pero esto dependiendo de quien(es) lo valla(n) a ejecutar.

if [ ${uid} != 0 ]; then
echo "\n-> Error, you do not have root permissions"
exit 1
fi
}
check_permissions

uid=$(/usr/bin/id -ur)
if [ ${uid} != 0 ]; then
echo "-> Error, you do not have root permissions"
exit 1
fi

echo "-> Compiling 'allow' daemon..."
( cd source
make clean all
) || exit 1
# Compile deamon
#
make_daemon (){
echo "-> Compiling 'allow' daemon..."
cd ${source}
make clean all
if [ ${?} != 0 ]; then
echo "\n-> Error while compiling the daemon"
echo " You should check you have all the dependencies."
exit 1
fi
}
make_daemon
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aquí tuve algunos conflictos con dependencias detalles de mi OS la verdad lo corri sobre trisquel y tuve conflictos con la librería event.h de momento son detalles que estoy revisando ademas de otras cosas que ando configurando en mi OS(hace poco formatie).

Lo que hice fue crear el archivo source/allow con un simple touch y cancelar la ejecución de la funciónmake_daemon al comentar esta linea para que el guión me pudiera seguir ejecutando el testing.


echo "-> Creating '$dest' structure"
mkdir -p ${dest}/{var,bin,htdocs} || exit 1
# Create the following structure:
# /var/www/usr/local/wicap-php/
# ├── bin
# ├── htdocs
# └── var
create_structure (){
echo "-> Creating '${dest}' structure"
(mkdir -p ${dest}/var && mkdir -p ${dest}/bin && mkdir -p ${dest}/htdocs)
if [ ${?} != 0 ]; then
echo "\n-> Error while creating the structure"
exit 1
fi
}
create_structure
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aquí había un detalle, verán si ejecuto:

mkdir -p ./{var,bin,htdocs}

Lo que me hace sh es que me crea un directorio llamado {var,bin,htdocs}, a diferencia de lo que hace bash o zh(no estoy del todo seguro de zh pero me parece que también lo hace).


echo "-> Copying files to '$dest'"
cp source/allow ${dest}/bin
cp source/allow.rc ${dest}/bin
cp source/rotate_something.sh ${dest}/bin
cp source/rotate.cron ${dest}/bin
cp source/htdocs/*.php ${dest}/htdocs
cp source/htdocs/*.jpg ${dest}/htdocs
# copy files
#
copy_files (){
echo "-> Copying files to '$dest'"
( cp ${source}/allow ${dest}/bin && \
cp ${source}/allow.rc ${dest}/bin && \
cp ${source}/rotate_something.sh ${dest}/bin && \
cp ${source}/rotate.cron ${dest}/bin && \
cp ${source}/htdocs/*.php ${dest}/htdocs && \
cp ${source}/htdocs/*.jpg ${dest}/htdocs )
if [ ${?} != 0 ]; then
echo "\n-> Error while Copying the files"
exit 1
fi
}
copy_files

echo "-> Setting permissions to '$dest'"
chown -R www ${dest}/var
chmod 700 ${dest}/bin/*
#set permissions
#
set_permissions (){
echo "-> Setting permissions to '$dest'"
(chown -R www ${dest}/var && \
chmod 700 ${dest}/bin/* )
if [ ${?} != 0 ]; then
echo "\n-> Error while Setting permissions to '$dest'"
exit 1
fi
}
set_permissions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aquí el único detalle es que no tenia el usuario www.

De momento se me vino la idea de declarar una variable para el nombre del usuario esto con el fin de facilitar los testings.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sí me referia a bash por que se que tiene el comportamiento que la instrucción:

mkdir {a,b,c}

Crea los directorios a,b,c, por otra parte supongo que shells amiagables como zh, o fish tambien lo hacen.

Desconozco que si ksh reconoce estos comodines, por lo que se es que sh no te realiza este comportamiento y como el control durante la ejecución del script la realiza sh decidí adaptar la sintaxis a sh.

#echo "-> Do you want me to create a Round-Robin-Database (RRD)"
#echo -n "-> for stats? (rrdtool must be installed) (y or n)? "
Expand All @@ -44,7 +107,6 @@ chmod 700 ${dest}/bin/*
# echo "Making RRD..."
# ./mkrrd.sh $rrdtool $dest/var/stats.rrd
#fi

( cd $dest/htdocs
echo "-> Linking..."
echo " $dest/htdocs/wicap.php -> $dest/htdocs/index.php"
Expand All @@ -53,20 +115,18 @@ chmod 700 ${dest}/bin/*
echo " $dest -> /$target"
ln -sf $dest /$target
) || exit 1

echo "-> Installing..."
echo " source/conf/httpd-minimal.conf as ${basedir}/conf/httpd.conf"
echo " ${source}/conf/httpd-minimal.conf as ${basedir}/conf/httpd.conf"
if [ -f ${basedir}/conf/httpd.conf ]; then
osha256=$(/bin/sha256 -q ${basedir}/conf/httpd.conf)
nsha256=$(/bin/sha256 -q source/conf/httpd-minimal.conf)
nsha256=$(/bin/sha256 -q ${source}/conf/httpd-minimal.conf)
if [ "${osha256}" != "${nsha256}" ]; then
echo "-> Error, ${basedir}/conf/httpd.conf differs from"
echo " source/conf/httpd-minimal.conf"
echo " ${source}/conf/httpd-minimal.conf"
echo " Make a backup of ${basedir}/conf/httpd.conf, delete it"
echo " and execute once again this shell script"
exit 1
fi
fi
cat source/conf/httpd-minimal.conf > ${basedir}/conf/httpd.conf

cat ${source}/conf/httpd-minimal.conf > ${basedir}/conf/httpd.conf
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aquí hay un detalle y es que previamente debe de existir el directorio ${basedir}/conf/ lo que hice fue crear el directorio y volver ejecutar el guión el cual se ejecuto correctamente.

Me queda mi duda si no es mejor idea el crear este directorio dentro de la función create_structure la cual quedaría como:

create_structure (){
    echo "-> Creating '${dest}' structure"
    (mkdir -p ${dest}/var && mkdir -p ${dest}/bin && mkdir -p ${dest}/htdocs && mkdir -p ${basedir}/conf )
    if [ ${?} != 0 ]; then
        echo "\n-> Error while creating the structure"
        exit 1
    fi
}

¿Que opinan?, igual y estaría bien realizar el cambio antes de cualquier merge.

echo "-> Done"
46 changes: 28 additions & 18 deletions mkrrd.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,36 @@
# excellent tutorial on rrdtool:
# http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/tut/rrdtutorial.en.html

rrdtool=/usr/local/bin/rrdtool
rrdtool=`which rrdtool`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En este guión el único detalle que tuve fue que en mi OS el rrdtool no se localiza en /usr/local/bin/rrdtool, lo que hacia para probarlo es pasarle como argumento la ruta del binario rrdtool pero mejor lo exporte con el which rrdtool creo que queda mas portable el código.

rrdfile=/var/www/usr/local/wicap-php/var/stats.rrd

if [ $1 ];then
echo "-> Using $1 for rrdtool path"
rrdtool=$1
if [ ${1} ];then
echo "-> Using ${1} for rrdtool path"
rrdtool=${1}
fi
if [ $2 ];then
echo "-> Using $2 for resulting rrd"
rrdfile=$2
if [ ${2} ];then
echo "-> Using ${2} for resulting rrd"
rrdfile=${2}
fi

$rrdtool create $rrdfile \
DS:auths:ABSOLUTE:600:U:U \
DS:evicts:ABSOLUTE:600:U:U \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797
#
#
mkrrd (){
${1} create ${2} \
DS:auths:ABSOLUTE:600:U:U \
DS:evicts:ABSOLUTE:600:U:U \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797
if [ ${?} != 0 ]; then
echo "\n-> Error "
exit 1
fi
}

mkrrd ${rrdtool} ${rrdfile}