Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: mzcwlong <[email protected]>
  • Loading branch information
blkart committed Nov 26, 2014
1 parent 0b24d56 commit 20f0a7b
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
135 changes: 135 additions & 0 deletions engine-reports-config-passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/bash
# oVirt Engine Reports Portal User Password Configuration Script
# By MaZhe <[email protected]>

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>$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
42 changes: 42 additions & 0 deletions engine-reports-config-passwd.spec
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> 0.1-1
- Initial package tagging.

0 comments on commit 20f0a7b

Please sign in to comment.