summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2013-02-25 14:39:52 +0100
committerJonathan Bauer2013-02-25 14:39:52 +0100
commita09cf9dea13b1d19c1f57e836fee3848aef779c9 (patch)
tree8353430c354ed2b34ed3e1e54649c4f4e432fa1f
parentcanonicalize function for paths (diff)
parentreally fix password generation/replacement (diff)
downloadtm-scripts-a09cf9dea13b1d19c1f57e836fee3848aef779c9.tar.gz
tm-scripts-a09cf9dea13b1d19c1f57e836fee3848aef779c9.tar.xz
tm-scripts-a09cf9dea13b1d19c1f57e836fee3848aef779c9.zip
Merge branch 'master' of git.openslx.org:openslx-ng/tm-scripts
-rw-r--r--helper/fileutil.inc9
-rw-r--r--helper/useradd.inc14
-rw-r--r--remote/tools/base/base.build6
3 files changed, 17 insertions, 12 deletions
diff --git a/helper/fileutil.inc b/helper/fileutil.inc
index 40bc42d5..3c165d99 100644
--- a/helper/fileutil.inc
+++ b/helper/fileutil.inc
@@ -6,12 +6,11 @@ tarcopy () {
return
fi
local SHORT=$1
- [ ${#SHORT} -gt 18 ] && SHORT=$(echo "$SHORT" | cut -c-13)...$(echo "$SHORT" | cut -c${#SHORT}-)
+ [ ${#SHORT} -gt 23 ] && SHORT=$(echo "$SHORT" | cut -c-18)...$(echo "$SHORT" | cut -c$[${#SHORT} - 4]-)
[ -z $2 ] && perror "tarcopy called with empty destination."
tar -cp "$1" | tar -xp -C "$2"
- local PS1=$PIPESTATUS[0]
- local PS2=$PIPESTATUS[1]
- [ $PS1 -ne 0 ] && perror "packing-part of tar-copy from '$SHORT' to '$2' failed."
- [ $PS2 -ne 0 ] && perror "unpacking-part of tar-copy from '$SHORT' to '$2' failed."
+ local PS=(${PIPESTATUS[*]})
+ [ "x${PS[0]}" != "x0" ] && perror "packing-part of tar-copy from '$SHORT' to '$2' failed. (${PS[0]})"
+ [ "x${PS[1]}" != "x0" ] && perror "unpacking-part of tar-copy from '$SHORT' to '$2' failed. (${PS[1]})"
}
diff --git a/helper/useradd.inc b/helper/useradd.inc
index f8675dd5..8b1315c6 100644
--- a/helper/useradd.inc
+++ b/helper/useradd.inc
@@ -70,6 +70,9 @@ add_user() {
local _PASSWD=${INIT_DIR}/etc/passwd
local _GROUP=${INIT_DIR}/etc/group
local _SHADOW=${INIT_DIR}/etc/shadow
+ [ ! -f "${_PASSWD}" ] && perror "add_user: password file does not exist in target system. (build base first)"
+ [ ! -f "${_GROUP}" ] && perror "add_user: group file does not exist in target system. (build base first)"
+ [ ! -f "${_SHADOW}" ] && perror "add_user: shadow file does not exist in target system. (build base first)"
if [ "x$1" != "x" ]
then
local USER=$1
@@ -127,9 +130,11 @@ add_user() {
then
local PASSWORD='*'
else
- PASSWORD=$(sha1pass "${PASSWORD}")
- [ -z "${PASSWORD}" ] && PASSWORD=$(openssl passwd -1 "${PASSWORD}")
- [ -z "${PASSWORD}" ] && perror "Error generating hashed password for $USER"
+ pdebug "Hashing password '$PASSWORD' for '$USER'"
+ local PW=$(mkpasswd -m sha-512 "${PASSWORD}")
+ [ -z "${PW}" ] && PASSWORD=$(openssl passwd -1 "${PASSWORD}")
+ [ -z "${PW}" ] && perror "Error generating hashed password for $USER"
+ PASSWORD=$PW
fi
# add user, or replace password
if [ -z "${_UID}" ]; then
@@ -139,7 +144,7 @@ add_user() {
pinfo "Created user $USER"
elif [ "$PASSWORD" != "*" ]; then
# update user's password
- sed -i -r "s/^${USER}:[^:]*:(.*)\$/${USER}:${PASSWORD}:\1/g" "${_SHADOW}"
+ sed -i -r "s#^${USER}:[^:]*:(.*)\$#${USER}:${PASSWORD}:\1#g" "${_SHADOW}"
pinfo "Updated password of $USER"
fi
[ -z "${_GID}" ] && pinfo "Created group $GROUP" && echo "${GROUP}:x:${GROUPID}:" >> "${_GROUP}"
@@ -151,6 +156,7 @@ add_group () {
local _PASSWD=${INIT_DIR}/etc/passwd
local _GROUP=${INIT_DIR}/etc/group
local _SHADOW=${INIT_DIR}/etc/shadow
+ [ ! -f "${_GROUP}" ] && perror "add_user: group file does not exist in target system. (build base first)"
local GROUP=$1
local GROUPID="-"
if ! [[ $GROUP =~ $NAME_REGEX ]]; then
diff --git a/remote/tools/base/base.build b/remote/tools/base/base.build
index fa58585d..aee237a0 100644
--- a/remote/tools/base/base.build
+++ b/remote/tools/base/base.build
@@ -86,11 +86,11 @@ clean_users_and_groups() {
post_copy() {
# make basic directory structure
- mkdir -p "${INIT_DIR}/{bin,dev,proc,lib,etc,mnt,sys,var/run,var/lock,var/log,run/lock,run/shm,openslx/mnt}"
+ mkdir -p "${INIT_DIR}"/{bin,dev,proc,lib,etc,mnt,sys,var/run,var/lock,var/log,run/lock,run/shm,openslx/mnt}
# copy devices from running system
- cp -a "/dev/{console,kmsg,mem,null,shm,tty,tty0,tty1,tty9,fb0,urandom,zero}" \
- "${INIT_DIR}/dev"
+ cp -a /dev/{console,kmsg,mem,null,shm,tty,tty0,tty1,tty9,fb0,urandom,zero} \
+ "${INIT_DIR}"/dev
# set /etc/environment to include /openslx/bin and /openslx/sbin
echo "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/openslx/sbin:/openslx/bin\"" \