Check if we're in git repo during self-update
This commit is contained in:
21
installJRMC
21
installJRMC
@@ -1594,7 +1594,8 @@ update_self() {
|
|||||||
debug "Running: ${FUNCNAME[0]} $*"
|
debug "Running: ${FUNCNAME[0]} $*"
|
||||||
|
|
||||||
local script_url="https://git.bryanroessler.com/bryan/installJRMC/raw/master/installJRMC"
|
local script_url="https://git.bryanroessler.com/bryan/installJRMC/raw/master/installJRMC"
|
||||||
local tmp; tmp=$(mktemp)
|
local tmp
|
||||||
|
tmp=$(mktemp)
|
||||||
|
|
||||||
# Check if we're in a git directory and if it's the installJRMC repository
|
# Check if we're in a git directory and if it's the installJRMC repository
|
||||||
if git rev-parse --is-inside-work-tree &>/dev/null; then
|
if git rev-parse --is-inside-work-tree &>/dev/null; then
|
||||||
@@ -1603,19 +1604,19 @@ update_self() {
|
|||||||
if [[ "$git_remote_url" == *"bryan/installJRMC"* ]]; then
|
if [[ "$git_remote_url" == *"bryan/installJRMC"* ]]; then
|
||||||
echo "installJRMC git repository detected. Running git pull..."
|
echo "installJRMC git repository detected. Running git pull..."
|
||||||
|
|
||||||
# Get the current checksum of the script
|
# Get the current commit hash of the script's directory
|
||||||
declare before_pull_checksum
|
local before_pull_hash
|
||||||
before_pull_checksum=$(git rev-parse HEAD:"$SCRIPT_PATH")
|
before_pull_hash=$(git rev-parse HEAD)
|
||||||
|
|
||||||
# Perform git pull
|
# Perform git pull
|
||||||
git pull || return 1
|
git pull || return 1
|
||||||
|
|
||||||
# Get the new checksum after the pull
|
# Get the new commit hash after the pull
|
||||||
declare after_pull_checksum
|
local after_pull_hash
|
||||||
after_pull_checksum=$(git rev-parse HEAD:"$SCRIPT_PATH")
|
after_pull_hash=$(git rev-parse HEAD)
|
||||||
|
|
||||||
# Check if the script has changed
|
# Check if the commit hash has changed
|
||||||
if [[ "$before_pull_checksum" != "$after_pull_checksum" ]]; then
|
if [[ "$before_pull_hash" != "$after_pull_hash" ]]; then
|
||||||
echo "installJRMC script updated. Restarting script..."
|
echo "installJRMC script updated. Restarting script..."
|
||||||
exec "$SCRIPT_PATH" "$@" "--no-self-update"
|
exec "$SCRIPT_PATH" "$@" "--no-self-update"
|
||||||
else
|
else
|
||||||
@@ -1663,8 +1664,6 @@ update_self() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
debug "Running: ${FUNCNAME[0]} $*"
|
debug "Running: ${FUNCNAME[0]} $*"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user