Bercik1337 / rt-auto-install

rtorrent and rutorrent automatic installer for modern operating systems on seedbox
150 stars 27 forks source link

Script is not working when the user is a single character #36

Closed ecengiz closed 1 year ago

ecengiz commented 1 year ago

Tested this on 20.04 and 22.04. Whenever I use a single-character user, the script is failing with the following error:

Creating session directory
mkdir: cannot create directory ‘/run/systemd\n/home/e/.rtorrent-session’: No such file or directory
chown: cannot access '/run/systemd'$'\n''/home/e/.rtorrent-session': No such file or directory
[FAIL]

Usernames with 2+ characters seem to be working.

Bercik1337 commented 1 year ago

I'll check it out tomorrow night, but... really ;D ? Normally when I deploy I use something longer (5-10chars), for dev/test i usually call it "rt", but never a single char. I'll see if quick fix is possible, but if not - i'm not gonna lie, I could close it as it's low impact.

I'll ping you tomorrow.

ecengiz commented 1 year ago

I know it is ridiculous and I agree that it is a low-impact bug. It took me a while to figure out why I couldn't get the script to work at all for a couple of hours and I figured, somebody might be having the same issue. I looked at the source code for a while and I am kinda curious to see what function is breaking the logic.

Bercik1337 commented 1 year ago

Confimed, found the culprit:

[bercik@ubu2004:~/rt-auto-install]$ grep "a": /etc/passwd
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
a:x:1002:1002:,,,:/home/a:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "b": /etc/passwd
b:x:1003:1003:,,,:/home/b:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "c": /etc/passwd
sync:x:4:65534:sync:/bin:/bin/sync
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
c:x:1004:1004:,,,:/home/c:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "d": /etc/passwd
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin
sshd:x:112:65534::/run/sshd:/usr/sbin/nologin
lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false
d:x:1005:1005:,,,:/home/d:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "e": /etc/passwd
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
landscape:x:109:115::/var/lib/landscape:/usr/sbin/nologin
pollinate:x:110:1::/var/cache/pollinate:/bin/false
e:x:1001:1001:,,,:/home/e:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "f": /etc/passwd
f:x:1006:1006:,,,:/home/f:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "g": /etc/passwd
syslog:x:104:110::/home/syslog:/usr/sbin/nologin
g:x:1007:1007:,,,:/home/g:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "h": /etc/passwd
h:x:1008:1008:,,,:/home/h:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "i": /etc/passwd
i:x:1009:1009:,,,:/home/i:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "j": /etc/passwd
j:x:1010:1010:,,,:/home/j:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "k": /etc/passwd
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
bercik:x:1000:1000:Bercik:/home/bercik:/bin/bash
k:x:1011:1011:,,,:/home/k:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "l": /etc/passwd
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
l:x:1012:1012:,,,:/home/l:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "m": /etc/passwd
tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false
m:x:1013:1013:,,,:/home/m:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "n": /etc/passwd
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
n:x:1014:1014:,,,:/home/n:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "o": /etc/passwd
o:x:1015:1015:,,,:/home/o:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "p": /etc/passwd
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
[bercik@ubu2004:~/rt-auto-install]$ grep "r": /etc/passwd
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
r:x:1016:1016:,,,:/home/r:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "s": /etc/passwd
sys:x:3:3:sys:/dev:/usr/sbin/nologin
games:x:5:60:games:/usr/games:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/usr/sbin/nologin
tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false
s:x:1017:1017:,,,:/home/s:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "t": /etc/passwd
root:x:0:0:root:/root:/bin/bash
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/usr/sbin/nologin
_apt:x:105:65534::/nonexistent:/usr/sbin/nologin
tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin
t:x:1018:1018:,,,:/home/t:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "u": /etc/passwd
u:x:1019:1019:,,,:/home/u:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "w": /etc/passwd
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
w:x:1020:1020:,,,:/home/w:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "x": /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/usr/sbin/nologin
syslog:x:104:110::/home/syslog:/usr/sbin/nologin
_apt:x:105:65534::/nonexistent:/usr/sbin/nologin
tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false
uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin
tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin
landscape:x:109:115::/var/lib/landscape:/usr/sbin/nologin
pollinate:x:110:1::/var/cache/pollinate:/bin/false
usbmux:x:111:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin
sshd:x:112:65534::/run/sshd:/usr/sbin/nologin
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
bercik:x:1000:1000:Bercik:/home/bercik:/bin/bash
lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false
e:x:1001:1001:,,,:/home/e:/bin/bash
a:x:1002:1002:,,,:/home/a:/bin/bash
b:x:1003:1003:,,,:/home/b:/bin/bash
c:x:1004:1004:,,,:/home/c:/bin/bash
d:x:1005:1005:,,,:/home/d:/bin/bash
f:x:1006:1006:,,,:/home/f:/bin/bash
g:x:1007:1007:,,,:/home/g:/bin/bash
h:x:1008:1008:,,,:/home/h:/bin/bash
i:x:1009:1009:,,,:/home/i:/bin/bash
j:x:1010:1010:,,,:/home/j:/bin/bash
k:x:1011:1011:,,,:/home/k:/bin/bash
l:x:1012:1012:,,,:/home/l:/bin/bash
m:x:1013:1013:,,,:/home/m:/bin/bash
n:x:1014:1014:,,,:/home/n:/bin/bash
o:x:1015:1015:,,,:/home/o:/bin/bash
r:x:1016:1016:,,,:/home/r:/bin/bash
s:x:1017:1017:,,,:/home/s:/bin/bash
t:x:1018:1018:,,,:/home/t:/bin/bash
u:x:1019:1019:,,,:/home/u:/bin/bash
w:x:1020:1020:,,,:/home/w:/bin/bash
x:x:1021:1021:,,,:/home/x:/bin/bash
y:x:1022:1022:,,,:/home/y:/bin/bash
z:x:1023:1023:,,,:/home/z:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "y": /etc/passwd
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
y:x:1022:1022:,,,:/home/y:/bin/bash
[bercik@ubu2004:~/rt-auto-install]$ grep "z": /etc/passwd
z:x:1023:1023:,,,:/home/z:/bin/bash

It happens when function SET_RTORRENT_USER tries to set HOMEDIR and it happens that grep returns MORE THAN ONE RESULT. It could possibly happen in other scenarios as well, but (since this is targeted for 1. fresh systems 2. newbie users) I doubt other scenario will occur.

I'll give myself a week or so to figure out solution. Either I make it or I won't because as we agreed - it's super rare. Easiest of all, could be to add step that verifies if username is more than 1 character :)

Bercik1337 commented 1 year ago

Fixed, it should be fine now. If problem persists please reopen.