1+ #! /bin/bash
2+
3+ set -e
4+
5+ cat << "EOF "
6+
7+ ▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
8+ ▐ ▌
9+ ▐ ██▓███ ██▀███ ▒█████ ███▄ ▄███▓ ██ ▄█▀ ███▄ █ ██▓ ▄████ ██░ ██ ▄▄▄█████▓ ▌
10+ ▐ ▓██░ ██▒▓██ ▒ ██▒▒██▒ ██▒▓██▒▀█▀ ██▒ ██▄█▒ ██ ▀█ █ ▓██▒ ██▒ ▀█▒▓██░ ██▒▓ ██▒ ▓▒ ▌
11+ ▐ ▓██░ ██▓▒▓██ ░▄█ ▒▒██░ ██▒▓██ ▓██░▓███▄░ ▓██ ▀█ ██▒▒██▒▒██░▄▄▄░▒██▀▀██░▒ ▓██░ ▒░ ▌
12+ ▐ ▒██▄█▓▒ ▒▒██▀▀█▄ ▒██ ██░▒██ ▒██ ▓██ █▄ ▓██▒ ▐▌██▒░██░░▓█ ██▓░▓█ ░██ ░ ▓██▓ ░ ▌
13+ ▐ ▒██▒ ░ ░░██▓ ▒██▒░ ████▓▒░▒██▒ ░██▒▒██▒ █▄▒██░ ▓██░░██░░▒▓███▀▒░▓█▒░██▓ ▒██▒ ░ ▌
14+ ▐ ▒▓▒░ ░ ░░ ▒▓ ░▒▓░░ ▒░▒░▒░ ░ ▒░ ░ ░▒ ▒▒ ▓▒░ ▒░ ▒ ▒ ░▓ ░▒ ▒ ▒ ░░▒░▒ ▒ ░░ ▌
15+ ▐ ░▒ ░ ░▒ ░ ▒░ ░ ▒ ▒░ ░ ░ ░░ ░▒ ▒░░ ░░ ░ ▒░ ▒ ░ ░ ░ ▒ ░▒░ ░ ░ ▌
16+ ▐ ░░ ░░ ░ ░ ░ ░ ▒ ░ ░ ░ ░░ ░ ░ ░ ░ ▒ ░░ ░ ░ ░ ░░ ░ ░ ▌
17+ ▐ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ▌
18+ ▐ ▌
19+ ▐ Cleanuparr ▌
20+ ▐▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
21+
22+ EOF
23+
24+ # Create group if it doesn't exist
25+ if ! getent group " $PGID " > /dev/null 2>&1 ; then
26+ echo " Creating group with GID $PGID "
27+ groupadd -g " $PGID " appgroup
28+ fi
29+
30+ # Create user if it doesn't exist
31+ if ! getent passwd " $PUID " > /dev/null 2>&1 ; then
32+ echo " Creating user with UID $PUID "
33+ useradd -u " $PUID " -g " $PGID " -s /bin/bash -M appuser
34+ fi
35+
36+ # Change ownership of app directory if not running as root
37+ if [ " $PUID " != " 0" ] || [ " $PGID " != " 0" ]; then
38+ mkdir -p /config || true
39+ chown -R " $PUID :$PGID " /app
40+ chown -R " $PUID :$PGID " /config
41+ fi
42+
43+ # Execute the main command as the specified user
44+ if [ " $PUID " = " 0" ] && [ " $PGID " = " 0" ]; then
45+ # Running as root, no need for gosu
46+ exec /app/Cleanuparr " $@ "
47+ else
48+ # Use gosu to drop privileges
49+ exec gosu " $PUID :$PGID " /app/Cleanuparr " $@ "
50+ fi
0 commit comments