branch develop updated (3cb88d4 -> 9b0876f)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository mum. See http://git.chorem.org/mum.git from 3cb88d4 replace run.sh to mum.sh new 9b0876f rewrite/refactor all script and package (deb, rpm) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 9b0876fcebb07e408284dd1a87f98ebcd4a33044 Author: Benjamin POUSSIN <poussin@codelutin.com> Date: Wed Jul 1 19:56:03 2015 +0200 rewrite/refactor all script and package (deb, rpm) Summary of changes: mum.conf => conf/mum.conf | 2 + conf/mum.sudoers.d | 1 + debian/postinst | 38 +++---------------- debian/postrm | 9 +++++ debian/preinst | 5 +++ debian/rules | 40 +++++++++----------- in-venv.sh | 7 ---- install.sh | 35 ----------------- mum.sh | 11 ------ redhat/mum.spec | 52 ++++++++++++++++++------- mum-daemon.sh => scripts/mum-daemon.sh | 0 scripts/mum-env.sh | 69 ++++++++++++++++++++++++++++++++++ scripts/mum-in-venv.sh | 14 +++++++ scripts/mum-install-venv.sh | 16 ++++++++ scripts/mum.service | 8 ++++ scripts/mum.sh | 12 ++++++ 16 files changed, 198 insertions(+), 121 deletions(-) rename mum.conf => conf/mum.conf (93%) create mode 100644 conf/mum.sudoers.d mode change 100644 => 100755 debian/postinst create mode 100755 debian/postrm create mode 100755 debian/preinst delete mode 100755 in-venv.sh delete mode 100755 install.sh delete mode 100755 mum.sh rename mum-daemon.sh => scripts/mum-daemon.sh (100%) create mode 100755 scripts/mum-env.sh create mode 100755 scripts/mum-in-venv.sh create mode 100755 scripts/mum-install-venv.sh create mode 100644 scripts/mum.service create mode 100755 scripts/mum.sh -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository mum. See http://git.chorem.org/mum.git commit 9b0876fcebb07e408284dd1a87f98ebcd4a33044 Author: Benjamin POUSSIN <poussin@codelutin.com> Date: Wed Jul 1 19:56:03 2015 +0200 rewrite/refactor all script and package (deb, rpm) --- mum.conf => conf/mum.conf | 2 + conf/mum.sudoers.d | 1 + debian/postinst | 38 +++---------------- debian/postrm | 9 +++++ debian/preinst | 5 +++ debian/rules | 40 +++++++++----------- in-venv.sh | 7 ---- install.sh | 35 ----------------- mum.sh | 11 ------ redhat/mum.spec | 52 ++++++++++++++++++------- mum-daemon.sh => scripts/mum-daemon.sh | 0 scripts/mum-env.sh | 69 ++++++++++++++++++++++++++++++++++ scripts/mum-in-venv.sh | 14 +++++++ scripts/mum-install-venv.sh | 16 ++++++++ scripts/mum.service | 8 ++++ scripts/mum.sh | 12 ++++++ 16 files changed, 198 insertions(+), 121 deletions(-) diff --git a/mum.conf b/conf/mum.conf similarity index 93% rename from mum.conf rename to conf/mum.conf index 0c5bb85..ee35c96 100644 --- a/mum.conf +++ b/conf/mum.conf @@ -1,5 +1,7 @@ server_port=1337 server_addr=0.0.0.0 +app_location=/usr/lib/mum +venv_location=/var/lib/mum/venv db_location=/var/lib/mum/data/mum.db log_location=/var/log/mum external_modules_location=/etc/mum/modules/ diff --git a/conf/mum.sudoers.d b/conf/mum.sudoers.d new file mode 100644 index 0000000..bf6107d --- /dev/null +++ b/conf/mum.sudoers.d @@ -0,0 +1 @@ +mum ALL=(ALL) NOPASSWD: /usr/bin/nmap diff --git a/debian/postinst b/debian/postinst old mode 100644 new mode 100755 index c00beaf..c2f5b8e --- a/debian/postinst +++ b/debian/postinst @@ -1,37 +1,11 @@ #!/bin/bash -cd /usr/lib/mum - -venv/bin/python --version >/dev/null 2>&1 || virtualenv venv -./in-venv.sh pip install -r requirements.txt - -# changing bottle templates in order to make it compatible with angularJS -sed -i 's/{{/[[/g' venv/bin/bottle.py -sed -i 's/}}/]]/g' venv/bin/bottle.py -sed -i 's/{{/[[/g' venv/lib/python2.7/site-packages/bottle.py -sed -i 's/}}/]]/g' venv/lib/python2.7/site-packages/bottle.py - -# creating mum user if doesn't exist -NB_MUM_USR=$(grep '^mum:' /etc/passwd | wc -l) -if [ $NB_MUM_USR -eq 0 ]; then - /usr/sbin/adduser mum --system - echo 'mum user created' +if [ -d /lib/systemd/system ]; then + ln -s /usr/lib/mum/scripts/mum.service /lib/systemd/system/mum.service +elif [ -d /etc/init.d ]; then + ln -s /usr/lib/mum/scripts/mum-daemon.sh /etc/init.d/mum fi -# creating mum group if doesn't exist and adding mum user to it -NB_MUM_GRP=$(grep '^mum:' /etc/group | wc -l) -if [ $NB_MUM_GRP -eq 0 ]; then - /usr/sbin/addgroup mum --system - echo 'mum group created' - /usr/sbin/usermod -a -G mum mum - echo 'mum user added to mum group' -fi - -# adding mum group to sudoers if not registered -NB_MUM_SUDOERS=$(grep '^mum\s' /etc/sudoers | wc -l) -if [ $NB_MUM_SUDOERS -eq 0 ]; then - echo 'mum ALL=(ALL) NOPASSWD: /usr/bin/nmap' >> /etc/sudoers - echo "mum added to sudoers" -fi +/usr/lib/mum/scripts/mum-install-venv.sh -exit 0; \ No newline at end of file +exit 0; diff --git a/debian/postrm b/debian/postrm new file mode 100755 index 0000000..94516cc --- /dev/null +++ b/debian/postrm @@ -0,0 +1,9 @@ +#!/bin/bash + +if [ -L /etc/init.d/mum ]; then + rm /etc/init.d/mum +fi + +if [ -L /lib/systemd/system/mum.service ]; then + rm /lib/systemd/system/mum.service +fi diff --git a/debian/preinst b/debian/preinst new file mode 100755 index 0000000..56e8e9f --- /dev/null +++ b/debian/preinst @@ -0,0 +1,5 @@ +#!/bin/bash + +/usr/sbin/useradd --system --user-group mum + +exit 0 diff --git a/debian/rules b/debian/rules index ad8c683..8b156fe 100755 --- a/debian/rules +++ b/debian/rules @@ -13,17 +13,17 @@ app=$(CURDIR)/app bower_components=$(CURDIR)/bower_components static=$(CURDIR)/static views=$(CURDIR)/views -install_script=$(CURDIR)/install.sh -in_venv=$(CURDIR)/in-venv.sh -mum_conf=$(CURDIR)/mum.conf -mum_daemon=$(CURDIR)/mum-daemon.sh -mum_service=$(CURDIR)/mum.service +scripts=$(CURDIR)/scripts +mum_conf=$(CURDIR)/conf/mum.conf +mum_sudoers=$(CURDIR)/conf/mum.sudoers.d +mum_daemon=$(CURDIR)/scripts/mum-daemon.sh +mum_service=$(CURDIR)/scripts/mum.service readme=$(CURDIR)/README requirements=$(CURDIR)/requirements.txt -run=$(CURDIR)/mum.sh +license=$(CURDIR)/LICENSE DEST_APP=$(CURDIR)/debian/mum/usr/lib/mum -DEST_CONF=$(CURDIR)/debian/mum/etc/mum +DEST_CONF=$(CURDIR)/debian/mum/etc DEST_VAR=$(CURDIR)/debian/mum/var/lib/mum DEST_BIN=$(CURDIR)/debian/mum/usr/bin DEST_INIT_D=$(CURDIR)/debian/mum/etc/init.d @@ -43,36 +43,32 @@ clean : rm -f build-stamp dh_clean -install : build clean $(app) $(bower_components) $(static) $(views) $(install_script) $(in_venv) $(mum_conf) $(readme) $(requirements) $(run) +install : build clean $(app) $(bower_components) $(static) $(views) $(scripts) $(mum_conf) $(mum_sudoers) $(readme) $(requirements) $(license) dh_testdir dh_testroot dh_clean -k dh_installdirs mkdir -p $(DEST_APP) - mkdir -p $(DEST_CONF) - mkdir -p $(DEST_VAR) + mkdir -p $(DEST_CONF)/mum + mkdir -p $(DEST_CONF)/sudoers.d + mkdir -p $(DEST_VAR)/keys + mkdir -p $(DEST_VAR)/data mkdir -p $(DEST_BIN) - mkdir -p $(DEST_SYSTEMD) mkdir -p $(DEST_DOC) mkdir -p $(DEST_LOGS) - mkdir $(DEST_VAR)/keys - mkdir $(DEST_VAR)/logs - mkdir $(DEST_VAR)/data cp -R $(app) $(DEST_APP) cp -R $(bower_components) $(DEST_APP) cp -R $(static) $(DEST_APP) cp -R $(views) $(DEST_APP) - cp $(install_script) $(DEST_APP) - cp $(in_venv) $(DEST_APP) - cp $(mum_conf) $(DEST_CONF) - cp $(mum_service) $(DEST_SYSTEMD) + cp -R $(scripts) $(DEST_APP) + cp $(mum_conf) $(DEST_CONF)/mum + cp $(mum_sudoers) $$(DEST_CONF)/sudoers.d cp $(readme) $(DEST_APP) + cp $(license) $(DEST_DOC) cp $(requirements) $(DEST_APP) - cp $(run) $(DEST_APP) - cp $(mum_daemon) $(DEST_DOC) - ln -s /usr/lib/mum/mum.sh -t $(DEST_BIN) + ln -sr $(DEST_APP)/scripts/mum.sh $(DEST_BIN) find $(DEST_APP)/app -type f -iname "*.pyc" -exec rm -f {} \; rm -rf $(DEST_APP)/bower_components/jquery @@ -100,4 +96,4 @@ binary-arch : build install dh_builddeb binary : binary-indep binary-arch -. PHONY : build clean binary-indep binary-arch binary install configure \ No newline at end of file +. PHONY : build clean binary-indep binary-arch binary install configure diff --git a/in-venv.sh b/in-venv.sh deleted file mode 100755 index 9a7793e..0000000 --- a/in-venv.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -cmd="$1" -shift -. venv/bin/activate -export PYTHONPATH=$PWD/lib:$PYTHONPATH -exec "$cmd" "$@" diff --git a/install.sh b/install.sh deleted file mode 100755 index 36050d1..0000000 --- a/install.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -venv/bin/python --version >/dev/null 2>&1 || virtualenv venv -./in-venv.sh pip install -r requirements.txt - -# changing bottle templates in order to make it compatible with angularJS -sed -i 's/{{/[[/g' venv/bin/bottle.py -sed -i 's/}}/]]/g' venv/bin/bottle.py -sed -i 's/{{/[[/g' venv/lib/python2.7/site-packages/bottle.py -sed -i 's/}}/]]/g' venv/lib/python2.7/site-packages/bottle.py - -# creating mum user if doesn't exist -NB_MUM_USR=$(grep '^mum:' /etc/passwd | wc -l) -if [ $NB_MUM_USR -eq 0 ]; then - /usr/sbin/adduser mum --system - echo "mum user created" -fi - -# creating mum group if doesn't exist and adding mum user to it -NB_MUM_GRP=$(grep '^mum:' /etc/group | wc -l) -if [ $NB_MUM_GRP -eq 0 ]; then - /usr/sbin/addgroup mum --system - echo "mum group created" - /usr/sbin/usermod -a -G mum mum - echo "mum user added to mum group" -fi - -# adding mum group to sudoers if not registered -NB_MUM_SUDOERS=$(grep '^mum\s' /etc/sudoers | wc -l) -if [ $NB_MUM_SUDOERS -eq 0 ]; then - echo 'mum ALL=(ALL) NOPASSWD: /usr/bin/nmap' >> /etc/sudoers - echo "mum added to sudoers" -fi - -exit 0; \ No newline at end of file diff --git a/mum.sh b/mum.sh deleted file mode 100755 index 0eb6148..0000000 --- a/mum.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -#DIR=$(basename /usr/lib/mum) -#cd $DIR - -if [ ! -d "venv" ]; then - echo "Preparing the virtual environment for the first launch (this may take several minutes)" - echo "Log files will be saved on /etc/mum" - ./install.sh > /var/log/mum/mum.install.log 2> /var/log/mum/mum.install.err -fi -exec ./in-venv.sh python app/mum.py $* diff --git a/redhat/mum.spec b/redhat/mum.spec index 8e065ae..7f52c78 100644 --- a/redhat/mum.spec +++ b/redhat/mum.spec @@ -4,8 +4,10 @@ %define version 0.1 %define DEST_APP /usr/lib/mum -%define DEST_CONF /etc/mum +%define DEST_SCRIPTS /usr/lib/mum/scripts +%define DEST_CONF /etc %define DEST_VAR /var/lib/mum +%define DEST_LOG /var/log/mum %define DEST_BIN /usr/bin Summary: Machines Under Monitoring @@ -28,10 +30,11 @@ autoconfiguration from this detection. %install rm -rf %{buildroot} -mkdir -p %{buildroot}/%{DEST_APP} -mkdir -p %{buildroot}/%{DEST_CONF} -mkdir -p %{buildroot}/%{DEST_VAR} -mkdir %{buildroot}/%{DEST_VAR}/keys +mkdir -p %{buildroot}/%{DEST_SCRIPTS} +mkdir -p %{buildroot}/%{DEST_CONF}/mum +mkdir -p %{buildroot}/%{DEST_CONF}/soduers.d +mkdir -p %{buildroot}/%{DEST_VAR}/keys +mkdir -p %{buildroot}/%{DEST_LOG} mkdir -p %{buildroot}/%{DEST_BIN} #cd %{_topdir} @@ -39,14 +42,14 @@ cp -R app %{buildroot}/%{DEST_APP} cp -R bower_components %{buildroot}/%{DEST_APP} cp -R static %{buildroot}/%{DEST_APP} cp -R views %{buildroot}/%{DEST_APP} -cp install.sh %{buildroot}/%{DEST_APP} -cp in-venv.sh %{buildroot}/%{DEST_APP} -cp mum.conf %{buildroot}/%{DEST_CONF} +cp -R scripts %{buildroot}/%{DEST_APP} +cp -R conf %{buildroot}/%{DEST_APP} +cp conf/mum.conf %{buildroot}/%{DEST_CONF}/mum +cp conf/mum.sudoers.d %{buildroot}/%{DEST_CONF}/sudoers.d/mum #cp $(mum_daemon) $(DEST_INIT_D) cp README %{buildroot}/%{DEST_APP} cp requirements.txt %{buildroot}/%{DEST_APP} -cp mum.sh %{buildroot}/%{DEST_APP} -ln -s mum.sh %{buildroot}/%{DEST_BIN} +ln -sr %{buildroot}/%{DEST_SCRIPTS}/mum.sh %{buildroot}/%{DEST_BIN} find %{buildroot}/%{DEST_APP}/app -type f -iname "*.pyc" -exec rm -f {} \; rm -rf %{buildroot}/%{DEST_APP}/bower_components/jquery @@ -57,13 +60,34 @@ rm -rf %{buildroot}/%{DEST_APP}/bower_components/jquery %{DEST_APP}/bower_components %{DEST_APP}/static %{DEST_APP}/views -%{DEST_APP}/install.sh -%{DEST_APP}/in-venv.sh -%{DEST_CONF}/mum.conf %{DEST_APP}/README %{DEST_APP}/requirements.txt -%{DEST_APP}/mum.sh +%{DEST_SCRIPTS} %{DEST_BIN}/mum.sh +%attr(0755,mum,mum) %{DEST_VAR} +%attr(0755,mum,mum) %{DEST_LOG} +%config(noreplace) %{DEST_CONF}/mum.conf +%attr(0440,root,root) %config(noreplace) /etc/sudoers.d/mum + +%pre +/usr/sbin/useradd --system --user-group mum + +%post +if [ -d /lib/systemd/system ]; then + ln -s /usr/lib/mum/scripts/mum.service /lib/systemd/system/mum.service +elif [ -d /etc/init.d ]; then + ln -s /usr/lib/mum/scripts/mum-daemon.sh /etc/init.d/mum +fi +/usr/lib/mum/scripts/mum-install-venv.sh + +%postun +if [ -L /etc/init.d/mum ]; then + rm /etc/init.d/mum +fi +if [ -L /lib/systemd/system/mum.service ]; then + rm /lib/systemd/system/mum.service +fi + %changelog * Thu May 21 2015 Alexis Guilbaud <aguilbaud@codelutin.com> - 0.1-1 diff --git a/mum-daemon.sh b/scripts/mum-daemon.sh similarity index 100% rename from mum-daemon.sh rename to scripts/mum-daemon.sh diff --git a/scripts/mum-env.sh b/scripts/mum-env.sh new file mode 100755 index 0000000..4442159 --- /dev/null +++ b/scripts/mum-env.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +if [ -z "$MUM_ENV" ]; then + +SCRIPT_DIR=$(dirname $(realpath $0)) + +USAGE="usage $(basename $0) [config_file|config_dir]" +CONF=$1 +MUM_PY=app/mum.py + +if [ -d "$CONF" ]; then + CONF=$CONF/*.conf +fi + +if [ -n "$CONF" ]; then + MUM_DIR=$(grep app_location $CONF |cut -f2 -d=|tail -1) + VENV_DIR=$(grep venv_location $CONF |cut -f2 -d=|tail -1) + LOG_DIR=$(dirname "$(grep log_location $CONF |cut -f2 -d=|tail -1)") +fi + +if [ ! -f "$MUM_DIR/$MUM_PY" ]; then + if [ -f "$SCRIPT_DIR/../$MUM_PY" ]; then + MUM_DIR=$(realpath "$SCRIPT_DIR/../$MUM_PY") + elif [ -f /usr/lib/mum/$MUM_PY ]; then + MUM_DIR=/usr/lib/mum + else + echo "Can't find mum installation directory, you must call mum with config argument" + echo "$USAGE" + exit 1 + fi +fi + +if [ -z "$VENV_DIR" ]; then + VENV_DIR=$MUM_DIR/venv +fi + +if [ -z "$LOG_DIR" ]; then + if [ -d /var/log/mum ]; then + LOG_DIR=/var/log/mum + else + LOG_DIR=/tmp/mum + fi +fi + +VENV_EXEC=$(which virtualenv) +PYTHON_EXEC=$(which python2) +if [ ! -x "$PYTHON_EXEC" ]; then + PYTHON_EXEC=$(which python) +fi + +if [ ! -x "$PYTHON_EXEC" -o ! -x "$VENV_EXEC" -o -z "$($PYTHON_EXEC -V 2>&1 |grep 'Python 2.')" ]; then + echo "Can't find python2 or virtualenv, please install them first" + exit 1 +fi + +mkdir -p $LOG_DIR +mkdir -p $(dirname $VENV_DIR) + +export CONF +export MUM_DIR +export VENV_DIR +export LOG_DIR +export MUM_PY +export PYTHON_EXEC +export VENV_EXEC + +export MUM_ENV=true + +fi diff --git a/scripts/mum-in-venv.sh b/scripts/mum-in-venv.sh new file mode 100755 index 0000000..882e45c --- /dev/null +++ b/scripts/mum-in-venv.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +SCRIPT_DIR=$(dirname $(realpath $0)) +cd $SCRIPT_DIR + +. mum-env.sh + +cmd="$1" +shift + +. $VENV_DIR/bin/activate +export PYTHONPATH=$PWD/lib:$PYTHONPATH + +exec "$cmd" "$@" diff --git a/scripts/mum-install-venv.sh b/scripts/mum-install-venv.sh new file mode 100755 index 0000000..360e0cf --- /dev/null +++ b/scripts/mum-install-venv.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +SCRIPT_DIR=$(dirname $(realpath $0)) + +. $SCRIPT_DIR/mum-env.sh + +$VENV_DIR/bin/python --version >/dev/null 2>&1 || $VENV_EXEC --python=$PYTHON_EXEC $VENV_DIR +$SCRIPT_DIR/mum-in-venv.sh pip install -r $MUM_DIR/requirements.txt + +# changing bottle templates in order to make it compatible with angularJS +sed -i 's/{{/[[/g' $VENV_DIR/bin/bottle.py +sed -i 's/}}/]]/g' $VENV_DIR/bin/bottle.py +sed -i 's/{{/[[/g' $VENV_DIR/lib/python*/site-packages/bottle.py +sed -i 's/}}/]]/g' $VENV_DIR/lib/python*/site-packages/bottle.py + +exit 0 diff --git a/scripts/mum.service b/scripts/mum.service new file mode 100644 index 0000000..e4cd74d --- /dev/null +++ b/scripts/mum.service @@ -0,0 +1,8 @@ +Description=Machines Under Monitoring + +[Service] +User=mum +ExecStart=/usr/bin/mum /etc/mum + +[Install] +WantedBy=multi-user.target diff --git a/scripts/mum.sh b/scripts/mum.sh new file mode 100755 index 0000000..4b826fe --- /dev/null +++ b/scripts/mum.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +SCRIPT_DIR=$(dirname $(realpath $0)) + +. $SCRIPT_DIR/mum-env.sh + +if [ ! -d "$VENV_DIR" ]; then + echo "Preparing the virtual environment for the first launch (this may take several minutes)" + echo "Log files will be saved on $LOG_DIR" + $SCRIPT_DIR/mum-install-venv.sh > $LOG_DIR/mum.install.log 2> $LOG_DIR/mum.install.err +fi +exec $SCRIPT_DIR/mum-in-venv.sh python $MUM_DIR/$MUM_PY $* -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm