From 20f0a7bb27ff0159168cfd0411bbbb5db2d68363 Mon Sep 17 00:00:00 2001 From: mzcwlong Date: Wed, 26 Nov 2014 11:03:10 +0800 Subject: [PATCH] Initial commit Signed-off-by: mzcwlong --- Makefile | 5 ++ engine-reports-config-passwd | 135 ++++++++++++++++++++++++++++++ engine-reports-config-passwd.spec | 42 ++++++++++ 3 files changed, 182 insertions(+) create mode 100644 Makefile create mode 100755 engine-reports-config-passwd create mode 100644 engine-reports-config-passwd.spec diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8547957 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +project_name = engine-reports-config-passwd +version = $(shell grep "Version" $(project_name).spec | awk '{print $$2}') + +sources: + git archive --format=tar --prefix=$(project_name)-$(version)/ HEAD | gzip -9v > $(project_name)-$(version).tar.gz diff --git a/engine-reports-config-passwd b/engine-reports-config-passwd new file mode 100755 index 0000000..5cd1b7f --- /dev/null +++ b/engine-reports-config-passwd @@ -0,0 +1,135 @@ +#!/bin/bash +# oVirt Engine Reports Portal User Password Configuration Script +# By MaZhe + +usage() { + cat << __EOF__ +Usage: $0 [--user=USERNAME [--password=PASSWORD]] + --user=USERNAME + The username. + --password=PASSWORD + The password. + -h, --help + Show this help message. + +__EOF__ + exit 1 +} + +interactive=true +while [ -n "$1" ]; do + x="$1" + v="${x#*=}" + shift + case "${x}" in + --user=*) + USERNAME="${v}" + ;; + --password=*) + PASSWORD="${v}" + if [ -z $USERNAME ]; then + usage + fi + ;; + --help) + usage + ;; + --non-interactive) + if [ ! -z $USERNAME ] && [ ! -z $PASSWORD ]; then + interactive=false + fi + ;; + -h) + usage + ;; + *) + usage + ;; + esac +done + +Set_ReportsUserPassword(){ + echo + echo -n "It will take a while. Please wait. " + local USERNAME=$1 + local PASSWORD=$2 + TMPDIR=/tmp/reports-users + LOGFILE=/var/log/engine-reports-config-password.log + [ -e $TMPDIR ] && rm -rf $TMPDIR + mkdir -p $TMPDIR + cd /usr/share/jasperreports-server/buildomatic/ + export ADDITIONAL_CONFIG_DIR=/var/lib/ovirt-engine-reports/build-conf/ + ./js-export.sh --output-dir $TMPDIR --users &> $LOGFILE + if [ $? -ne 0 ]; then + echo + echo "Password update failed. " + echo "Log File: $LOGFILE. " + rm -rf $TMPDIR + exit 1 + else + if [ -f $TMPDIR/users/$USERNAME.xml ]; then + sed -i "s/.*/$PASSWORD<\/password>/g" $TMPDIR/users/$USERNAME.xml + ./js-import.sh --input-dir $TMPDIR --update &>> $LOGFILE + if [ $? -eq 0 ]; then + echo + echo "Password update successfully." + if $interactive ; then + echo "Please run \"service ovirt-engine-reportsd restart\"." + else + service ovirt-engine-reportsd restart &>> $LOGFILE + fi + rm -rf $TMPDIR + exit 0 + else + echo + echo "Password update failed." + echo "Log File: $LOGFILE. " + rm -rf $TMPDIR + exit 1 + fi + else + echo + echo "User \"$USERNAME\" is not exsit." + rm -rf $TMPDIR + exit 2 + fi + fi +} + +Get_Username(){ + DEFUSER="admin" + read -p "Please enter Username: [$DEFUSER]" USERNAME + if [ -z $USERNAME ]; then + USERNAME=$DEFUSER + fi +} + +Get_Password(){ + read -sp "Please enter Password: " PASSWORD + if [ -z $PASSWORD ]; then + echo + echo -n "Password can not be empty. " + read -n1 + Get_Password + else + echo + read -sp "Please retype password: " REPASSWORD + if [ -z $PASSWORD ] || [ "x$PASSWORD" != "x$REPASSWORD" ]; then + echo + echo -n "Sorry, passwords do not match. " + read -n1 + Get_Password + fi + fi +} + +if [ ! -z $USERNAME ] && [ -z $PASSWORD ]; then + Get_Password + Set_ReportsUserPassword $USERNAME $PASSWORD +elif [ ! -z $USERNAME ] && [ ! -z $PASSWORD ]; then + Set_ReportsUserPassword $USERNAME $PASSWORD +else + Get_Username + Get_Password + Set_ReportsUserPassword $USERNAME $PASSWORD +fi diff --git a/engine-reports-config-passwd.spec b/engine-reports-config-passwd.spec new file mode 100644 index 0000000..243bb71 --- /dev/null +++ b/engine-reports-config-passwd.spec @@ -0,0 +1,42 @@ +Name: engine-reports-config-passwd +Version: 0.1 +Release: 1%{?dist} +Summary: oVirt Engine Reports Portal User Password Configuration Tool + +Group: Application +License: GPL +URL: http://ovirt-china.org +Source0: engine-reports-config-passwd-%{version}.tar.gz +BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) + +BuildRequires: /bin/bash +Requires: ovirt-engine-reports + +%description +oVirt Engine Reports Portal User Password Configuration Tool. + +%prep +%setup -q + + +%build + + +%install +rm -rf %{buildroot} +rm -rf .git +mkdir -p %{buildroot}/usr/bin +cp engine-reports-config-passwd %{buildroot}/usr/bin + +%clean +rm -rf %{buildroot} + + +%files +%defattr(-,root,root,-) +%attr(0755,root,root)/usr/bin/engine-reports-config-passwd + + +%changelog +* Fri Nov 26 2014 MaZhe 0.1-1 +- Initial package tagging.