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
62 changes: 62 additions & 0 deletions samples/issabel/create_rpm_issabel4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/sh

#
# Create a RPM from last stable version or other if setted
# This script need have installed git, sed, rpmdevtools and curl
#
# Author: Rodrigo Ramírez Norambuena <a@rodrigoramirez.com>
#

# config
BRANCH=stable
SPEC_FILE=issabel4-qpanel.spec
REPO="https://github.com/roramirez/qpanel.git"
URL_STABLE_VERSION="https://rodrigoramirez.com/qpanel/version/$BRANCH"

if ! [ -x "$(command -v git)" ]; then
echo "Please install git"
exit 1
fi

if ! [ -x "$(command -v rpmdev-setuptree)" ]; then
echo "Please install rpm-build and rpmdevtools"
exit 1
fi

if ! [ -x "$(command -v curl)" ]; then
echo "Please install curl"
exit 1
fi

if ! [ -x "$(command -v npm)" ]; then
echo "Please install npm"
exit 1
fi

VERSION_STABLE=$(curl -L $URL_STABLE_VERSION)
CLONE_DIR="/tmp/qpanel-$VERSION_STABLE"
FILE_TAR="qpanel-$VERSION_STABLE.tar.gz"
if [ -d "$CLONE_DIR" ]; then
cd $CLONE_DIR
git pull
else
git clone -b $BRANCH $REPO $CLONE_DIR
fi

cd $CLONE_DIR
pybabel compile -d translations
# Bower
cd $CLONE_DIR
npm install
sudo $CLONE_DIR/node_modules/bower/bin/bower --allow-root install

cd /tmp
tar cvfz $FILE_TAR --exclude=node_modules qpanel-$VERSION_STABLE

rpmdev-setuptree
cd
cp /tmp/$FILE_TAR rpmbuild/SOURCES
cd rpmbuild
cp $CLONE_DIR/samples/issabel/$SPEC_FILE $SPEC_FILE
sed -i s/"Version: *.*.*"/"Version: $VERSION_STABLE"/g $SPEC_FILE
rpmbuild -v -bb $SPEC_FILE
127 changes: 127 additions & 0 deletions samples/issabel/issabel4-qpanel.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
%define modname qpanel
Name: issabel-%{modname}
Version: 0.14.1
Release: 2%{?dist}
Summary: Qpanel is dashboard for Queues in Asterisk
Group: Applications/Communications
License: MIT
URL: https://github.com/roramirez/qpanel
Source0: %{modname}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{modname}-%{version}-root
Prereq: issabel-framework >= 4.0.0

# Git is used for py-asterisk lib from repository
Requires: httpd, python >= 2.7, python-pip, mod_wsgi, git
BuildArch: noarch

%description
Qpanel is a dashboard for app_queue of Asterisk


%prep
%setup -n %{modname}-%{version}


%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/opt/%{modname}
mv * $RPM_BUILD_ROOT/opt/%{modname}
mkdir -p $RPM_BUILD_ROOT/usr/share/issabel/module_installer/%{name}-%{version}-%{release}/
cp $RPM_BUILD_ROOT/opt/%{modname}/samples/issabel/menu.xml $RPM_BUILD_ROOT/usr/share/issabel/module_installer/%{name}-%{version}-%{release}/

%post



CONFIG_FILE=/opt/%{modname}/config.ini
if ! [ -f "$CONFIG_FILE" ]; then

# Manager config
RAN_PASS=$(date +%s | sha256sum | base64 | head -c 32 ; echo)
cp /opt/%{modname}/samples/config.ini-dist /opt/%{modname}/config.ini
sed -i "s/= password/= $RAN_PASS/" /opt/%{modname}/config.ini
sed -i "s/= username/= qpanel/" /opt/%{modname}/config.ini
sed -i "s/;base_url = /base_url = \/qpanel/" /opt/%{modname}/config.ini

search_include=$(grep manager_qpanel.conf /etc/asterisk/manager.conf | grep -v ';')
if [ ${#search_include} -eq 0 ]; then
echo "#include manager_qpanel.conf" >> /etc/asterisk/manager.conf;
fi
else
RAN_PASS=$(grep "\[manager\]" -a5 $CONFIG_FILE | grep password | cut -f 3 --delimiter=" ")
python /opt/%{modname}/update_config.py $CONFIG_FILE /opt/%{modname}/samples/config.ini-dist
fi

# Update or create manager config for qpanel user
CONFIG_FILE_MANAGER=/etc/asterisk/manager_qpanel.conf
if ! [ -f "$CONFIG_FILE_MANAGER" ]; then
cp /opt/%{modname}/samples/configs/manager_asterisk.conf $CONFIG_FILE_MANAGER
else
# update role commands
ROL_READ=$(grep "read.*" /opt/%{modname}/samples/configs/manager_asterisk.conf)
ROL_WRITE=$(grep "write.*" /opt/%{modname}/samples/configs/manager_asterisk.conf)
sed -i "s/read.*/$ROL_READ/" $CONFIG_FILE_MANAGER
sed -i "s/write.*/$ROL_WRITE/" $CONFIG_FILE_MANAGER
fi
sed -i "s/secret.*/secret = $RAN_PASS/" $CONFIG_FILE_MANAGER
asterisk -rx "reload"


# Dependencies
pip install virtualenv
mkdir /opt/%{modname}/env
virtualenv /opt/%{modname}/env
source /opt/%{modname}/env/bin/activate
pip install -r /opt/%{modname}/requirements.txt
deactivate


# httpd apache
if ! [ -f "/etc/httpd/conf.d/qpanel.conf" ]; then
echo '
Alias /qpanel/static /opt/qpanel/qpanel/static
<Directory /opt/qpanel/qpanel/static>
Require all granted
</Directory>

<Directory /opt/qpanel>
<Files start.wsgi>
Require all granted
</Files>
</Directory>

WSGISocketPrefix /var/run/wsgi
WSGIDaemonProcess qpanel_app python-path=/opt/qpanel:/opt/qpanel/env/lib/python2.7/site-packages
WSGIProcessGroup qpanel_app
WSGIScriptAlias /qpanel /opt/qpanel/start.wsgi process-group=qpanel_app
' > /etc/httpd/conf.d/qpanel.conf

fi
service httpd restart


pathModule="/usr/share/issabel/module_installer/%{name}-%{version}-%{release}"
# Run installer script to fix up ACLs and add module to issabel menus.
issabel-menumerge $pathModule/menu.xml


%pre
mkdir -p /usr/share/issabel/module_installer/%{name}-%{version}-%{release}/


%clean
rm -rf $RPM_BUILD_ROOT

%preun
if [ $1 -eq 0 ] ; then # Validation for desinstall this rpm
echo "Delete menus"
issabel-menuremove "%{modname}"
fi

%files
%defattr(-,root,root,-)
/opt/%{modname}/*
/usr/share/issabel/module_installer/*
%doc

%changelog
9 changes: 9 additions & 0 deletions samples/issabel/menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module>
<menulist>
<menuitem menuid="qpanel" desc="QPanel" parent="pbxconfig" module="yes" link="https://{NAME_SERVER}/qpanel" order="7">
<permissions>
<group id="1" name="administrator" desc="total access"></group>
</permissions>
</menuitem>
</menulist>