Skip to content

Commit

Permalink
allow custom username (#2132)
Browse files Browse the repository at this point in the history
* removed hardcoded references to user "pi"

* removed check userNotPi

* change testuser in workflow and container

* updated docs

* updated comments and docs

* updated comments and docs

* remove extra home_path check

* changes testuser name and group
  • Loading branch information
AlvinSchiller authored Dec 4, 2023
1 parent f1558a2 commit cf5aa6c
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Otherwise the output of `cat /etc/os-release`
i.e. `master`
the following command will help with that
`cd /home/pi/RPi-Jukebox-RFID/ && git status | head -2`
`cd ~/RPi-Jukebox-RFID/ && git status | head -2`
-->

### Installscript
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/test_docker_debian_codename_sub_v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ on:
type: string
default: ubuntu-latest

env:
TEST_USER_NAME: testuser
TEST_USER_GROUP: testusergroup

# let only one instance run the test so cache is not corrupted.
# cancel already running instances as only the last run will be relevant
concurrency:
Expand Down Expand Up @@ -101,6 +105,8 @@ jobs:
cache-to: type=gha,mode=max,scope=${{ steps.vars.outputs.cache_scope }}
build-args: |
DEBIAN_CODENAME=${{ inputs.debian_codename }}
USER_NAME=${{ env.TEST_USER_NAME }}
USER_GROUP=${{ env.TEST_USER_GROUP }}
GIT_BRANCH=${{ github.head_ref || github.ref_name }}
GIT_USER=${{ github.event.pull_request.head.user.login || github.repository_owner }}
Expand Down Expand Up @@ -137,11 +143,7 @@ jobs:
strategy:
fail-fast: false
matrix:
username: ['pi']
test_script: ['run_install_common.sh', 'run_install_faststartup.sh', 'run_install_webapp_local.sh', 'run_install_webapp_download.sh']
include:
- username: hans
test_script: run_install_user_not_pi.sh

steps:
- name: Set up QEMU
Expand All @@ -160,11 +162,11 @@ jobs:
docker load --input ${{ needs.build.outputs.image_file_name }}
# Run test
- name: Run Test ${{ inputs.debian_codename }}-${{ matrix.username }}-${{ matrix.test_script }}
- name: Run Test ${{ inputs.debian_codename }}-${{ env.TEST_USER_NAME }}-${{ matrix.test_script }}
uses: tj-actions/docker-run@v2
with:
image: ${{ needs.build.outputs.image_tag_name }}
options: --platform ${{ inputs.platform }} --user ${{ matrix.username }} --init
options: --platform ${{ inputs.platform }} --user ${{ env.TEST_USER_NAME }} --init
name: ${{ matrix.test_script }}
args: |
./${{ matrix.test_script }}
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ For bug fixes and improvements just open an issue or PR as described below. If y
* By default this will get you to the `future3/main` branch. You will move to the `future3/develop` branch, do this:

~~~bash
cd /home/pi/RPi-Jukebox-RFID
cd ~/RPi-Jukebox-RFID
git checkout future3/develop
git fetch origin
git reset --hard origin/future3/develop
Expand Down Expand Up @@ -122,7 +122,7 @@ If you touched *any* Python file (even if only for fixing spelling errors), run
It contains out setup file.
~~~bash
cd /home/pi/RPi-Jukebox-RFID
cd ~/RPi-Jukebox-RFID
./run_flake8.sh
~~~
Expand All @@ -135,7 +135,7 @@ Tests are very few at the moment, but it cannot hurt to run them. If you have te
them.
~~~bash
cd /home/pi/RPi-Jukebox-RFID/
cd ~/RPi-Jukebox-RFID/
./run_pytest.sh
~~~
Expand Down
18 changes: 3 additions & 15 deletions ci/ci-debian.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG DEBIAN_CODENAME
ENV TERM=xterm DEBIAN_FRONTEND=noninteractive
ENV CI_RUNNING=true

# create pi configs to test installation
# create RPi configs to test installation
RUN touch /boot/config.txt
RUN echo "logo.nologo" > /boot/cmdline.txt

Expand Down Expand Up @@ -40,8 +40,8 @@ RUN echo "--- install packages (1) ---" \
RUN echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections
# ------

# Base Target for setting up the default user. user can be selected with the docker '--user YYY' option
FROM base as user
# Base Target for setting up a test user. user can be selected with the docker '--user YYY' option
FROM base as test-user
ARG USER_NAME=pi
ARG USER_GROUP=$USER_NAME
ARG USER_ID=1000
Expand All @@ -56,18 +56,6 @@ RUN groupadd --gid 1000 $USER_GROUP \
ENV XDG_RUNTIME_DIR=/run/user/$USER_ID DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USER_ID/bus
# ------


# Target for setting up an alternativ user 'hans:wurst'. user can be selected with the docker '--user YYY' option
FROM user as test-user

RUN export USER_ALT=hans \
&& export USER_ALT_GROUP=wurst \
&& groupadd --gid 1001 $USER_ALT_GROUP \
&& useradd -u 1001 -g $USER_ALT_GROUP -G sudo,$TEST_USER_GROUP -d /home/$USER_ALT -m -s /bin/bash -p '$1$iV7TOwOe$6ojkJQXyEA9bHd/SqNLNj0' $USER_ALT \
&& echo "$USER_ALT ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER_ALT
# ------


# Target for adding envs and scripts from the repo to test installation
FROM test-user as test-code
ARG GIT_BRANCH
Expand Down
25 changes: 0 additions & 25 deletions ci/installation/run_install_user_not_pi.sh

This file was deleted.

2 changes: 1 addition & 1 deletion documentation/builders/autohotspot.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ After connecting to the `Phoniebox_Hotspot` you are able to connect via
ssh to your Jukebox

``` bash
ssh pi@10.0.0.5
ssh <username>@10.0.0.5
```

## Changing basic configuration of the hotspot
Expand Down
4 changes: 2 additions & 2 deletions documentation/builders/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Before you can install the Phoniebox software, you need to prepare your Raspberr
* Click `Edit Settings`
* Switch to the `General` tab
* Provide a hostname. (When on Mac, you will be able to use it to connect via SSH)
* Username currently MUST be `pi`. Other usernames are currently not supported.
* Username
* Password
* Wifi
* Set locale settings
Expand Down Expand Up @@ -72,7 +72,7 @@ You will need a terminal, like PuTTY for Windows or the Terminal app for Mac to

7. Eject your SD card and insert it into your Raspberry Pi.
8. Start your Raspberry Pi by attaching a power supply.
9. Login into your Raspberry Pi, username is `pi` and password is `raspberry`.
9. Login into your Raspberry Pi
If `raspberrypi.local` does not work, find out your Raspberry Pi's IP address from your router.
</details>
Expand Down
7 changes: 3 additions & 4 deletions documentation/builders/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ The system consists of
4. [Web UI](system.md#web-ui) which is served through an Nginx web server
5. A set of [Configuration Tools](../developers/coreapps.md#configuration-tools) and a set of [Developer Tools](../developers/coreapps.md#developer-tools)

.. note:: The default install puts everything into the folder `/home/pi/RPi-Jukebox-RFID`.
Another folder might work, but is certainly not tested. Things are installed for the default user `pi`. Again,
another user might work, but is not tested.
.. note:: The default install puts everything into the users home folder `~/RPi-Jukebox-RFID`.
Another folder might work, but is certainly not tested.

## Music Player Daemon (MPD)

Expand Down Expand Up @@ -102,7 +101,7 @@ Starting and stopping the service can be useful for debugging or configuration c
The Web UI is served using nginx. Nginx runs as a system service. The home directory is localed at

```
/home/pi/RPi-Jukebox-RFID/src/webapp/build
~/RPi-Jukebox-RFID/src/webapp/build
```

The Nginx configuration is located at
Expand Down
4 changes: 2 additions & 2 deletions documentation/developers/known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ browser for now.

## Configuration

In `jukebox.yaml` (and all other config files): do not use relative paths with `~/some/dir`.
Always use entire explicit path, e.g. `/home/pi/some/dir`.
In `jukebox.yaml` (and all other config files):
Always use relative path from settingsfile `../../`, but do not use relative paths with `~/`.

**Sole** exception is in `playermpd.mpd_conf`.
28 changes: 0 additions & 28 deletions installation/install-jukebox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,6 @@ _check_os_type() {
fi
}

# currently the user 'pi' is mandatory
# https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/1785
_check_user() {
if [ "${CURRENT_USER}" != "pi" ]; then
echo
echo "ERROR: User must be 'pi'!"
echo " Other usernames are currently not supported."
echo " Please check the wiki for further information"
exit 2
fi

if [ "${HOME_PATH}" != "/home/pi" ]; then
echo
echo "ERROR: HomeDir must be '/home/pi'!"
echo " Other usernames are currently not supported."
echo " Please check the wiki for further information"
exit 2
fi

if [ ! -d "${HOME_PATH}" ]; then
echo
echo "ERROR: HomeDir ${HOME_PATH} does not exist."
echo " Please create it and start again."
exit 2
fi
}

# Manipulate file descriptor for logging
# Behavior:
# Write To logfile:
Expand Down Expand Up @@ -154,7 +127,6 @@ _load_sources() {

### CHECK PREREQUISITE
_check_os_type
_check_user

### SETUP LOGGING
_setup_logging
Expand Down
5 changes: 4 additions & 1 deletion installation/routines/setup_autohotspot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ _other_configuration() {
_install_service_and_timer() {
sudo cp "${INSTALLATION_PATH}"/resources/autohotspot/autohotspot.service /etc/systemd/system/autohotspot.service
sudo systemctl enable autohotspot.service
sudo cp "${INSTALLATION_PATH}"/resources/autohotspot/autohotspot.timer /etc/cron.d/autohotspot

local cron_autohotspot_file="/etc/cron.d/autohotspot"
sudo cp "${INSTALLATION_PATH}"/resources/autohotspot/autohotspot.timer "${cron_autohotspot_file}"
sudo sed -i "s|%%USER%%|${CURRENT_USER}|g" "${cron_autohotspot_file}"
}

_install_autohotspot_script() {
Expand Down
1 change: 1 addition & 0 deletions installation/routines/setup_jukebox_webapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ _jukebox_webapp_register_as_system_service_with_nginx() {

sudo mv -f "${WEBAPP_NGINX_SITE_DEFAULT_CONF}" "${WEBAPP_NGINX_SITE_DEFAULT_CONF}.orig"
sudo cp -f "${INSTALLATION_PATH}/resources/default-settings/nginx.default" "${WEBAPP_NGINX_SITE_DEFAULT_CONF}"
sudo sed -i "s|%%INSTALLATION_PATH%%|${INSTALLATION_PATH}|g" "${WEBAPP_NGINX_SITE_DEFAULT_CONF}"

# make sure nginx can access the home directory of the user
sudo chmod o+x "${HOME_PATH}"
Expand Down
4 changes: 2 additions & 2 deletions resources/autohotspot/autohotspot.timer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# cron timer for autohotspot
*/5 * * * * pi sudo /usr/bin/autohotspot 2>&1 | logger -t autohotspot
@reboot pi sudo /usr/bin/autohotspot 2>&1 | logger -t autohotspot
*/5 * * * * %%USER%% sudo /usr/bin/autohotspot 2>&1 | logger -t autohotspot
@reboot %%USER%% sudo /usr/bin/autohotspot 2>&1 | logger -t autohotspot
2 changes: 1 addition & 1 deletion resources/default-settings/jukebox.default.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IMPORTANT:
# Do not use paths with '~/some/dir' - always use '/home/pi/some/dir'
# Always use relative path from settingsfile `../../`, but do not use relative paths with `~/`.
# Sole (!) exception is in playermpd.mpd_conf
system:
box_name: Jukebox
Expand Down
8 changes: 4 additions & 4 deletions resources/default-settings/nginx.default
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ server {
listen 80 default_server;
listen [::]:80 default_server;

root /home/pi/RPi-Jukebox-RFID/src/webapp/build;
root %%INSTALLATION_PATH%%/src/webapp/build;

index index.html index.htm;

Expand All @@ -21,7 +21,7 @@ server {
}

location /logs {
root /home/pi/RPi-Jukebox-RFID/shared;
root %%INSTALLATION_PATH%%/shared;

autoindex on;
autoindex_exact_size off;
Expand All @@ -31,14 +31,14 @@ server {
}

location @buildwebui {
root /home/pi/RPi-Jukebox-RFID/resources/html;
root %%INSTALLATION_PATH%%/resources/html;
try_files /runbuildui.html =404;
internal;
}

error_page 404 = /404.html;
location /404.html {
root /home/pi/RPi-Jukebox-RFID/resources/html;
root %%INSTALLATION_PATH%%/resources/html;
internal;
}
}
4 changes: 1 addition & 3 deletions src/webapp/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const SUBSCRIPTIONS = [
'volume.level',
];

// TODO: This is not optimal, we should not know about this path here!
// Let's try to work with relatives paths in the RPC only!
const DEFAULT_AUDIO_DIR = '/home/pi/RPi-Jukebox-RFID/shared/audiofolders';
const DEFAULT_AUDIO_DIR = '../../shared/audiofolders';
const ROOT_DIRS = ['./', DEFAULT_AUDIO_DIR];


Expand Down

0 comments on commit cf5aa6c

Please sign in to comment.