Skip to content

Commit

Permalink
feat: added titledb update feature
Browse files Browse the repository at this point in the history
  • Loading branch information
shawly committed Nov 5, 2021
1 parent 8cf25e2 commit cd62a8a
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 5 deletions.
13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ARG S6_OVERLAY_BASE_URL=https://github.com/just-containers/s6-overlay/releases/d
# Set NUT vars
ARG NUT_BRANCH=tags/v3.3
ARG NUT_RELEASE=https://github.com/blawar/nut/archive/refs/${NUT_BRANCH}.tar.gz
ARG TITLEDB_URL=https://github.com/blawar/titledb

# Set base images with s6 overlay download variable (necessary for multi-arch building via GitHub workflows)
FROM python:${PYTHON_VERSION} as python-amd64
Expand Down Expand Up @@ -108,8 +109,14 @@ RUN \
# Build nut
FROM python-${TARGETARCH:-amd64}${TARGETVARIANT}

ARG TITLEDB_URL

ENV UMASK=022 \
FIX_OWNERSHIP=true
FIX_OWNERSHIP=true \
TITLEDB_UPDATE=true \
TITLEDB_URL=${TITLEDB_URL} \
TITLEDB_REGION=US \
TITLEDB_LANGUAGE=en

# Download S6 Overlay
ADD ${S6_OVERLAY_RELEASE} /tmp/s6overlay.tar.gz
Expand All @@ -131,7 +138,9 @@ RUN \
shadow \
coreutils \
libjpeg-turbo \
tzdata && \
tzdata \
diffutils \
git && \
echo "Extracting s6 overlay..." && \
tar xzf /tmp/s6overlay.tar.gz -C / && \
echo "Creating nut user..." && \
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ docker run -d \
Where:
- `$HOME/nut/titles`: This location contains nsp files.
- `$HOME/nut/conf`: This location contains the config files for NUT.
- `$HOME/nut/_NSPOUT`: This location contains the nps files packed by NUT.
- `$HOME/nut/_NSPOUT`: This location contains the nsp files packed by NUT.

## Usage

Expand Down Expand Up @@ -92,6 +92,10 @@ of this parameter has the format `<VARIABLE_NAME>=<VALUE>`.
|`TZ`| [TimeZone] of the container. Timezone can also be set by mapping `/etc/localtime` between the host and the container. | `Etc/UTC` |
|`UMASK`| This sets the umask for the crafty control process in the container. | `022` |
|`FIX_OWNERSHIP`| This executes a script which checks if the USER_ID & GROUP_ID changed from the default of 1000 and fixes the ownership of the /nut folder if necessary, otherwise nut wont't start. It's recommended to leave this enabled if you changed the USER_ID or GROUP_ID. | `true` |
|`TITLEDB_UPDATE`| If the container should update the titledb when starting. | `true` |
|`TITLEDB_URL`| Git repository from which the titledb should be pulled. (If you change this URL you need to remove the /nut/titledb folder within your container!) | `https://github.com/blawar/titledb` |
|`TITLEDB_REGION`| Region to be used when importing the titledb. | `true` |
|`TITLEDB_LANGUAGE`| Language to be used when importing the titledb. | `true` |

### Data Volumes

Expand All @@ -105,6 +109,8 @@ format: `<HOST_DIR>:<CONTAINER_DIR>[:PERMISSIONS]`.
|`/nut/conf`| rw | This is the path NUT will use to read its config files. |
|`/nut/_NSPOUT`| rw | This is the path NUT use for outputting nsp files. |

**Note**: You can also use `/nut/titledb` within a separate bind mount or volume so your titledb is persisted between recreation of your container, this improves startup time.

### Ports

Here is the list of ports used by the container. They can be mapped to the host
Expand Down Expand Up @@ -153,6 +159,8 @@ services:
- TZ: Europe/Berlin
- USER_ID: 9000
- GROUP_ID: 9000
- TITLEDB_REGION: US
- TITLEDB_LANGUAGE: en
ports:
- "9000:9000"
volumes:
Expand Down Expand Up @@ -204,3 +212,19 @@ uid=1000(myuser) gid=1000(myuser) groups=1000(myuser),4(adm),24(cdrom),27(sudo),

The value of `uid` (user ID) and `gid` (group ID) are the ones that you should
be given the container.

## Troubleshooting

### The log says `could not load keys.txt, all crypto operations will fail`

If you just want to serve titles for your Switch you don't need the keys.txt at all.
Otherwise you can extract the keys.txt via biskeydump and Lockpick or find them on the internet, I won't provide any links however use Google.

### The log says `titledb/db.nza unknown extension titledb/db.nza`

You can ignore this.

### The log says something about "Permission denied" and/or NUT cant find any nsp files

This means your folder permissions are not correct or rather the folders are owned by a user that has a uid different from `1000`, see [User/Group IDs](#usergroup-ids).
Beware, if you have the environment variable `FIX_OWNERSHIP` set to `true` and change the `USER_ID` or `GROUP_ID` your volume's ownership will be changed!
23 changes: 21 additions & 2 deletions rootfs/etc/cont-init.d/01-create_configs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#!/usr/bin/with-contenv sh
#!/usr/bin/with-contenv bash

USER_ID=${USER_ID:-1000}
GROUP_ID=${GROUP_ID:-1000}

echo '
-------------------------------------
Checking conf folder...
Checking conf folder...
-------------------------------------'
if [ ! -f "/nut/conf/nut.default.conf" ]; then
echo "nut.default.conf not found! Copying..."
cp -v /nut/conf_template/nut.default.conf /nut/conf/nut.default.conf
echo '{}' > /nut/conf/nut.conf
fi

if ! diff /nut/conf/nut.default.conf /nut/conf_template/nut.default.conf > /dev/null; then
echo "nut.default.conf has been altered or updated!"
echo "To update your default config just remove nut.default.conf and restart the container."
echo "It is recommended to make changes within a nut.conf file rather than in nut.default.conf."
fi

if [ ! -f "/nut/conf/users.conf" ]; then
Expand All @@ -19,6 +29,15 @@ if [ ! -f "/nut/conf/blacklist.online.txt" ]; then
cp -v /nut/conf_template/blacklist.online.txt /nut/conf/blacklist.online.txt
fi

if ! diff /nut/conf/blacklist.online.txt /nut/conf_template/blacklist.online.txt > /dev/null; then
echo "blacklist.online.txt has been updated! Saving as blacklist.online.txt.new..."
cp -v /nut/conf_template/blacklist.online.txt /nut/conf/blacklist.online.txt.new
echo "Make sure to adjust your blacklist.online.txt or override it with the new one."
fi

echo "Changing ownership of /nut/conf folder..."
chown -R $USER_ID:$GROUP_ID /nut/conf

echo '
-------------------------------------
'
36 changes: 36 additions & 0 deletions rootfs/etc/cont-init.d/03-update-titledb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/with-contenv sh

USER_ID=${USER_ID:-1000}
GROUP_ID=${GROUP_ID:-1000}
TITLEDB_UPDATE=${UPDATE_TITLEDB:-true}
TITLEDB_URL=${TITLEDB_URL:-https://github.com/blawar/titledb}
TITLEDB_REGION=${TITLEDB_REGION:-US}
TITLEDB_LANGUAGE=${TITLEDB_LANGUAGE:-en}

echo '
-------------------------------------
Updating titledb...
-------------------------------------'

if [ "$TITLEDB_UPDATE" = true ]; then
if [ ! -d "/nut/titledb/.git" ]; then
echo "Getting titledb, this will take some time..."
rm -rf /nut/titledb/*
git clone --depth 1 "$TITLEDB_URL" /nut/titledb
echo "Adjusting ownership of /nut/titledb folder..."
chown -R $USER_ID:$GROUP_ID /nut/titledb
else
echo "Updating titledb, this might take some time..."
git -C /nut/titledb pull
fi
echo "Importing titledb..."
cd /nut
s6-setuidgid nut /usr/local/bin/python /nut/nut.py -U --import-region $TITLEDB_REGION --language $TITLEDB_LANGUAGE
else
echo "TITLEDB_UPDATE was disabled, skipping titledb update."
fi

echo "
Done.
-------------------------------------
"

0 comments on commit cd62a8a

Please sign in to comment.