[
  {
    "path": ".github/workflows/build-and-publish.yml",
    "content": "name: Build and Publish\n\non:\n  # run it on push to the default repository branch\n  push:\n    branches: [main]\n  # run it during pull request\n  pull_request:\n\njobs:\n  # define job to build and publish docker image\n  build-and-push-docker-image:\n    name: Build Docker image and push to repositories\n    # run only when code is compiling and tests are passing\n    runs-on: ubuntu-latest\n\n    # steps to perform in job\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v2\n\n      # setup Docker buld action\n      - name: Set up Docker Buildx\n        id: buildx\n        uses: docker/setup-buildx-action@v1\n\n      - name: Login to DockerHub\n        uses: docker/login-action@v1\n        with:\n          username: ${{ secrets.DOCKERHUB_USERNAME }}\n          password: ${{ secrets.DOCKERHUB_TOKEN }}\n\n      - name: Login to Github Packages\n        uses: docker/login-action@v1\n        with:\n          registry: ghcr.io\n          username: ${{ github.actor }}\n          password: ${{ secrets.GHCR_PAT }}\n      \n      - name: Build image and push to Docker Hub and GitHub Container Registry\n        uses: docker/build-push-action@v2\n        with:\n          # relative path to the place where source code with Dockerfile is located\n          context: .\n          file: ./Dockerfile\n          # Note: tags has to be all lower-case\n          tags: |\n            seanap/auto-m4b:latest \n          # build on feature branches, push only on main branch\n          push: ${{ github.ref == 'refs/heads/main' }}\n\n      - name: Image digest\n        run: echo ${{ steps.docker_build.outputs.digest }}\n"
  },
  {
    "path": "Dockerfile",
    "content": "FROM phusion/baseimage:jammy-1.0.1\n#FROM phusion/baseimage:master\n\n#Basic Container\nRUN echo \"---- INSTALL RUNTIME PACKAGES ----\" && \\\n    apt-get update && apt-get install -y --no-install-recommends \\\n    python3-pip \\\n    git \\\n    #ffmpeg \\\n    dnsutils \\\n    iputils-ping \\\n    wget \\\n    crudini && rm -rf /var/lib/apt/lists/*\n\n#Build layer\nRUN echo \"---- INSTALL ALL BUILD-DEPENDENCIES ----\" && \\\n    buildDeps='gcc \\\n    g++ \\\n    make \\\n    autoconf \\\n    automake \\\n    build-essential \\\n    cmake \\\n    git-core \\\n    libass-dev \\\n    libfreetype6-dev \\\n    libgnutls28-dev \\\n    libmp3lame-dev \\\n    libsdl2-dev \\\n    libtool \\\n    libva-dev \\\n    libvdpau-dev \\\n    libvorbis-dev \\\n    libxcb1-dev \\\n    libxcb-shm0-dev \\\n    libxcb-xfixes0-dev \\\n    meson \\\n    ninja-build \\\n    pkg-config \\\n    texinfo \\\n    yasm \\\n    libfdk-aac-dev \\\n    zlib1g-dev' && \\\n    set -x && \\\n    apt-get update && apt-get install -y $buildDeps --no-install-recommends && \\\n    rm -rf /var/lib/apt/lists/* && \\\necho \"---- BUILD & INSTALL MP4V2 ----\" && \\\n    mkdir -p /tmp && \\\n    cd /tmp && \\\n    git clone https://github.com/sandreas/mp4v2 && \\\n    cd mp4v2 && \\\n    ./configure && \\\n    make && \\\n    make install && \\\n    make distclean && \\\necho \"---- BUILD & INSTALL ffmpeg ----\" && \\\n    mkdir -p ~/ffmpeg_sources ~/bin && \\\n    cd ~/ffmpeg_sources && \\\n    git -C fdk-aac pull 2> /dev/null || git clone --depth 1 https://github.com/mstorsjo/fdk-aac && \\\n    cd fdk-aac && \\\n    autoreconf -fiv && \\\n    ./configure --prefix=\"$HOME/ffmpeg_build\" --disable-shared && \\\n    make && \\\n    make install && \\\n    make distclean && \\\n    cd ~/ffmpeg_sources && \\\n    wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \\\n    tar xjvf ffmpeg-snapshot.tar.bz2 && \\\n    cd ffmpeg && \\\n    PATH=\"$HOME/bin:$PATH\" PKG_CONFIG_PATH=\"$HOME/ffmpeg_build/lib/pkgconfig\" ./configure \\\n      --prefix=\"$HOME/ffmpeg_build\" \\\n      --pkg-config-flags=\"--static\" \\\n      --extra-cflags=\"-I$HOME/ffmpeg_build/include\" \\\n      --extra-ldflags=\"-L$HOME/ffmpeg_build/lib\" \\\n      --extra-libs=\"-lpthread -lm\" \\\n      --ld=\"g++\" \\\n      --bindir=\"$HOME/bin\" \\\n      --enable-libfdk-aac \\\n      --enable-nonfree && \\\n    PATH=\"$HOME/bin:$PATH\" make && \\\n    make install && \\\n    hash -r && \\\n    make distclean && \\\n    mv ~/bin/* /bin/ && \\\necho \"---- REMOVE ALL BUILD-DEPENDENCIES ----\" && \\\n    apt-get purge -y --auto-remove $buildDeps && \\\n    ldconfig && \\\n    rm -r /tmp/* ~/ffmpeg_sources ~/bin\n\n#ENV WORKDIR /mnt/\n#ENV M4BTOOL_TMP_DIR /tmp/m4b-tool/\nLABEL Description=\"Container to run m4b-tool as a deamon.\"\n\nRUN echo \"---- INSTALL M4B-TOOL DEPENDENCIES ----\" && \\\n    apt-get update && apt-get install -y --no-install-recommends \\\n    fdkaac \\\n    php-cli \\\n    php-intl \\\n    php-json \\\n    php-mbstring \\\n    php-xml \\\n    libxcb-shm0-dev \\\n    libxcb-xfixes0-dev \\\n    libasound-dev \\\n    libsdl2-dev \\\n    libva-dev \\\n    libvdpau-dev\n\n#Mount volumes\nVOLUME /temp\nVOLUME /config\n\nENV PUID=\"\"\nENV PGID=\"\"\nENV CPU_CORES=\"\"\nENV SLEEPTIME=\"\"\n\n#Merge-Script importieren\nADD runscript.sh /etc/service/bot/run\nADD auto-m4b-tool.sh /\n\n#install actual m4b-tool\n#RUN echo \"---- INSTALL M4B-TOOL ----\" && \\\n#    wget https://github.com/sandreas/m4b-tool/releases/download/v.0.4.2/m4b-tool.phar -O /usr/local/bin/m4b-tool && \\\n#    chmod +x /usr/local/bin/m4b-tool\nARG M4B_TOOL_DOWNLOAD_LINK=\"https://github.com/sandreas/m4b-tool/releases/latest/download/m4b-tool.tar.gz\"\nRUN echo \"---- INSTALL M4B-TOOL ----\" \\\n    && if [ ! -f /tmp/m4b-tool.phar ]; then \\\n            wget \"${M4B_TOOL_DOWNLOAD_LINK}\" -O /tmp/m4b-tool.tar.gz && \\\n            if [ ! -f /tmp/m4b-tool.phar ]; then \\\n                tar xzf /tmp/m4b-tool.tar.gz -C /tmp/ && rm /tmp/m4b-tool.tar.gz ;\\\n            fi \\\n       fi \\\n    && mv /tmp/m4b-tool.phar /usr/local/bin/m4b-tool \\\n    && M4B_TOOL_PRE_RELEASE_LINK=$(wget -q -O - https://github.com/sandreas/m4b-tool/releases/tag/latest | grep -o 'M4B_TOOL_DOWNLOAD_LINK=[^ ]*' | head -1 | cut -d '=' -f 2) \\\n    && wget \"${M4B_TOOL_PRE_RELEASE_LINK}\" -O /tmp/m4b-tool.tar.gz \\\n    && tar xzf /tmp/m4b-tool.tar.gz -C /tmp/ && rm /tmp/m4b-tool.tar.gz \\\n    && mv /tmp/m4b-tool.phar /usr/local/bin/m4b-tool-pre \\\n    && chmod +x /usr/local/bin/m4b-tool /usr/local/bin/m4b-tool-pre\n\n#use the remommended clean command\nRUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*\n\n"
  },
  {
    "path": "README.md",
    "content": "# Auto-M4B\n\n[![Join the chat at https://gitter.im/Audiobook-Server/auto-m4b](https://badges.gitter.im/Audiobook-Server/auto-m4b.svg)](https://gitter.im/Audiobook-Server/auto-m4b?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\nThis container is mostly based on the powerful [m4b-tool](https://github.com/sandreas/m4b-tool) made by sandreas  \nThis repo is my fork of the fantastic [docker-m4b-tool](https://github.com/9Mad-Max5/docker-m4b-tool) created by 9Mad-Max5. \n\nThis is a docker container that will watch a folder for new books, auto convert mp3 books to chapterized m4b, and move all m4b books to a specific output folder, this output folder is where the [beets.io audible plugin](https://github.com/seanap/beets-audible) will look for audiobooks and use the audible api to perfectly tag and organize your books.\n\n## Intended Use\nThis is meant to be an automated step between aquisition and tagging.\n* Install via docker-compose \n* Save new audiobooks to a /recentlyadded folder.\n* All multifile m4b/mp3/m4a/ogg books will be converted to a chapterized m4b and saved to an /untagged folder  \n* This script will watch `/temp/recentlyadded` and automatically move mp3 books to `/temp/merge`, then automatically put all m4b's in the output folder `/temp/untagged`.  It also makes a backup incase something goes wrong (can be disabled if desired).\n\nUse the [beets.io audible plugin](https://github.com/seanap/beets-audible) to finish the tagging and sorting.\n\n## Known Limitations\n\n* The chapters are based on the mp3 tracks. A single mp3 file will become a single m4b with 1 chapter, also if the mp3 filenames are garbarge then your m4b chapternames will be terrible as well.  See section on Chapters below for how to manually adjust.  \n* The conversion process actually strips some tags and covers from the files, which is why you need to use a tagger (mp3tag or beets.io) before adding to Plex.\n\n## Need ARM Support?\nChange the image to `spencermksmith/auto-m4b`\n\n## Using torrents and need to preserve seeding?\nIn the settings of your client add this line to `Run external program on torrent completion`, it will copy all finished torrent files to your \"recentlyadded\" folder:\n* `cp -r \"%F\" \"path/to/temp/recentlyadded\"`\n\n## How to use\nThis docker assumes the following folder structure:\n\n```sh\ntemp\n│\n└───recentlyadded # Input folder Add new books here\n│     │     book1.m4b\n│     |     book2.mp3\n|     └─────book3\n│           │   01-book3.mp3\n│           │   ... \n└───merge # folder the script uses to combine mp3's\n│     └─────book2\n│           │   01-book2.mp3\n│           │   ...\n└───untagged # Output folder where all m4b's wait to be tagged\n│     └─────book4\n│           │   book4.m4b\n└───delete # needed by the script\n|\n└───fix # Manually fix books\n|\n└───backup # Backups incase anything goes wrong\n      └─────book2\n            │   01-book2.mp3\n            │   ... \n```\n\n### Installation\n\n1. Create a `temp` folder and keep the location in mind for Step 6 \n2. Install docker https://docs.docker.com/engine/install/ubuntu/\n3. Manage docker as non-root https://docs.docker.com/engine/install/linux-postinstall/\n4. Install docker-compose https://docs.docker.com/compose/install/\n5. Create the compose file:  \n    `nano docker-compose.yml`\n6. Paste the yaml code below into the compose file, and change the volume mount locations\n7. Put a test mp3 in the /temp/recentlyadded directory.\n8. Start the docker (It should convert the mp3 and leave it in your /temp/untagged directory. It runs automatically every 5 min)  \n    `docker-compose up -d`\n### Example docker-compose.yml\n*  Replace the `/path/to/...` with your actual folder locations, but leave the `:` and everything after:  \n*  Replace the PUID and PGID with your user ( [?](https://www.carnaghan.com/knowledge-base/how-to-find-your-uiduserid-and-gidgroupid-in-linux-via-the-command-line/) )\n#### docker-compose.yml\n```yaml\nversion: '3.7'\nservices:\n  auto-m4b:\n    image: seanap/auto-m4b\n    container_name: auto-m4b\n    volumes:\n      - /path/to/config:/config\n      - /path/to/temp:/temp\n    environment:\n      - PUID=1000\n      - PGID=1000\n      - CPU_CORES=2\n      - SLEEPTIME=1m\n      - MAKE_BACKUP=Y\n```\n\n## To Manually Set Chapters:\n1. Put a folder with mp3's in the `/temp/recentlyadded` and let the script process the book like normal\n2. In the output folder ( `/temp/untagged` ) there will be a book folder that includes the recently converted *.m4b and a *.chapters.txt file.\n3. Open the chapters file and edit/add/rename, then save\n4. Move the book folder (which contains the m4b and chapters.txt files) to `/temp/merge`\n5. When the script runs it will re-chapterize the m4b and move it back to `/temp/untagged`\n\n## Advanced Options\n\n#### Edit the script that is run\nYou shouldn't need to change any options, but if you want to you will need to exec into the docker container. By default only vim text editor is installed, you will need to do a `apt-get update && apt-get install nano` if you want to use nano to edit the scipt.  \n* `docker exec -it auto-m4b sh -c 'vi auto-m4b-tool.sh'`  \n\n#### CPU Cores\nThe script will automatically use all CPU cores available, to change the amount of cpu cores for the converting change the `--jobs` flag in the m4b-tool command, but do not set it higher than the amount of cores available.  \n\n#### Backup Folder\nFor those copying files from another source into the `recentlyadded` folder, it might not make sense to waste time copying to the `backup` folder (because they were already copied from somewhere else).  Backing up is enabled by default.  To disable this copy operation, change this line in your compose file: `- MAKE_BACKUP=N`.\n\n#### More Reading\nMore m4b-tool options https://github.com/sandreas/m4b-tool#reference\n\n\n"
  },
  {
    "path": "auto-m4b-tool.sh",
    "content": "#!/bin/bash\n# set m to 1\nm=1\n#variable defenition\ninputfolder=\"${INPUT_FOLDER:-\"/temp/merge/\"}\"\noutputfolder=\"${OUTPUT_FOLDER:-\"/temp/untagged/\"}\"\noriginalfolder=\"${ORIGINAL_FOLDER:-\"/temp/recentlyadded/\"}\"\nfixitfolder=\"${FIXIT_FOLDER:-\"/temp/fix\"}\"\nbackupfolder=\"${BACKUP_FOLDER:-\"/temp/backup/\"}\"\nbinfolder=\"${BIN_FOLDER:-\"/temp/delete/\"}\"\nm4bend=\".m4b\"\nlogend=\".log\"\n\n#ensure the expected folder-structure\nmkdir -p \"$inputfolder\"\nmkdir -p \"$outputfolder\"\nmkdir -p \"$originalfolder\"\nmkdir -p \"$fixitfolder\"\nmkdir -p \"$backupfolder\"\nmkdir -p \"$binfolder\"\n\n#fix of the user for the new created folders\nusername=\"$(whoami)\"\nuserid=\"$(id -u $username)\"\ngroupid=\"$(id -g $username)\"\nchown -R $userid:$groupid /temp \n\n#adjust the number of cores depending on the ENV CPU_CORES\nif [ -z \"$CPU_CORES\" ]\nthen\n      echo \"Using all CPU cores as not other defined.\"\n\t  CPUcores=$(nproc --all)\nelse\n      echo \"Using $CPU_CORES CPU cores as defined.\"\n\t  CPUcores=\"$CPU_CORES\"\nfi\n\n#adjust the interval of the runs depending on the ENV SLEEPTIME\nif [ -z \"$SLEEPTIME\" ]\nthen\n      echo \"Using standard 1 min sleep time.\"\n\t  sleeptime=1m\nelse\n      echo \"Using $SLEEPTIME min sleep time.\"\n\t  sleeptime=\"$SLEEPTIME\"\nfi\n\n#change to the merge folder, keeps this clear and the script could be kept inside the container\ncd \"$inputfolder\" || return\n\n# continue until $m  5\nwhile [ $m -ge 0 ]; do\n\n\t#copy files to backup destination\n\tif [ \"$MAKE_BACKUP\" == \"N\" ]; then\n\t\techo \"Skipping making a backup\"\n\telse\n\t\techo \"Making a backup of the whole $originalfolder\"\n\t\tcp -Ru \"$originalfolder\"* $backupfolder\n\tfi\n\n\t#make sure all single file mp3's & m4b's are in their own folder\n\techo \"Making sure all books are in their own folder\"\n\tfor file in \"$originalfolder\"*.{m4b,mp3}; do\n\t\tif [[ -f \"$file\" ]]; then\n\t\t\tmkdir \"${file%.*}\"\n\t\t\tmv \"$file\" \"${file%.*}\"\n\t\tfi\n\tdone\n\n\t# Finds folders with nested subfolders - renames and flattens files into a single folder\n\techo \"Flattening nested subfolders 3 levels deep or more and renaming files...\"\n\tfind \"$originalfolder\" -mindepth 3 -type f \\( -name '*.mp3' -o -name '*.m4b' -o -name '*.m4a' \\) -print0 | \n\twhile IFS= read -r -d '' file; do\n\t\t\t# Get the relative path from the original folder\n\t\t\trelative_path=\"${file#$originalfolder/}\"\n\t\t\t\n\t\t\t# Split the path into an array\n\t\t\tIFS='/' read -ra path_parts <<< \"$relative_path\"\n\n\t\t\t# Only process if the file is at least 3 levels deep\n\t\t\tif [ ${#path_parts[@]} -ge 4 ]; then\n\t\t\t\t\t# Get the filename (last element)\n\t\t\t\t\tfilename=\"${path_parts[-1]}\"\n\t\t\t\t\t\n\t\t\t\t\t# Get the grandparent directory\n\t\t\t\t\tgrandparent=\"${path_parts[3]}\"\n\n\t\t\t\t\t# Construct the new filename\n\t\t\t\t\tnew_filename=\"\"\n\t\t\t\t\tfor ((i=4; i<${#path_parts[@]}-1; i++)); do\n\t\t\t\t\t\t\tnew_filename+=\"${path_parts[i]} - \"\n\t\t\t\t\tdone\n\t\t\t\t\tnew_filename+=\"$filename\"\n\t\t\t\t\t\n\t\t\t\t\t# Create the new path (2 levels deep)\n\t\t\t\t\tnew_path=\"$originalfolder/$grandparent/$new_filename\"\n\t\t\t\t\t\n\t\t\t\t\t# Create the grandparent directory if it doesn't exist\n\t\t\t\t\tmkdir -p \"$(dirname \"$new_path\")\"\n\t\t\t\t\t\n\t\t\t\t\t# Move and rename the file\n\t\t\t\t\tmv -v \"$file\" \"$new_path\"\n\t\t\tfi\n\tdone\n\n\t#Move folders with multiple audiofiles to inputfolder\n\techo \"Moving folders with 2 or more audiofiles to $inputfolder \"\n\tfind \"$originalfolder\" -maxdepth 2 -mindepth 2 -type f \\( -name '*.mp3' -o -name '*.m4b' -o -name '*.m4a' \\) -print0 | xargs -0 -L 1 dirname | sort | uniq -c | grep -E -v '^ *1 ' | sed 's/^ *[0-9]* //' | while read i; do mv -v \"$i\" $inputfolder; done\n\n\n\t#Move single file mp3's to inputfolder\n\techo \"Moving single file mp3's to $inputfolder \"\n\tfind \"$originalfolder\" -maxdepth 2 -type f \\( -name '*.mp3' \\) -printf \"%h\\0\" | xargs -0 mv -t \"$inputfolder\"\n\n\t#Moving the single m4b files to the untagged folder as no Merge needed\n\techo \"Moving all the single m4b books to $outputfolder \"\n\tfind \"$originalfolder\" -maxdepth 2 -type f \\( -iname \\*.m4b -o -iname \\*.mp4 -o -iname \\*.m4a -o -iname \\*.ogg \\) -printf \"%h\\0\" | xargs -0 mv -t \"$outputfolder\"\n\n\t# clear the folders\n\trm -r \"$binfolder\"* 2>/dev/null\n\n\tif ls -d */ 2>/dev/null; then\n\t\techo Folder Detected\n\t\tfor book in *; do\n\t\t\tif [ -d \"$book\" ]; then\n\t\t\t\tmpthree=$(find \"$book\" -maxdepth 2 -type f \\( -name '*.mp3' -o -name '*.m4b' \\) | head -n 1)\n\t\t\t\tm4bfile=\"$outputfolder$book/$book$m4bend\"\n\t\t\t\tlogfile=\"$outputfolder$book/$book$logend\"\n\t\t\t\tchapters=$(ls \"$inputfolder$book\"/*chapters.txt 2> /dev/null | wc -l)\n\t\t\t\tif [ \"$chapters\" != \"0\" ]; then\n\t\t\t\t\techo Adjusting Chapters\n\t\t\t\t\tmp4chaps -i \"$inputfolder\"\"$book\"/*$m4bend\n\t\t\t\t\tmv \"$inputfolder$book\" \"$outputfolder\"\n\t\t\t\telse\n\t\t\t\t\techo Sampling $mpthree\n\t\t\t\t\tbit=$(ffprobe -hide_banner -loglevel 0 -of flat -i \"$mpthree\" -select_streams a -show_entries format=bit_rate -of default=noprint_wrappers=1:nokey=1)\n\t\t\t\t\techo Bitrate = $bit\n\t\t\t\t\techo The folder \"$book\" will be merged to \"$m4bfile\"\n\t\t\t\t\techo Starting Conversion\n\t\t\t\t\tm4b-tool merge \"$book\" -n -q --audio-bitrate=\"$bit\" --skip-cover --use-filenames-as-chapters --no-chapter-reindexing --audio-codec=libfdk_aac --jobs=\"$CPUcores\" --output-file=\"$m4bfile\" --logfile=\"$logfile\"\n\t\t\t\t\tmv \"$inputfolder$book\" \"$binfolder\"\n\t\t\t\tfi\n\t\t\t\techo Finished Converting\n\t\t\t\t#make sure all single file m4b's are in their own folder\n\t\t\t\techo Putting the m4b into a folder\n\t\t\t\tfor file in $outputfolder*.m4b; do\n\t\t\t\t\tif [[ -f \"$file\" ]]; then\n\t\t\t\t\t\tmkdir \"${file%.*}\"\n\t\t\t\t\t\tmv \"$file\" \"${file%.*}\"\n\t\t\t\t\tfi\n\t\t\t\tdone\n\t\t\t\techo Deleting duplicate mp3 audiobook folder\n\t\t\tfi\n\t\tdone\n\telse\n\t\techo No folders detected, next run $sleeptime min...\n\t\tsleep $sleeptime\n\tfi\ndone\n"
  },
  {
    "path": "clean_untagged.sh",
    "content": "find /PATH/TO/temp/untagged/ -mindepth 1 -type d -prune -exec sh -c '[ $(du -s \"$1\" | awk \"{print \\$1}\") -lt 1000 ] && rm -Rf \"$1\"' _ {} \\;\n"
  },
  {
    "path": "docker-compose.yml",
    "content": "version: '3.7'\nservices:\n  auto-m4b:\n    #image: seanap/auto-m4b\n    build: .\n    container_name: auto-m4b\n    volumes:\n      - ./config:/config\n      - ./temp:/temp\n    environment:\n      - PUID=1000\n      - PGID=1000\n      - CPU_CORES=2\n      - MAKE_BACKUP=N"
  },
  {
    "path": "runscript.sh",
    "content": "#!/bin/bash\n#cd /temp/mp3merge\n#file=\"/temp/mp3merge/auto-m4b-tool.sh\"\n#cp -u /auto-m4b-tool.sh /temp/mp3merge/auto-m4b-tool.sh\n\nuser_name=\"autom4b\"\nuser_id=\"1001\"\ngroup_id=\"100\"\n\n# Create user if they don't exist\nif ! id -u \"${PUID}\" &>/dev/null; then\n    # If PUID is a number, create a user with that id\n    if [[ \"${PUID}\" =~ ^[0-9]+$ ]]; then\n        user_id=\"${PUID}\"\n    # otherwise create a user with the name from PUID\n    else\n        user_name=\"${PUID}\"\n    fi\n    # If PGID is a number, create a user with that id\n    if [[ \"${PGID}\" =~ ^[0-9]+$ ]]; then\n        group_id=\"${PGID}\"\n    fi\n\n    addgroup --gid \"${group_id}\" \"${user_name}\"\n\n    adduser \\\n        --uid \"${user_id}\" \\\n        \"${user_name}\" \\\n        --gid \"${group_id}\"\n    echo \"\"    \n    echo \"Created missing ${user_name} user with UID ${user_id} and GID ${group_id}\"\nfi\n\ncmd_prefix=\"\"\nif [[ -n \"${PUID:-}\" ]]; then\n    cmd_prefix=\"/sbin/setuser ${user_name}\"\nfi\n\n${cmd_prefix} /auto-m4b-tool.sh 2> /config/auto-m4b-tool.log\n"
  }
]