#!/bin/bash

if [ "$1" = '' ]; then
        echo "Please type in an username.";
        exit 2;
fi

if [ "$2" = '' ]; then
        echo "Please type in a password.";
        exit 2;
fi

USERNAME=$( printf "%q\n" "$1" )
PASSWORD=$( printf "%q\n" "$2" )

RET=$( echo "user = User.find_by(username: '$USERNAME')
user.password = '$PASSWORD'
user.password_confirmation = '$PASSWORD'
user.save!
quit" | gitlab-rails console production 2>&1 )

echo "$RET" | grep 'Enqueued ActionMailer::DeliveryJob' > /dev/null

exit $?

