Switch to double bracket tests, reduce redundancy

This commit is contained in:
flow.gunso
2020-01-06 18:35:32 +01:00
parent 9bae0fafc9
commit 87c40f3f95

View File

@@ -16,41 +16,25 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
function fail_with_message {
echo "$1"
echo "Exiting container."
exit 1
}
# Check mandatory Seafile configuration have been properly set.
if [ -z $SEAF_SERVER_URL ]; then
echo "The \$SEAF_SERVER_URL is not defined. Stopping container..."
exit 1
fi
if [ -z $SEAF_USERNAME ]; then
echo "The \$SEAF_USERNAME is not defined. Stopping container..."
exit 1
fi
if [ -z $SEAF_PASSWORD ]; then
echo "The \$SEAF_PASSWORD is not defined. Stopping container..."
exit 1
fi
if [ -z $SEAF_LIBRARY_UUID ]; then
echo "The \$SEAF_LIBRARY_UUID is not defined. Stopping container..."
exit 1
fi
if [[ -n "$SEAF_UPLOAD_LIMIT"
&& $SEAF_UPLOAD_LIMIT =~ ^[0-9]+$
&& "$SEAF_UPLOAD_LIMIT" -gt 0 ]]; then
echo "The \$SEAF_UPLOAD_LIMIT is not an integer greater than 0. Stopping container..."
exit 1
fi
if [[ -n "$SEAF_DOWNLOAD_LIMIT"
&& $SEAF_DOWNLOAD_LIMIT =~ ^[0-9]+$
&& "$SEAF_DOWNLOAD_LIMIT" -gt 0 ]]; then
echo "The \$SEAF_DOWNLOAD_LIMIT is not an integer greater than 0. Stopping container..."
exit 1
fi
[[ -z "$SEAF_SERVER_URL" ]] && fail_with_message "The \$SEAF_SERVER_URL is not defined."
[[ -z "$SEAF_USERNAME" ]] && fail_with_message "The \$SEAF_USERNAME is not defined."
[[ -z "$SEAF_PASSWORD" ]] && fail_with_message "The \$SEAF_PASSWORD is not defined."
[[ -z "$SEAF_LIBRARY_UUID" ]] && fail_with_message "The \$SEAF_LIBRARY_UUID is not defined."
[[ -n "$SEAF_UPLOAD_LIMIT" && $SEAF_UPLOAD_LIMIT =~ ^[0-9]+$ && "$SEAF_UPLOAD_LIMIT" -gt 0 ]] && \
fail_with_message "The \$SEAF_UPLOAD_LIMIT is not an integer greater than 0."
[[ -n "$SEAF_DOWNLOAD_LIMIT" && $SEAF_DOWNLOAD_LIMIT =~ ^[0-9]+$ && "$SEAF_DOWNLOAD_LIMIT" -gt 0 ]] && \
fail_with_message "The \$SEAF_DOWNLOAD_LIMIT is not an integer greater than 0."
# Update the user ID, if the $UID changed.
if [ "$UID" != "1000" ]; then
usermod -u $UID $UNAME
# What if the $UID already exists ?
fi
# TODO: What if the $UID already exists ?
[[ "$UID" != "1000" ]] && usermod -u $UID $UNAME
# Change the group, if the $GID changed.
if [ "$GID" != "1000" ]; then
@@ -73,11 +57,10 @@ su - $UNAME << EO
export SEAF_USERNAME=$SEAF_USERNAME
export SEAF_PASSWORD=$SEAF_PASSWORD
export SEAF_LIBRARY_UUID=$SEAF_LIBRARY_UUID
export SEAF_SKIP_SSL_CERT=$SEAF_SKIP_SSL_CERT
test -n "$SEAF_UPLOAD_LIMIT" && export SEAF_UPLOAD_LIMIT=$SEAF_UPLOAD_LIMIT
test -n "$SEAF_DOWNLOAD_LIMIT" && export SEAF_DOWNLOAD_LIMIT=$SEAF_DOWNLOAD_LIMIT
test -n "$SEAF_2FA_SECRET" && export SEAF_2FA_SECRET=$SEAF_2FA_SECRET
test -n "$SEAF_LIBRARY_PASSWORD" && export SEAF_LIBRARY_PASSWORD=$SEAF_LIBRARY_PASSWORD
export UNAME=$UNAME
[[ "$SEAF_SKIP_SSL_CERT" ]] && export SEAF_SKIP_SSL_CERT=$SEAF_SKIP_SSL_CERT
[[ "$SEAF_UPLOAD_LIMIT" ]] && export SEAF_UPLOAD_LIMIT=$SEAF_UPLOAD_LIMIT
[[ "$SEAF_DOWNLOAD_LIMIT" ]] && export SEAF_DOWNLOAD_LIMIT=$SEAF_DOWNLOAD_LIMIT
[[ "$SEAF_2FA_SECRET" ]] && export SEAF_2FA_SECRET=$SEAF_2FA_SECRET
[[ "$SEAF_LIBRARY_PASSWORD" ]] && export SEAF_LIBRARY_PASSWORD=$SEAF_LIBRARY_PASSWORD
/bin/bash /home/seafuser/entrypoint.sh
EO