[PC-BSD Commits] r17293 - pcbsd/current/src-sh/pbi-manager

svn at pcbsd.org svn at pcbsd.org
Sat Jun 16 07:07:07 PDT 2012


Author: kris
Date: 2012-06-16 14:07:07 +0000 (Sat, 16 Jun 2012)
New Revision: 17293

Modified:
   pcbsd/current/src-sh/pbi-manager/install.sh
   pcbsd/current/src-sh/pbi-manager/pbi-manager
Log:

Add new ability to pbi-manager. Now when running pbi_makeport, it will
save any users / groups the ports require, and attempt to create them
during PBI installation.

If the PBI is being installed as non-root, instead it will warn about
any users / groups that need to be manually created. 

For functionality to work, the port must set USERS= or GROUPS= in the
Makefile, and have the corrisponding entries in UIDs and GIDs respectively



Modified: pcbsd/current/src-sh/pbi-manager/install.sh
===================================================================
--- pcbsd/current/src-sh/pbi-manager/install.sh	2012-06-16 09:17:59 UTC (rev 17292)
+++ pcbsd/current/src-sh/pbi-manager/install.sh	2012-06-16 14:07:07 UTC (rev 17293)
@@ -84,6 +84,7 @@
 
 # Create the wrapper binary
 cd ${DIR}/wrapper
+make clean
 make install
 chown root:wheel /usr/pbi/.pbiwrapper 
 chmod 644 /usr/pbi/.pbiwrapper

Modified: pcbsd/current/src-sh/pbi-manager/pbi-manager
===================================================================
--- pcbsd/current/src-sh/pbi-manager/pbi-manager	2012-06-16 09:17:59 UTC (rev 17292)
+++ pcbsd/current/src-sh/pbi-manager/pbi-manager	2012-06-16 14:07:07 UTC (rev 17293)
@@ -1320,6 +1320,10 @@
 	PBI_APPDESK_DIR=".${MOD_XDGDESK_DIR}"
 	PBI_APPMENU_DIR=".${MOD_XDGMENU_DIR}"
 	PBI_APPMIME_DIR=".${MOD_XDGMIME_DIR}"
+	PBI_BUILD_USERS=""
+	PBI_BUILD_GROUPS=""
+	PBI_INS_USERSFILE=".pbi-uids"
+	PBI_INS_GROUPSFILE=".pbi-gids"
 	PBI_DESKADD="NO"
 	PBI_MENUADD="NO"
 	PBI_MIMEADD="NO"
@@ -2925,6 +2929,9 @@
 	mk_pbi_extract_dir
 	pbi_extract_archive
 	
+	pbi_add_check_gids
+	pbi_add_check_uids
+
 	pbi_add_run_script
 	check_postinstall_script
 
@@ -2936,10 +2943,93 @@
 	clean_remote_dl
 }
 
+# Check for any GIDs we need to create
+pbi_add_check_gids() {
+	if [ ! -e "${PBI_PROGDIRPATH}/${PBI_INS_GROUPSFILE}" ] ; then return ; fi
+	runUID=`id -u`
+
+	while read gidLine
+	do
+		gName=`echo $gidLine | cut -d ':' -f 1`
+		gID=`echo $gidLine | cut -d ':' -f 3`
+		gUsers=`echo $gidLine | cut -d ':' -f 4`
+
+		# Is this group already on the system?
+		pw groupshow $gName >/dev/null 2>/dev/null
+		if [ $? -eq 0 ] ; then 
+			echo "Using existing group: $gName"
+		else
+			# Are we installing as root?
+			if [ "$runUID" != "0" ] ; then
+				echo "Please create group \"$gName\" manually or re-install PBI as root."
+			else
+				echo "Adding group: $gName"
+				pw groupadd $gName -g $gID;
+			fi
+		fi
+
+		if [ -n "$gUsers" ] ; then
+			for gUser in `echo $gUsers | sed 's|,| |g'`
+			do
+				pw groupshow ${gName} | grep -qw ${gUser}
+				if [ $? -ne 0 ] ; then
+					# Are we installing as root?
+					if [ "$runUID" != "0" ] ; then
+						echo "Please add user \"$gUser\" to group \"$gName\" manually or re-install PBI as root."
+						continue
+					fi
+
+					echo "Adding user ${gUser} to group ${gName}"
+					pw groupmod ${gName} -m ${gUser}
+				fi
+			done
+		fi
+	done < ${PBI_PROGDIRPATH}/${PBI_INS_GROUPSFILE}
+}
+
+# Check for any UIDs we need to create
+pbi_add_check_uids() {
+	if [ ! -e "${PBI_PROGDIRPATH}/${PBI_INS_USERSFILE}" ] ; then return ; fi
+	runUID=`id -u`
+
+	while read uidLine
+	do
+		uName=`echo $uidLine | cut -d ':' -f 1`
+
+		# Is this user already on the system?
+		pw usershow $uName >/dev/null 2>/dev/null
+		if [ $? -eq 0 ] ; then echo "Using existing user: $uName"; continue ; fi
+
+		# Are we installing as root?
+		if [ "$runUID" != "0" ] ; then
+			echo "Please create user \"$uName\" manually or re-install PBI as root."
+			continue
+		fi
+
+		uID=`echo $uidLine | cut -d ':' -f 3`
+		gID=`echo $uidLine | cut -d ':' -f 4`
+		uClass=`echo $uidLine | cut -d ':' -f 5`
+		uGecos=`echo $uidLine | cut -d ':' -f 8`
+		uHomedir=`echo $uidLine | cut -d ':' -f 9 | sed "s|^/usr/local|${PBI_PROGDIRPATH}|"`
+		uShell=`echo $uidLine | cut -d ':' -f 10`
+
+		echo "Adding user: $uName"
+		pw useradd $uName -u $uID -g $gID $uClass -c "$uGecos" -d $uHomedir -s $uShell;
+
+		# Create homedir
+		case $uHomedir in 
+			/nonexistent|/var/empty) ;; 
+			*) install -d -g $gID -o $uID $uHomedir ;;
+		esac 
+	done < ${PBI_PROGDIRPATH}/${PBI_INS_USERSFILE}
+}
+
 add_hashdir_trigger() {
 	get_dbdir
         _htrig=`echo ${APPDBDIR} | sed "s|${PBI_DBAPPDIR}|${PBI_DBHASHQUEUEDIR}|g"`
-	touch "${_htrig}"
+	if [ ! -e "${_htrig}" ] ; then
+		touch "${_htrig}"
+	fi
 }
 
 # Run the install script if exists
@@ -6120,6 +6210,10 @@
   	# See if we need to run a post make script
   	run_pbi_postportmake
 
+	# Check for any users / groups we need to save for install time
+	mk_pbi_users_file
+	mk_pbi_groups_file
+
 	# Auto-generate a external_links directive from plist info
 	mk_auto_ext_linksfile
 
@@ -6138,6 +6232,48 @@
 	exit 0
 }
 
+# Check if we need to save a list of GROUPS to create at install
+mk_pbi_groups_file()
+{
+	if [ -z "$PBI_BUILD_GROUPS" ] ; then return ; fi
+
+	for group in $PBI_BUILD_GROUPS
+	do
+		# Check /usr/ports/GIDs for group entry
+		gidLine=`cat /usr/ports/GIDs | grep "^$group:"`
+		if [ -z "$gidLine" ] ; then
+			echo "Warning: No entry for \"$group\" in GIDs file..."
+			continue
+		fi
+		grep -q "^$group:" ${PBI_PROGDIRPATH}/${PBI_INS_GROUPSFILE} 2>/dev/null
+		if [ $? -ne 0 ] ; then
+			echo "Saving gid details for group: $group"
+			echo "$gidLine" >> ${PBI_PROGDIRPATH}/${PBI_INS_GROUPSFILE}
+		fi
+	done
+}
+
+# Check if we need to save a list of users to create at install
+mk_pbi_users_file()
+{
+	if [ -z "$PBI_BUILD_USERS" ] ; then return ; fi
+
+	for user in $PBI_BUILD_USERS
+	do
+		# Check /usr/ports/UIDs for user entry
+		uidLine=`cat /usr/ports/UIDs | grep "^$user:"`
+		if [ -z "$uidLine" ] ; then
+			echo "Warning: No entry for \"$user\" in UIDs file..."
+			continue
+		fi
+		grep -q "^$user:" ${PBI_PROGDIRPATH}/${PBI_INS_USERSFILE} 2>/dev/null
+		if [ $? -ne 0 ] ; then
+			echo "Saving uid details for user: $user"
+			echo "$uidLine" >> ${PBI_PROGDIRPATH}/${PBI_INS_USERSFILE}
+		fi
+	done
+}
+
 # Source any pre-build script to allow a custom script to modify the port
 start_prebuild_script()
 {
@@ -6653,6 +6789,16 @@
   local pkgName=`make -V PKGNAME -C $_lPort`
   if [ -e "/var/db/pkg/${pkgName}" ] ; then return ; fi
 
+  # Save any users / groups we need to create later
+  local pUsers="`make -V USERS -C $_lPort`"
+  local pGroups="`make -V GROUPS -C $_lPort`"
+  if [ -n "$pUsers" ] ; then
+     PBI_BUILD_USERS="$PBI_BUILD_USERS $pUsers"
+  fi
+  if [ -n "$pGroups" ] ; then
+     PBI_BUILD_GROUPS="$PBI_BUILD_GROUPS $pGroups"
+  fi
+
   # Parse the deps 
   local TMPFILE=`mktemp /tmp/deplist.XXXXXXXX`
   make all-depends-list -C $_lPort >$TMPFILE



More information about the Commits mailing list