Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install-template.sh: speed up this script by reducing # of forks. #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 52 additions & 58 deletions install-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ uninstall_components() {
local _directive
while read _directive; do

local _command=`echo $_directive | cut -f1 -d:`
local _file=`echo $_directive | cut -f2 -d:`
local _command=${_directive%%:*}
local _file=${_directive#*:}

# Sanity checks
if [ ! -n "$_command" ]; then critical_err "malformed installation directive"; fi
Expand Down Expand Up @@ -549,8 +549,8 @@ install_components() {
local _directive
while read _directive; do

local _command=`echo $_directive | cut -f1 -d:`
local _file=`echo $_directive | cut -f2 -d:`
local _command=${_directive%%:*}
local _file=${_directive#*:}

# Sanity checks
if [ ! -n "$_command" ]; then critical_err "malformed installation directive"; fi
Expand All @@ -559,54 +559,45 @@ install_components() {
# Decide the destination of the file
local _file_install_path="$_dest_prefix/$_file"

if echo "$_file" | grep "^etc/" > /dev/null
then
local _f="$(echo "$_file" | sed 's/^etc\///')"
_file_install_path="$CFG_SYSCONFDIR/$_f"
fi

if echo "$_file" | grep "^bin/" > /dev/null
then
local _f="$(echo "$_file" | sed 's/^bin\///')"
_file_install_path="$CFG_BINDIR/$_f"
fi

if echo "$_file" | grep "^lib/" > /dev/null
then
local _f="$(echo "$_file" | sed 's/^lib\///')"
_file_install_path="$CFG_LIBDIR/$_f"
fi

if echo "$_file" | grep "^share" > /dev/null
then
local _f="$(echo "$_file" | sed 's/^share\///')"
_file_install_path="$CFG_DATADIR/$_f"
fi

if echo "$_file" | grep "^share/man/" > /dev/null
then
local _f="$(echo "$_file" | sed 's/^share\/man\///')"
_file_install_path="$CFG_MANDIR/$_f"
fi
case "$_file" in
etc/*)
local _f=${_file#"etc/"}
_file_install_path="$CFG_SYSCONFDIR/$_f"
;;
bin/*)
local _f=${_file#"bin/"}
_file_install_path="$CFG_BINDIR/$_f"
;;
lib/*)
local _f=${_file#"lib/"}
_file_install_path="$CFG_LIBDIR/$_f"
;;
share/man/*)
local _f=${_file#"share/man/"}
_file_install_path="$CFG_MANDIR/$_f"
;;
share/doc/*)
# HACK: Try to support overriding --docdir. Paths with the form
# "share/doc/$product/" can be redirected to a single --docdir
# path. If the following detects that --docdir has been specified
# then it will replace everything preceeding the "$product" path
# component. The problem here is that the combined rust installer
# contains two "products": rust and cargo; so the contents of those
# directories will both be dumped into the same directory; and the
# contents of those directories are _not_ disjoint. Since this feature
# is almost entirely to support 'make install' anyway I don't expect
# this problem to be a big deal in practice.
if [ "$CFG_DOCDIR" != "<default>" ]; then
local _f=${_file#"share/doc/"}
_file_install_path="$CFG_DOCDIR/$_f"
fi
;;
share/*)
local _f=${_file#"share/"}
_file_install_path="$CFG_DATADIR/$_f"
;;
esac

# HACK: Try to support overriding --docdir. Paths with the form
# "share/doc/$product/" can be redirected to a single --docdir
# path. If the following detects that --docdir has been specified
# then it will replace everything preceeding the "$product" path
# component. The problem here is that the combined rust installer
# contains two "products": rust and cargo; so the contents of those
# directories will both be dumped into the same directory; and the
# contents of those directories are _not_ disjoint. Since this feature
# is almost entirely to support 'make install' anyway I don't expect
# this problem to be a big deal in practice.
if [ "$CFG_DOCDIR" != "<default>" ]
then
if echo "$_file" | grep "^share/doc/" > /dev/null
then
local _f="$(echo "$_file" | sed 's/^share\/doc\/[^/]*\///')"
_file_install_path="$CFG_DOCDIR/$_f"
fi
fi

# Make sure there's a directory for it
make_dir_recursive "$(dirname "$_file_install_path")"
Expand All @@ -625,15 +616,18 @@ install_components() {

maybe_backup_path "$_file_install_path"

if echo "$_file" | grep "^bin/" > /dev/null || test -x "$_src_dir/$_component/$_file"
then
run cp "$_src_dir/$_component/$_file" "$_file_install_path"
run chmod 755 "$_file_install_path"
else
run cp "$_src_dir/$_component/$_file" "$_file_install_path"
run chmod 644 "$_file_install_path"
local mode=644
if test -x "$_src_dir/$_component/$_file"; then
mode=755
fi
case "$_file" in
bin/*) mode=755
;;
esac
run cp "$_src_dir/$_component/$_file" "$_file_install_path"
critical_need_ok "file creation failed"
run chmod $mode "$_file_install_path"
critical_need_ok "failed to set permissions on file"

# Update the manifest
append_to_file "file:$_file_install_path" "$_installed_manifest"
Expand Down