Browse Source

Makefile: add grant_sudo_perm.sh

Signed-off-by: weishanshan1084 <weishanshan1084@phytium.com.cn>
pull/26/head
weishanshan1084 6 months ago
parent
commit
4dda116468
  1. 9
      Makefile
  2. 77
      utils/grant_sudo_perm.sh

9
Makefile

@ -587,7 +587,7 @@ prepare: $(BUILD_DIR)/buildroot-config/auto.conf
$(EXTRA_ENV) $(s) $(TARGET_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))
.PHONY: world
world: target-post-image
world: grant_sudo_perm target-post-image
.PHONY: prepare-sdk
prepare-sdk: world
@ -823,6 +823,13 @@ target-post-image: $(TARGETS_ROOTFS) target-finalize staging-finalize
$(call MESSAGE,"Executing post-image script $(s)"); \
$(EXTRA_ENV) $(s) $(BINARIES_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))
.PHONY: grant_sudo_perm
grant_sudo_perm:
ifeq ($(BR2_ROOTFS_SKELETON_UBUNTU)$(BR2_ROOTFS_SKELETON_DEBIAN),y)
@echo "*************************"
@$(TOPDIR)/utils/grant_sudo_perm.sh || exit 1
endif
.PHONY: source
source: $(foreach p,$(PACKAGES),$(p)-all-source)

77
utils/grant_sudo_perm.sh

@ -0,0 +1,77 @@
#!/bin/bash
SUDO_FILE=/etc/sudoers.d/buildroot_conf
permission_grant()
{
echo "User(${USER[@]}) is applying the sudo permission."
file=$(tempfile)
if [ "x$?" != "x0" ]
then
echo "Failed to creat a tempfile.";
return 1
fi
if [ -f ${SUDO_FILE} ]
then
${SUDO} rm -rf ${SUDO_FILE}
fi
echo "Host_Alias HOST = ${HOST}" >> ${file}
echo "User_Alias USER = "${USER[0]} >> ${file}
USER_RES=(${USER[@]})
unset USER_RES[0]
for u in "${USER_RES[@]}"
do
${SED} -i -e "/User_Alias/ s/$/,${u}/" ${file}
done
echo "Cmnd_Alias MOUNT = ${MOUNT},${UMOUNT}" >> ${file}
echo "Cmnd_Alias CHOWN = ${CHOWN}" >> ${file}
echo "Cmnd_Alias CHROOT1 = ${CHROOT1}" >> ${file}
echo "Cmnd_Alias CHMOD = ${CHMOD}" >> ${file}
echo "Cmnd_Alias FIND = ${FIND}" >> ${file}
echo "Cmnd_Alias CP = ${CP}" >> ${file}
echo "Cmnd_Alias MV = ${MV}" >> ${file}
echo "Cmnd_Alias DEBOOTSTRAP = ${DEBOOTSTRAP}" >> ${file}
echo "Cmnd_Alias MKDIR = ${MKDIR}" >> ${file}
echo "Cmnd_Alias TEE = ${TEE}" >> ${file}
echo "Cmnd_Alias RM = ${RM}" >> ${file}
echo "USER HOST=(root) NOPASSWD:MOUNT,CHMOD,CHROOT1,FIND,CP,MV,RM,MKDIR,TEE,CHOWN,DEBOOTSTRAP" >> ${file}
${SUDO} ${CHOWN} root:root ${file}
${SUDO} ${CHMOD} +r ${file}
${SUDO} ${MV} ${file} ${SUDO_FILE}
echo "Buildroot User(${USER[@]}) is granted"
return 0
}
HOST=ALL
SUDO=`which sudo`
MOUNT=`which mount`
UMOUNT=`which umount`
CHROOT1=`which chroot`
CHOWN=`which chown`
CHMOD=`which chmod`
FIND=`which find`
CP=`which cp`
MV=`which mv`
SED=`which sed`
MKDIR=`which mkdir`
TEE=`which tee`
RM=`which rm`
DEBOOTSTRAP=`which debootstrap`
if [ "x${DEBOOTSTRAP}" = "x" ]
then
echo "debootstrap not found. Try running \"install debootstrap\""
exit 1
fi
USER=()
confirmed=false
if [[ $# -eq 0 ]]
then
USER=($(whoami))
fi
if [[ ${#USER[@]} -eq 0 ]]
then
USER=($(whoami))
fi
permission_grant
Loading…
Cancel
Save