1. Support create avs user and root password

This commit is contained in:
Huang Xin 2022-06-29 09:15:08 -07:00
parent 79a9b58170
commit 7cfa02ca11
5 changed files with 105 additions and 8 deletions

View File

@ -0,0 +1,71 @@
SUMMARY = "Example recipe for using inherit useradd"
DESCRIPTION = "This recipe serves as an example for using features from useradd.bbclass"
SECTION = "examples"
PR = "r1"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
SRC_URI = "file://dot.bashrc \
file://dot.profile \
"
S = "${WORKDIR}"
#PACKAGES =+ "${PN}-user3 ${PN}-root"
inherit useradd
# You must set USERADD_PACKAGES when you inherit useradd. This
# lists which output packages will include the user/group
# creation code.
USERADD_PACKAGES = "${PN}"
#USERADD_PACKAGES = "${PN} ${PN}-user3 ${PN}-root"
# You must also set USERADD_PARAM and/or GROUPADD_PARAM when
# you inherit useradd.
# USERADD_PARAM specifies command line options to pass to the
# useradd command. Multiple users can be created by separating
# the commands with a semicolon. Here we'll create two users,
# user1 and user2:
USERADD_PARAM_${PN} = "-u 1000 -m -d /home/avs -r -s /bin/bash -P 'avs123!@#' avs"
# user3 will be managed in the useradd-example-user3 pacakge:
# As an example, we use the -P option to set clear text password for user3
#USERADD_PARAM_${PN}-user3 = "-u 1202 -d /home/user3 -r -s /bin/bash -P 'user3' user3"
# root will be managed in the useradd-root pacakge:
# As an example, we use the -P option to set clear text password for root
#USERADD_PARAM_${PN}-root = "-u 0 -d /home/root -r -s /bin/bash -P '123321' root"
# GROUPADD_PARAM works the same way, which you set to the options
# you'd normally pass to the groupadd command. This will create
# groups group1 and group2:
#GROUPADD_PARAM_${PN} = "-g 881 group1; -g 890 group2"
# Likewise, we'll manage group3 in the useradd-example-user3 package:
#GROUPADD_PARAM_${PN}-user3 = "-g 900 group3"
# Likewise, we'll manage group3 in the useradd-example-root package:
#GROUPADD_PARAM_${PN}-root = "-g 0 root"
do_install_append() {
install -m 0755 -o root -g root -d ${D}/home/root/
install -m 0755 -o root -g root ${S}/dot.bashrc ${D}/home/root/.bashrc
install -m 0755 -o root -g root ${S}/dot.profile ${D}/home/root/.profile
install -d -m 755 ${D}/home/avs/
install -m 0755 -o avs -g avs ${S}/dot.bashrc ${D}/home/avs/.bashrc
install -m 0755 -o avs -g avs ${S}/dot.profile ${D}/home/avs/.profile
}
# ALLOW_EMPTY_${PN} = "1"
FILES_${PN} = "/home/root/.bashrc /home/root/.profile /home/avs/.bashrc /home/avs/.profile"
# Prevents do_package failures with:
# debugsources.list: No such file or directory:
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"

View File

@ -0,0 +1,16 @@
# ~/.bashrc: executed by bash(1) for non-login shells.
export PS1='\h:\w\$ '
umask 022
# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval `dircolors`
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

View File

@ -0,0 +1,10 @@
# ~/.profile: executed by Bourne-compatible login shells.
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# path set by /etc/profile
# export PATH
mesg n

View File

@ -82,6 +82,7 @@ IMAGE_INSTALL_append = " \
libev \
iptables \
strace \
useradd \
"
install_proc() {
@ -136,7 +137,9 @@ install_proc() {
ln -s ../usr/share/zoneinfo/Asia/Hong_Kong localtime
cd -
sed -i '2,$s#/bin/sh#/bin/false#' ${IMAGE_ROOTFS}/etc/passwd
usermod --root ${IMAGE_ROOTFS} -G input,audio,video,netdev avs
usermod --root ${IMAGE_ROOTFS} -P "avs123!@#" root
}
ROOTFS_POSTPROCESS_COMMAND += " install_proc"

View File

@ -21,16 +21,13 @@ SRC_URI = "file://rotation \
file://issue.net \
file://issue \
file://usbd \
file://shadow \
file://passwd \
file://group \
file://share/dot.bashrc \
file://share/dot.profile \
file://licenses/GPL-2 \
"
S = "${WORKDIR}"
DEPENDS = "base-passwd"
# DEPENDS = "base-passwd"
INHIBIT_DEFAULT_DEPS = "1"
@ -120,9 +117,9 @@ do_install () {
install -m 0644 ${WORKDIR}/rotation ${D}${sysconfdir}/rotation
fi
install -m 0644 ${WORKDIR}/shadow ${D}${sysconfdir}/shadow
install -m 0644 ${WORKDIR}/group ${D}${sysconfdir}/group
install -m 0644 ${WORKDIR}/passwd ${D}${sysconfdir}/passwd
# install -m 0644 ${WORKDIR}/shadow ${D}${sysconfdir}/shadow
# install -m 0644 ${WORKDIR}/group ${D}${sysconfdir}/group
# install -m 0644 ${WORKDIR}/passwd ${D}${sysconfdir}/passwd
install -m 0644 ${WORKDIR}/fstab ${D}${sysconfdir}/fstab
install -m 0644 ${WORKDIR}/filesystems ${D}${sysconfdir}/filesystems