galeb

Једноставна статичка дистрибуција заснована на musl-у
git clone https://git.sr.ht/~strahinja/galeb
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

createdirs (1634B)


      1 #!/bin/sh
      2 
      3 . ./lib/env.sh
      4 . ./lib/fun.sh
      5 
      6 dirdb=./lib/dirs.tsv
      7 currentstep=$1
      8 
      9 startuid=$(id -u)
     10 
     11 recno=0
     12 IFS=$(printf '\n')
     13 while read -r record
     14 do
     15 	recno=$((recno+1))
     16 
     17 	if [ "${recno}" -eq 1 ]; then
     18 		continue
     19 	fi
     20 
     21 	path=$(printf "${record}"	| cut -d  "$(printf '\t')" -f1)
     22 	mode=$(printf "${record}"	| cut -sd "$(printf '\t')" -f2)
     23 	owner=$(printf "${record}"	| cut -sd "$(printf '\t')" -f3)
     24 	group=$(printf "${record}"	| cut -sd "$(printf '\t')" -f4)
     25 	step=$(printf "${record}"	| cut -sd "$(printf '\t')" -f5)
     26 
     27 	ownerid=''
     28 	if [ -n "${owner}" ]; then
     29 		if [ -e ${GR}/etc/passwd ]; then
     30 			ownerid=$(grep "^${owner}:" ${GR}/etc/passwd | \
     31 				cut -d: -f3)
     32 		else
     33 			ownerid=0	# fallback
     34 		fi
     35 	fi
     36 
     37 	groupid=''
     38 	if [ -n "${group}" ]; then
     39 		if [ -e ${GR}/etc/group ]; then
     40 			groupid=$(grep "^${owner}:" ${GR}/etc/group | \
     41 				cut -d: -f3)
     42 		else
     43 			groupid=0	# fallback
     44 		fi
     45 	fi
     46 
     47 	# If no step was passed, do all
     48 	if [ -n "${currentstep}" ] && \
     49 		! { echo "${step}" | grep "${currentstep}" >/dev/null 2>&1; }
     50 	then
     51 		continue
     52 	fi
     53 
     54 	if [ -z "${path}" ]; then
     55 		msg warn "Empty path at record #%d; skipping" "${recno}"
     56 		continue
     57 	fi
     58 
     59 	if [ ! -d "${GR}${path}" ]; then
     60 		msg info "mkdir -p %s" "${GR}${path}"
     61 		mkdir -p "${GR}${path}" || exit 1
     62 	fi
     63 
     64 	if [ "${startuid}" -eq 0 ] &&  [ -n "${mode}" ]; then
     65 		msg info "chmod %s %s" "${mode}" "${GR}${path}"
     66 		chmod "${mode}" "${GR}${path}" || exit 1
     67 	fi
     68 
     69 	if [ "${startuid}" -eq 0 ] &&  [ -n "${owner}" ] && \
     70 		[ -n "${group}" ]; then
     71 		msg info "chown %s:%s %s" "${ownerid}" "${groupid}" \
     72 			"${GR}${path}"
     73 		chown ${ownerid}:${groupid} "${GR}${path}" || exit 1
     74 	fi
     75 done <${dirdb}