Rework compile (#2059)

* Ability to update while we are a regular user.
* Fix to work 'declare -f'
* Add the variables needed at the beginning of the path
* First we need to check the changed files
This commit is contained in:
The-going
2020-06-25 16:23:16 +03:00
committed by GitHub
parent 37ee587662
commit 374ba97eb5

View File

@@ -29,21 +29,35 @@ else
exit 255 exit 255
fi fi
if [[ "${EUID}" == "0" ]] || [[ "${1}" == "vagrant" ]]; then # Add the variables needed at the beginning of the path
: check_args ()
elif [[ "${1}" == docker || "${1}" == dockerpurge || "${1}" == docker-shell ]] && grep -q "$(whoami)" <(getent group docker); then {
: for p in "$@"; do
else
display_alert "This script requires root privileges, trying to use sudo" "" "wrn" case "${p%=*}" in
sudo "${SRC}/compile.sh" "$@" LIB_TAG)
exit $? # Take a variable if the branch exists locally
fi if [ "${p#*=}" == "$(git branch | \
gawk -v b="${p#*=}" '{if ( $NF == b ) {print $NF}}')" ]; then
echo "Setting $p"
eval "$p"
else
echo "Skip $p Set as LIB_TAG=\"\""
eval LIB_TAG=""
fi
;;
esac
done
}
check_args "$@"
update_src() { update_src() {
cd "${SRC}" || exit cd "${SRC}" || exit
if [[ ! -f "${SRC}"/.ignore_changes ]]; then if [[ ! -f "${SRC}"/.ignore_changes ]]; then
echo -e "[\e[0;32m o.k. \x1B[0m] This script will try to update" echo -e "[\e[0;32m o.k. \x1B[0m] This script will try to update"
git pull
CHANGED_FILES=$(git diff --name-only) CHANGED_FILES=$(git diff --name-only)
if [[ -n "${CHANGED_FILES}" ]]; then if [[ -n "${CHANGED_FILES}" ]]; then
echo -e "[\e[0;35m warn \x1B[0m] Can't update since you made changes to: \e[0;32m\n${CHANGED_FILES}\x1B[0m" echo -e "[\e[0;35m warn \x1B[0m] Can't update since you made changes to: \e[0;32m\n${CHANGED_FILES}\x1B[0m"
@@ -62,18 +76,20 @@ update_src() {
done done
else else
git checkout "${LIB_TAG:-master}" git checkout "${LIB_TAG:-master}"
git pull
fi fi
fi fi
} }
TMPFILE=$(mktemp) TMPFILE=$(mktemp)
chmod 644 "${TMPFILE}" chmod 644 "${TMPFILE}"
cat <<EOF >> "${TMPFILE}" {
SRC="${SRC}" echo SRC="$SRC"
LIB_TAG="${LIB_TAG}" echo LIB_TAG="$LIB_TAG"
declare -f update_src declare -f update_src
update_src echo "update_src"
EOF
} > "$TMPFILE"
#do not update/checkout git with root privileges to messup files onwership. #do not update/checkout git with root privileges to messup files onwership.
#due to in docker/VM, we can't su to a normal user, so do not update/checkout git. #due to in docker/VM, we can't su to a normal user, so do not update/checkout git.
@@ -87,6 +103,16 @@ fi
rm "${TMPFILE}" rm "${TMPFILE}"
if [[ "${EUID}" == "0" ]] || [[ "${1}" == "vagrant" ]]; then
:
elif [[ "${1}" == docker || "${1}" == dockerpurge || "${1}" == docker-shell ]] && grep -q "$(whoami)" <(getent group docker); then
:
else
display_alert "This script requires root privileges, trying to use sudo" "" "wrn"
sudo "${SRC}/compile.sh" "$@"
exit $?
fi
# Check for required packages for compiling # Check for required packages for compiling
if [[ -z "$(command -v dialog)" ]]; then if [[ -z "$(command -v dialog)" ]]; then
sudo apt-get update sudo apt-get update