Blame subr.rtl/rtl_install.subr

Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
#
8d7a8a
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 LucĂ­a Andrea Illanes Albornoz <lucia@luciaillanes.de>
Lucio Andrés Illanes Albornoz e1d469
# set +o errexit -o noglob -o nounset is assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
#
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
131fe2
#
131fe2
# rtl_install() - install files
131fe2
# @[-v]:	increase verbosity
131fe2
# @_prefix:	installation prefix pathname
131fe2
# @...:		install operation (one of: -* (remove,) !*=* (move/rename,) /=* (create directory/ies,) @*=* (create/update symbolic link,) m[0-7][0-7][0-7][0-7]=* (set mode bits,) o*=* (set user/group owner,) *=* (copy))
131fe2
#
131fe2
# Returns:	zero (0) on success, non-zero (>0) on failure
131fe2
#
Lucio Andrés Illanes Albornoz c6d6e0
rtl_install() {
e9fa07
	local	_ri_verbose="" _ri_prefix=""							\
e9fa07
		_ri_chmod_mode="" _ri_dname="" _ri_file_fname_dst="" _ri_file_fname_src=""	\
e9fa07
		_ri_fname="" _ri_ln_fname="" _ri_ln_target="" _ri_owner_spec="" _ri_pname="";
e9fa07
e9fa07
	if [ "${1}" = "-v" ]; then
e9fa07
	       _ri_verbose=1; shift;
e9fa07
	fi;
e9fa07
	_ri_prefix="${1}"; shift;
Lucio Andrés Illanes Albornoz e1a474
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	case "${1}" in
e9fa07
Lucio Andrés Illanes Albornoz e1a474
	-*)
e9fa07
		_ri_pname="${1#-}";
e9fa07
		if [ "${_ri_pname#/}" = "${_ri_pname}" ]; then
e9fa07
			_ri_pname="${_ri_prefix:+${_ri_prefix}/}${_ri_pname}";
Lucio Andrés Illanes Albornoz e1a474
		fi;
e9fa07
		if ! rtl_fileop rm "${_ri_pname}"; then
Lucio Andrés Illanes Albornoz e1a474
			return 1;
Lucio Andrés Illanes Albornoz e1a474
		fi; ;;
Lucio Andrés Illanes Albornoz e1a474
Lucio Andrés Illanes Albornoz e1a474
	!*=*)
e9fa07
		_ri_file_fname_src="${1#!}"; _ri_file_fname_src="${_ri_file_fname_src%=*}";
e9fa07
	       	_ri_file_fname_dst="${1#!}"; _ri_file_fname_dst="${_ri_file_fname_dst#*=}";
e9fa07
		if [ "${_ri_file_fname_src#/}" = "${_ri_file_fname_src}" ]; then
e9fa07
			_ri_file_fname_src="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_src}";
Lucio Andrés Illanes Albornoz e1a474
		fi;
e9fa07
		if [ "${_ri_file_fname_dst#/}" = "${_ri_file_fname_dst}" ]; then
e9fa07
			_ri_file_fname_dst="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_dst}";
Lucio Andrés Illanes Albornoz e1a474
		fi;
e9fa07
		if ! rtl_fileop mv "${_ri_file_fname_src}" "${_ri_file_fname_dst}"; then
Lucio Andrés Illanes Albornoz e1a474
			return 1;
Lucio Andrés Illanes Albornoz e1a474
		fi; ;;
Lucio Andrés Illanes Albornoz e1a474
Lucio Andrés Illanes Albornoz e1a474
	/=*)
e9fa07
		_ri_dname="${1#/=}";
e9fa07
		if [ "${_ri_dname#/}" = "${_ri_dname}" ]; then
e9fa07
			_ri_dname="${_ri_prefix:+${_ri_prefix}/}${_ri_dname}";
Lucio Andrés Illanes Albornoz e1a474
		fi;
e9fa07
		if ! rtl_fileop mkdir "${_ri_dname}"; then
Lucio Andrés Illanes Albornoz e1a474
			return 1;
Lucio Andrés Illanes Albornoz e1a474
		fi; ;;
Lucio Andrés Illanes Albornoz e1a474
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	@*=*)
e9fa07
		_ri_ln_target="${1%=*}"; _ri_ln_target="${_ri_ln_target#@}"; _ri_ln_fname="${1#*=}";
e9fa07
		if [ "${_ri_ln_fname#/}" = "${_ri_ln_fname}" ]; then
e9fa07
			_ri_ln_fname="${_ri_prefix:+${_ri_prefix}/}${_ri_ln_fname}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		fi;
e9fa07
		if [ -e "${_ri_ln_fname}" ]; then
e9fa07
			rtl_fileop rm "${_ri_ln_fname}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		fi;
e9fa07
		if ! rtl_fileop ln_symbolic "${_ri_ln_target}" "${_ri_ln_fname}"; then
Lucio Andrés Illanes Albornoz 7bfc1e
			return 1;
Lucio Andrés Illanes Albornoz e1a474
		fi; ;;
Lucio Andrés Illanes Albornoz e1a474
Lucio Andrés Illanes Albornoz e1a474
	m[0-7][0-7][0-7][0-7]=*)
e9fa07
		_ri_fname="${1#m[0-7][0-7][0-7][0-7]=}"; _ri_chmod_mode="${1%%=*}"; _ri_chmod_mode="${_ri_chmod_mode#m}";
e9fa07
		if ! rtl_fileop chmod "${_ri_chmod_mode}" "${_ri_fname}"; then
Lucio Andrés Illanes Albornoz 7bfc1e
			return 1;
Lucio Andrés Illanes Albornoz e1a474
		fi; ;;
Lucio Andrés Illanes Albornoz e1a474
Lucio Andrés Illanes Albornoz e1a474
	o*=*)
e9fa07
		_ri_fname="${1#o*=}"; _ri_owner_spec="${1%%=*}"; _ri_owner_spec="${_ri_owner_spec#o}";
e9fa07
		if ! rtl_fileop chown "${_ri_owner_spec}" "${_ri_fname}"; then
Lucio Andrés Illanes Albornoz e1a474
			return 1;
Lucio Andrés Illanes Albornoz e1a474
		fi; ;;
Lucio Andrés Illanes Albornoz e1a474
Lucio Andrés Illanes Albornoz e1a474
	*=*)
e9fa07
		_ri_file_fname_src="${1%=*}"; _ri_file_fname_dst="${1#*=}";
e9fa07
		if [ "${_ri_file_fname_src#/}" = "${_ri_file_fname_src}" ]; then
e9fa07
			_ri_file_fname_src="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_src}";
Lucio Andrés Illanes Albornoz (arab, vxp) 9f270b
		fi;
e9fa07
		if [ "${_ri_file_fname_dst#/}" = "${_ri_file_fname_dst}" ]; then
e9fa07
			_ri_file_fname_dst="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_dst}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		fi;
e9fa07
		if ! rtl_fileop cp "${_ri_file_fname_src}" "${_ri_file_fname_dst}"; then
Lucio Andrés Illanes Albornoz 7bfc1e
			return 1;
Lucio Andrés Illanes Albornoz e1a474
		fi; ;;
e9fa07
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	esac; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	done;
e9fa07
e9fa07
	return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
};
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
64844b
# vim:filetype=sh textwidth=0