Skip to content

Commit 2fc86ca

Browse files
committed
menu: remove assumption user ID is 1000
On menu.sh start, store current UID and GID to .env, if they are missing. Use these to run services that support custom user.
1 parent 15dca57 commit 2fc86ca

File tree

25 files changed

+81
-56
lines changed

25 files changed

+81
-56
lines changed

.templates/blynk_server/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ blynk_server:
77
restart: unless-stopped
88
environment:
99
- TZ=Etc/UTC
10-
- IOTSTACK_UID=1000
11-
- IOTSTACK_GID=1000
10+
- IOTSTACK_UID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
11+
- IOTSTACK_GID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
1212
ports:
1313
- "8180:8080"
1414
- "8440:8440"

.templates/domoticz/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ domoticz:
1010
restart: unless-stopped
1111
network_mode: bridge
1212
environment:
13-
- PUID=1000
14-
- PGID=1000
13+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
14+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
1515
# - TZ=
1616
# - WEBROOT=domoticz
1717

.templates/gitea/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ gitea:
66
- "7920:3000/tcp"
77
- "2222:22/tcp"
88
environment:
9-
- USER_UID=1000
10-
- USER_GID=1000
9+
- USER_UID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
10+
- USER_GID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
1111
volumes:
1212
- ./volumes/gitea/data:/data
1313
- /etc/timezone:/etc/timezone:ro

.templates/heimdall/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ heimdall:
22
image: ghcr.io/linuxserver/heimdall
33
container_name: heimdall
44
environment:
5-
- PUID=1000
6-
- PGID=1000
5+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
6+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
77
- TZ=Europe/Paris
88
volumes:
99
- ./volumes/heimdall/config:/config

.templates/homebridge/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ homebridge:
44
restart: unless-stopped
55
environment:
66
- TZ=Etc/UTC
7-
- PGID=1000
8-
- PUID=1000
7+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
8+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
99
- HOMEBRIDGE_CONFIG_UI=1
1010
- HOMEBRIDGE_CONFIG_UI_PORT=8581
1111
volumes:

.templates/homer/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ homer:
22
image: b4bz/homer:latest
33
container_name: homer
44
environment:
5-
- UID=1000
6-
- GID=1000
5+
- UID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
6+
- GID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
77
volumes:
88
- ./volumes/homer/assets:/www/assets
99
ports:

.templates/mariadb/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ mariadb:
33
container_name: mariadb
44
environment:
55
- TZ=Etc/UTC
6-
- PUID=1000
7-
- PGID=1000
6+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
7+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
88
- MYSQL_ROOT_PASSWORD=%randomAdminPassword%
99
- MYSQL_DATABASE=default
1010
- MYSQL_USER=mariadbuser

.templates/n8n/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ n8n:
2222
# - N8N_BASIC_AUTH_USER=<USER>
2323
# - N8N_BASIC_AUTH_PASSWORD=<PASSWORD>
2424

25-
# - PGID=1000
26-
# - PUID=1000
25+
# - PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
26+
# - PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
2727
# - USBDEVICES=/dev/ttyAMA0
2828
# - PACKAGES=mc
2929

.templates/nextcloud/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ nextcloud_db:
2323
restart: unless-stopped
2424
environment:
2525
- TZ=Etc/UTC
26-
- PUID=1000
27-
- PGID=1000
26+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
27+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
2828
- MYSQL_ROOT_PASSWORD=%randomPassword%
2929
- MYSQL_PASSWORD=%randomMySqlPassword%
3030
- MYSQL_DATABASE=nextcloud

.templates/plex/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ plex:
33
container_name: plex
44
network_mode: host
55
environment:
6-
- PUID=1000
7-
- PGID=1000
6+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
7+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
88
- VERSION=docker
99
volumes:
1010
- ./volumes/plex/config:/config

.templates/prometheus/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ prometheus:
66
ports:
77
- "9090:9090"
88
environment:
9-
- IOTSTACK_UID=1000
10-
- IOTSTACK_GID=1000
9+
- IOTSTACK_UID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
10+
- IOTSTACK_GID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
1111
volumes:
1212
- ./volumes/prometheus/data:/prometheus
1313
command:

.templates/python/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ python:
44
restart: unless-stopped
55
environment:
66
- TZ=Etc/UTC
7-
- IOTSTACK_UID=1000
8-
- IOTSTACK_GID=1000
7+
- IOTSTACK_UID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
8+
- IOTSTACK_GID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
99
# ports:
1010
# - "external:internal"
1111
volumes:

.templates/qbittorrent/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
image: linuxserver/qbittorrent
33
container_name: qbittorrent
44
environment:
5-
- PUID=1000
6-
- PGID=1000
5+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
6+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
77
- UMASK_SET=022
88
- WEBUI_PORT=15080
99
volumes:

.templates/syncthing/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
container_name: syncthing
44
hostname: raspberrypi #optional
55
environment:
6-
- PUID=1000
7-
- PGID=1000
6+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
7+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
88
- HOME=/app
99
- TZ=Etc/UTC
1010
volumes:

.templates/transmission/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ transmission:
22
image: linuxserver/transmission
33
container_name: transmission
44
environment:
5-
- PUID=1000
6-
- PGID=1000
5+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
6+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
77
- TZ=Etc/UTC
88
volumes:
99
- ./volumes/transmission/config:/config

.templates/wireguard/service.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ wireguard:
33
image: ghcr.io/linuxserver/wireguard
44
restart: unless-stopped
55
environment:
6-
- PUID=1000
7-
- PGID=1000
6+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
7+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
88
- TZ=Etc/UTC
99
- SERVERURL=your.dynamic.dns.name
1010
- SERVERPORT=51820

docs/Basic_setup/Backup-and-Restore.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ There are 2 ways to run backups:
1414

1515
The command that's run from the command line can also be executed from a cronjob:
1616

17-
```0 2 * * * cd /home/pi/IOTstack && /bin/bash ./scripts/backup.sh```
17+
```
18+
0 2 * * * cd /home/pi/IOTstack && /bin/bash ./scripts/backup.sh
19+
```
1820

1921
The current directory of bash must be in IOTstack's directory, to ensure that it can find the relative paths of the files it's meant to back up. In the example above, it's assume that it's inside the `pi` user's home directory.
2022

@@ -60,7 +62,13 @@ There are 2 ways to run a restore:
6062
* From the menu: `Backup and Restore` > `Restore from backup`
6163
* Running the following command: `bash ./scripts/restore.sh`
6264

63-
**Important**: The restore script assumes that the IOTstack directory is fresh, as if it was just cloned. If it is not fresh, errors may occur, or your data may not correctly be restored even if no errors are apparent.
65+
**Important**:
66+
67+
* The restore script assumes that the IOTstack directory is fresh, as if it was
68+
just cloned. If it is not fresh, errors may occur, or your data may not
69+
correctly be restored even if no errors are apparent.
70+
* When reinstalling Raspberry or migrating to a new installation, use the same
71+
user and ID (usually pi and 1000) as when you created the backup.
6472

6573
*Note*: It is suggested that you test that your backups can be restored after initially setting up, and anytime you add or remove a service. Major updates to services can also break backups.
6674

docs/Basic_setup/index.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ IOTstack makes the following assumptions:
3535
$ sudo apt upgrade -y
3636
```
3737

38-
4. You are logged-in as the user "pi".
39-
5. User "pi" has the user ID 1000.
40-
6. The home directory for user "pi" is `/home/pi/`.
41-
7. IOTstack is installed at `/home/pi/IOTstack` (with that exact spelling).
38+
For brevity, this documentation makes the following assumptions, but these are
39+
not technical requirements. If you use a different configuration, you'll just
40+
have to change the suggested commands correspondingly:
4241

43-
If the first three assumptions hold, assumptions four through six are Raspberry Pi defaults on a clean installation. The seventh is what you get if you follow these instructions faithfully.
42+
- You are logged-in as the user "pi".
43+
- The home directory for user "pi" is `/home/pi/`.
44+
- IOTstack is installed at `/home/pi/IOTstack` (with that exact spelling).
4445

4546
Please don't read these assumptions as saying that IOTstack will not run on other hardware, other operating systems, or as a different user. It is just that IOTstack gets most of its testing under these conditions. The further you get from these implicit assumptions, the more your mileage may vary.
4647

docs/Containers/Home-Assistant.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ your RPi hostname is raspberrypi)
124124
cap_add:
125125
- NET_ADMIN
126126
environment:
127-
- PUID=1000
128-
- PGID=1000
127+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
128+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
129129
- TZ=Etc/UTC
130130
- URL=<yourdomain>.duckdns.org
131131
- SUBDOMAINS=wildcard

docs/Containers/NextCloud.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ nextcloud_db:
2727
restart: unless-stopped
2828
environment:
2929
- TZ=Etc/UTC
30-
- PUID=1000
31-
- PGID=1000
30+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
31+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
3232
- MYSQL_ROOT_PASSWORD=«root_password»
3333
- MYSQL_PASSWORD=«user_password»
3434
- MYSQL_DATABASE=nextcloud

docs/Containers/Prometheus.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ The IOTstack implementation of *Prometheus* supports two environment variables:
237237

238238
```yaml
239239
environment:
240-
- IOTSTACK_UID=1000
241-
- IOTSTACK_GID=1000
240+
- IOTSTACK_UID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
241+
- IOTSTACK_GID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
242242
```
243243
244244
Those variables control ownership of the [Configuration directory](#configDir) and its contents. Those environment variables are present in the standard IOTstack service definition for *Prometheus* and have the effect of assigning ownership to "pi:pi".

docs/Containers/Python.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ When you select Python in the menu:
3434
restart: unless-stopped
3535
environment:
3636
- TZ=Etc/UTC
37-
- IOTSTACK_UID=1000
38-
- IOTSTACK_GID=1000
37+
- IOTSTACK_UID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
38+
- IOTSTACK_GID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
3939
# ports:
4040
# - "external:internal"
4141
volumes:
@@ -48,7 +48,7 @@ The service definition contains a number of customisation points:
4848

4949
1. `restart: unless-stopped` assumes your Python script will run in an infinite loop. If your script is intended to run once and terminate, you should remove this directive.
5050
2. `TZ=Etc/UTC` should be set to your local time-zone. Never use quote marks on the right hand side of a `TZ=` variable.
51-
3. If you are running as a different user ID, you may want to change both `IOTSTACK_UID` and `IOTSTACK_GID` to appropriate values.
51+
3. If you need a different user ID, you may want to change both `IOTSTACK_UID` and `IOTSTACK_GID` to appropriate values. By default they are defined to be the same as the current user when you run the menu, and saved to the file `~/IOTstack/.env`, changing this file will affect many services which may not be what you want.
5252

5353
Notes:
5454

@@ -444,8 +444,8 @@ Proceed like this:
444444
restart: unless-stopped restart: unless-stopped
445445
environment: environment:
446446
- TZ=Etc/UTC - TZ=Etc/UTC
447-
- IOTSTACK_UID=1000 - IOTSTACK_UID=1000
448-
- IOTSTACK_GID=1000 - IOTSTACK_GID=1000
447+
- IOTSTACK_UID=${IOTSTACK_UID:?...} - IOTSTACK_UID=${IOTSTACK_UID:?...}
448+
- IOTSTACK_GID=${IOTSTACK_GID:?...} - IOTSTACK_GID=${IOTSTACK_GID:?...}
449449
# ports: # ports:
450450
# - "external:internal" # - "external:internal"
451451
volumes: volumes:

docs/Containers/WireGuard.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ wireguard:
4141
image: ghcr.io/linuxserver/wireguard
4242
restart: unless-stopped
4343
environment:
44-
- PUID=1000
45-
- PGID=1000
44+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
45+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
4646
- TZ=Etc/UTC
4747
- SERVERURL=your.dynamic.dns.name
4848
- SERVERPORT=51820
@@ -247,8 +247,8 @@ You will need to create the `compose-override.yml` **before** running the menu t
247247
services:
248248
wireguard:
249249
environment:
250-
- PUID=1000
251-
- PGID=1000
250+
- PUID=${IOTSTACK_UID:?IOTSTACK_UID must be defined in ~/IOTstack/.env}
251+
- PGID=${IOTSTACK_GID:?IOTSTACK_GID must be defined in ~/IOTstack/.env}
252252
- TZ=Australia/Sydney
253253
- SERVERURL=downunda.duckdns.org
254254
- SERVERPORT=51820

menu.sh

+16-2
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,18 @@ function do_checks() {
380380
fi
381381
}
382382

383+
function do_dotenv_defaults() {
384+
echo "Checking .env is setting IOTSTACK_UID and IOTSTACK_GID"
385+
grep -qs '^IOTSTACK_UID=' .env || {
386+
echo "Adding missing definitions to .env (using UID:GID=$(id --user):$(id --group))"
387+
echo "# Changing IOTSTACK_UID or IOTSTACK_GID after you have started the stack is not" >> .env
388+
echo "# supported. File owners in the 'volumes'-folder won't automatically update to" >> .env
389+
echo "# match, resulting in various problems." >> .env
390+
echo "IOTSTACK_UID=$(id --user)" >> .env
391+
}
392+
grep -qs '^IOTSTACK_GID=' .env || echo "IOTSTACK_GID=$(id --group)" >> .env
393+
}
394+
383395
function do_help() {
384396
echo "USAGE:
385397
$0 [OPTIONS...]"
@@ -397,7 +409,7 @@ do
397409
--branch) CURRENT_BRANCH=${2:-$(git name-rev --name-only HEAD)}
398410
;;
399411
--no-check)
400-
NO_CHECK=true
412+
NO_CHECKS=true
401413
echo "Skipping preflight checks."
402414
;;
403415
--run-env-setup) # Sudo cannot be run from inside functions.
@@ -431,10 +443,12 @@ do
431443
shift
432444
done
433445

434-
if [[ -z "$NO_CHECK" ]]; then
446+
if [[ -z "$NO_CHECKS" ]]; then
435447
do_checks
436448
fi
437449

450+
do_dotenv_defaults
451+
438452
# This section is temporary, it's just for notifying people of potential breaking changes.
439453
if [[ -f .new_install ]]; then
440454
echo "Existing installation detected."

scripts/backup.sh

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ bash ./scripts/backup_restore/pre_backup_complete.sh >> $LOGFILE 2>&1
9090
echo "./services/" >> $BACKUPLIST
9191
echo "./volumes/" >> $BACKUPLIST
9292
[ -f "./docker-compose.yml" ] && echo "./docker-compose.yml" >> $BACKUPLIST
93+
[ -f "./docker-compose.override.yml" ] && echo "./docker-compose.override.yml" >> $BACKUPLIST
94+
[ -f "./.env" ] && echo "./.env" >> $BACKUPLIST
9395
[ -f "./compose-override.yml" ] && echo "./compose-override.yml" >> $BACKUPLIST
9496
[ -f "./extra" ] && echo "./extra" >> $BACKUPLIST
9597
[ -f "./.tmp/databases_backup" ] && echo "./.tmp/databases_backup" >> $BACKUPLIST

0 commit comments

Comments
 (0)