diff --git a/entrypoint.sh b/entrypoint.sh index 5274927..2f4ce90 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,24 +4,31 @@ downloadsPath="/downloads" profilePath="/config" qbtConfigFile="$profilePath/qBittorrent/config/qBittorrent.conf" -if [ -n "$PUID" ] && [ "$PUID" != "$(id -u qbtUser)" ]; then - sed -i "s|^qbtUser:x:[0-9]*:|qbtUser:x:$PUID:|g" /etc/passwd +isRoot="0" +if [ "$(id -u)" = "0" ]; then + isRoot="1" fi -if [ -n "$PGID" ] && [ "$PGID" != "$(id -g qbtUser)" ]; then - sed -i "s|^\(qbtUser:x:[0-9]*\):[0-9]*:|\1:$PGID:|g" /etc/passwd - sed -i "s|^qbtUser:x:[0-9]*:|qbtUser:x:$PGID:|g" /etc/group -fi +if [ "$isRoot" = "1" ]; then + if [ -n "$PUID" ] && [ "$PUID" != "$(id -u qbtUser)" ]; then + sed -i "s|^qbtUser:x:[0-9]*:|qbtUser:x:$PUID:|g" /etc/passwd + fi -if [ -n "$PAGID" ]; then - _origIFS="$IFS" - IFS=',' - for AGID in $PAGID; do - AGID=$(echo "$AGID" | tr -d '[:space:]"') - addgroup -g "$AGID" "qbtGroup-$AGID" - addgroup qbtUser "qbtGroup-$AGID" - done - IFS="$_origIFS" + if [ -n "$PGID" ] && [ "$PGID" != "$(id -g qbtUser)" ]; then + sed -i "s|^\(qbtUser:x:[0-9]*\):[0-9]*:|\1:$PGID:|g" /etc/passwd + sed -i "s|^qbtUser:x:[0-9]*:|qbtUser:x:$PGID:|g" /etc/group + fi + + if [ -n "$PAGID" ]; then + _origIFS="$IFS" + IFS=',' + for AGID in $PAGID; do + AGID=$(echo "$AGID" | tr -d '[:space:]"') + addgroup -g "$AGID" "qbtGroup-$AGID" + addgroup qbtUser "qbtGroup-$AGID" + done + IFS="$_origIFS" + fi fi if [ ! -f "$qbtConfigFile" ]; then @@ -52,13 +59,15 @@ if [ -z "$QBT_WEBUI_PORT" ]; then QBT_WEBUI_PORT=8080 fi -# those are owned by root by default -# don't change existing files owner in `$downloadsPath` -if [ -d "$downloadsPath" ]; then - chown qbtUser:qbtUser "$downloadsPath" -fi -if [ -d "$profilePath" ]; then - chown qbtUser:qbtUser -R "$profilePath" +if [ "$isRoot" = "1" ]; then + # those are owned by root by default + # don't change existing files owner in `$downloadsPath` + if [ -d "$downloadsPath" ]; then + chown qbtUser:qbtUser "$downloadsPath" + fi + if [ -d "$profilePath" ]; then + chown qbtUser:qbtUser -R "$profilePath" + fi fi # set umask just before starting qbt @@ -66,10 +75,19 @@ if [ -n "$UMASK" ]; then umask "$UMASK" fi -exec \ - doas -u qbtUser \ +if [ "$isRoot" = "1" ]; then + exec \ + doas -u qbtUser \ + qbittorrent-nox \ + "$confirmLegalNotice" \ + --profile="$profilePath" \ + --webui-port="$QBT_WEBUI_PORT" \ + "$@" +else + exec \ qbittorrent-nox \ "$confirmLegalNotice" \ --profile="$profilePath" \ --webui-port="$QBT_WEBUI_PORT" \ "$@" +fi diff --git a/manual_build/entrypoint.sh b/manual_build/entrypoint.sh index 5274927..2f4ce90 100755 --- a/manual_build/entrypoint.sh +++ b/manual_build/entrypoint.sh @@ -4,24 +4,31 @@ downloadsPath="/downloads" profilePath="/config" qbtConfigFile="$profilePath/qBittorrent/config/qBittorrent.conf" -if [ -n "$PUID" ] && [ "$PUID" != "$(id -u qbtUser)" ]; then - sed -i "s|^qbtUser:x:[0-9]*:|qbtUser:x:$PUID:|g" /etc/passwd +isRoot="0" +if [ "$(id -u)" = "0" ]; then + isRoot="1" fi -if [ -n "$PGID" ] && [ "$PGID" != "$(id -g qbtUser)" ]; then - sed -i "s|^\(qbtUser:x:[0-9]*\):[0-9]*:|\1:$PGID:|g" /etc/passwd - sed -i "s|^qbtUser:x:[0-9]*:|qbtUser:x:$PGID:|g" /etc/group -fi +if [ "$isRoot" = "1" ]; then + if [ -n "$PUID" ] && [ "$PUID" != "$(id -u qbtUser)" ]; then + sed -i "s|^qbtUser:x:[0-9]*:|qbtUser:x:$PUID:|g" /etc/passwd + fi -if [ -n "$PAGID" ]; then - _origIFS="$IFS" - IFS=',' - for AGID in $PAGID; do - AGID=$(echo "$AGID" | tr -d '[:space:]"') - addgroup -g "$AGID" "qbtGroup-$AGID" - addgroup qbtUser "qbtGroup-$AGID" - done - IFS="$_origIFS" + if [ -n "$PGID" ] && [ "$PGID" != "$(id -g qbtUser)" ]; then + sed -i "s|^\(qbtUser:x:[0-9]*\):[0-9]*:|\1:$PGID:|g" /etc/passwd + sed -i "s|^qbtUser:x:[0-9]*:|qbtUser:x:$PGID:|g" /etc/group + fi + + if [ -n "$PAGID" ]; then + _origIFS="$IFS" + IFS=',' + for AGID in $PAGID; do + AGID=$(echo "$AGID" | tr -d '[:space:]"') + addgroup -g "$AGID" "qbtGroup-$AGID" + addgroup qbtUser "qbtGroup-$AGID" + done + IFS="$_origIFS" + fi fi if [ ! -f "$qbtConfigFile" ]; then @@ -52,13 +59,15 @@ if [ -z "$QBT_WEBUI_PORT" ]; then QBT_WEBUI_PORT=8080 fi -# those are owned by root by default -# don't change existing files owner in `$downloadsPath` -if [ -d "$downloadsPath" ]; then - chown qbtUser:qbtUser "$downloadsPath" -fi -if [ -d "$profilePath" ]; then - chown qbtUser:qbtUser -R "$profilePath" +if [ "$isRoot" = "1" ]; then + # those are owned by root by default + # don't change existing files owner in `$downloadsPath` + if [ -d "$downloadsPath" ]; then + chown qbtUser:qbtUser "$downloadsPath" + fi + if [ -d "$profilePath" ]; then + chown qbtUser:qbtUser -R "$profilePath" + fi fi # set umask just before starting qbt @@ -66,10 +75,19 @@ if [ -n "$UMASK" ]; then umask "$UMASK" fi -exec \ - doas -u qbtUser \ +if [ "$isRoot" = "1" ]; then + exec \ + doas -u qbtUser \ + qbittorrent-nox \ + "$confirmLegalNotice" \ + --profile="$profilePath" \ + --webui-port="$QBT_WEBUI_PORT" \ + "$@" +else + exec \ qbittorrent-nox \ "$confirmLegalNotice" \ --profile="$profilePath" \ --webui-port="$QBT_WEBUI_PORT" \ "$@" +fi