-
Notifications
You must be signed in to change notification settings - Fork 1
Organizing the logic of the install script. #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| # check permissions | ||
| # | ||
| check_permissions (){ | ||
| uid=$(/usr/bin/id -ur) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Lo que hice fue crear el archivo source/allow con un simple touch y cancelar la ejecución de la función |
||
|
|
||
| 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| 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 | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Desconozco que si |
||
| #echo "-> Do you want me to create a Round-Robin-Database (RRD)" | ||
| #echo -n "-> for stats? (rrdtool must be installed) (y or n)? " | ||
|
|
@@ -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" | ||
|
|
@@ -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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Me queda mi duda si no es mejor idea el crear este directorio dentro de la función 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" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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` | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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} | ||
There was a problem hiding this comment.
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}.