dump from a script run from crontab fails with unset USER #1951

Closed
opened 2025-11-02 04:18:55 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @gullevek on GitHub (Jun 19, 2018).

  • Gitea version (or commit ref): 1.4.2
  • Git version: 2.17.1
  • Operating system: Debian
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

Running dump from a shell script from crontab will fail as the user check in go checks for USER which can be unset

sample:
crontab

0 0 * * * git /bin/backup_gitea.sh

backup_gitea.sh

#!/bin/bash
cd "/backup/gitea/"
/usr/local/bin/gitea dump -c /etc/gitea/app.ini

will fail with "empty user"
2018/06/19 01:00:02 ...s/setting/setting.go:994 NewContext()] [E] Expect user 'git' but
current user is:

adding 'export USER=$(whoami)' before the gitea dump will make the dump work

Reference in code:
71dee6b7c0/modules/user/user.go (L11)

Something like this might be a better approach to get the user
https://golangcode.com/get-the-current-username-name-and-home-dir-cross-platform/

Originally created by @gullevek on GitHub (Jun 19, 2018). - Gitea version (or commit ref): 1.4.2 - Git version: 2.17.1 - Operating system: Debian - Database (use `[x]`): - [X] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [X] Not relevant - Log gist: ## Description Running dump from a shell script from crontab will fail as the user check in go checks for USER which can be unset sample: crontab > 0 0 * * * git /bin/backup_gitea.sh backup_gitea.sh ``` #!/bin/bash cd "/backup/gitea/" /usr/local/bin/gitea dump -c /etc/gitea/app.ini ``` will fail with "empty user" 2018/06/19 01:00:02 ...s/setting/setting.go:994 NewContext()] [E] Expect user 'git' but current user is: adding 'export USER=$(whoami)' before the gitea dump will make the dump work Reference in code: https://github.com/go-gitea/gitea/blob/71dee6b7c09242707028cdfe23373a1f88d6a663/modules/user/user.go#L11 Something like this might be a better approach to get the user https://golangcode.com/get-the-current-username-name-and-home-dir-cross-platform/
GiteaMirror added the type/enhancementissue/stale labels 2025-11-02 04:18:55 -06:00
Author
Owner

@bwint commented on GitHub (Aug 30, 2018):

I have the same problem.

Thank you very much @gullevek for providing a solution!

@bwint commented on GitHub (Aug 30, 2018): I have the same problem. Thank you very much @gullevek for providing a solution!
Author
Owner

@alexdohmen commented on GitHub (Jan 8, 2019):

Another solution for docker container is to use the --user switch. The user is equal to the RUN_USER.

@alexdohmen commented on GitHub (Jan 8, 2019): Another solution for docker container is to use the --user switch. The user is equal to the RUN_USER.
Author
Owner

@stale[bot] commented on GitHub (Mar 9, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Mar 9, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@stale[bot] commented on GitHub (Mar 23, 2019):

This issue has been automatically closed because of inactivity. You can re-open it if needed.

@stale[bot] commented on GitHub (Mar 23, 2019): This issue has been automatically closed because of inactivity. You can re-open it if needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#1951