6 # This script works with the standard busybox tools.
8 PATH
=/bin
:/usr
/bin
:/opt
/bin
22 echo "This program needs to run as root" >&2
27 # To make sure that files are created with the correct permissions.
35 FIRMWARE_VERSION
=$
(cat /.unslung
)
37 elif grep -q OpenSlug
/etc
/issue
40 FIRMWARE_VERSION
=$
(awk '/OpenSlug/ {print $2}' /etc
/issue
)
44 FIRMWARE_VERSION
=unknown
47 if SSH_VERSION
=$
(ssh -V 2>&1)
49 if [ "${SSH_VERSION%_*}" = OpenSSH
]
56 if DROPBEAR
=$
(ssh -V 2>&1 |
grep Dropbear
)
58 SSH_VERSION
="${DROPBEAR}"
60 [ ${FIRMWARE} = unslung
] && SUPPORT
=2
104 echo "Unsuported configuration." >&2
106 echo "Suported configurations:" >&2
107 echo " unslung & openssh" >&2
109 echo "Work in progress:" >&2
110 echo " openslug & busybox" >&2
112 echo "Work in progress:" >&2
113 echo " openslug & openssh" >&2
115 echo "Use \"-f\" (force) to try creating a chroot" >&2
117 echo "And report succes on the mailinglist" >&2
119 echo "Detected firmware: $FIRMWARE_VERSION" >&2
120 echo "Detected ssh: $SSH_VERSION" >&2
122 if [ ${SUPPORT} = 2 -a ! "${FORCE}" ]
128 if [ -z "${USER}" -o "${ERROR}" ]
131 ${PROG} [-n] [-r root] [-h <home>] -u <user>
136 Don't use other options unless you know what you do!!
144 ROOT
="/home/${USER}_root"
149 HOME
="${ROOT}//${USER}"
153 # We should use adduser but it's not default installed on unslung
155 if [ -z "${CREATE}" ]
157 if grep -q "^${USER}:" /etc
/passwd
159 echo "User exists: Choose a other user name"
163 while grep -q :${ID}: /etc
/passwd
167 echo "${USER}:x:${ID}:100:${USER} (scponly):${HOME}:/opt/sbin/scponlyc" >>/etc
/passwd
172 for d
in bin etc lib usr usr
/bin usr
/lib usr
/libexec dev
177 chown
-R root
:root
"${ROOT}"
178 chmod -R 755 "${ROOT}" "${HOME}"
184 cp /bin
/busybox chgrp
186 for f
in chmod chown
ln ls mkdir
mv rm rmdir
193 for f
in ld-linux.so
.2 libc.so
.6 libcrypt.so
.1 libdl.so
.2 libm.so
.6 libnsl.so
.1 libnss_files.so
.2 libresolv.so
.2 libutil.so
.1 libgcc_s.so
.1
195 [ -f "/lib/${f}" ] && cp "/lib/${f}" .
200 echo "root:x:0:" > group
201 echo "users:x:100:" >> group
203 echo "root::0:0:::" > passwd
204 echo "bin::1:1:::" >> passwd
205 echo "${USER}::${ID}:100::/${USER}:" >> passwd
207 for f
in ld.so.conf ld.so.cache
209 [ -f "/etc/${f}" ] && cp "/etc/${f}" .
218 if [ -f /opt
/bin
/scp
]
221 elif [ -f /usr
/bin
/scp
]
226 cd "${ROOT}/usr/libexec"
227 if [ -f /opt
/libexec
/sftp-server
]
229 cp /opt
/libexec
/sftp-server .
230 elif [ -f /usr
/libexec
/sftp-server
]
232 cp /usr
/libexec
/sftp-server .
236 [ -f /opt
/lib
/libcrypto.so
.0.9.7 ] && cp /opt
/lib
/libcrypto.so
.0.9.7 .
238 if [ -f /opt
/lib
/libz.so
.1.2.3 ]
240 cp /opt
/lib
/libz.so
.1.2.3 .
241 ln -s libz.so
.1.2.3 libz.so
242 ln -s libz.so
.1.2.3 libz.so
.1
243 elif [ -f /usr
/lib
/libz.so
.1.2.3 ]
245 cp /usr
/lib
/libz.so
.1.2.3 .
246 ln -s libz.so
.1.2.3 libz.so
247 ln -s libz.so
.1.2.3 libz.so
.1
250 if [ -z "${PASSWD}" ]
256 # This doesn't work if we do it to fast after adding the account (bug?)
258 chown
"${USER}":100 "${HOME}"