jordanhillis/pvekclean

Simplify use by direct download and execute

ptr727 opened this issue · 6 comments

ptr727 commented

The installation instructions call for using git, and the update instructions say to repeat install, but with git that is really not repeat, it would be a git pull, which is not quite the same.

Suggest as alternative instructions to execute script directly using e.g.
wget -O - https://raw.githubusercontent.com/jordanhillis/pvekclean/master/pvekclean.sh | bash -s arg1 arg2

The installation instructions call for using git, and the update instructions say to repeat install, but with git that is really not repeat, it would be a git pull, which is not quite the same.

Suggest as alternative instructions to execute script directly using e.g.

wget -O - https://raw.githubusercontent.com/jordanhillis/pvekclean/master/pvekclean.sh | bash -s arg1 arg2

The update instruction listed on the readme are old and I will have to change that. The new way to update is to simply run pvekclean and it will automatically look for updates. If it finds a new update it gives you the option to update right from the command line with a simply "y". Let me know if you have any further questions!

ptr727 commented

I assume (I did not look at code) that only works when Can we install PVE Kernel Cleaner to your /usr/local/sbin for easier access [y/N] n installing, else git pull would bring in the updated version, and changing the version in the git folder would create an inconsistency?

I assume (I did not look at code) that only works when Can we install PVE Kernel Cleaner to your /usr/local/sbin for easier access [y/N] n installing, else git pull would bring in the updated version, and changing the version in the git folder would create an inconsistency?

The update can be applied even if it isn't installed to the /usr/local/sbin. It will update the file you executed so if that's pvekclean.sh inside a folder somewhere it will update that or if you ran /usr/local/sbin/pvekclean it will update that. It does this using curl and checks to ensure the correct #!/bin/bash is the first line before applying the update to the file to avoid scenarios where it failed to retrieve the requested file. I did this instead of git in instances where maybe the user doesn't have git installed for some reason. Curl seems to be more common place on systems.

Does this answer your question? I feel like maybe I am misunderstanding it 😅 so feel free to ask more questions if need be.

ptr727 commented

If you update files in a git managed folder, the contents of the folder is now out of sync with the upstream. If you change the install instructions to just use wget/curls to get the script, then set +x, then the script can update itself without impacting the git state. So splitting hairs here, but pulling using git should update by pulling from git, not external modification.

# Function to check for updates
check_for_update() {
	if [ "$check_for_updates" == "true" ] && [ "$force_purge" == "false" ]; then
		local remote_version=$(curl -s -m 10 https://raw.githubusercontent.com/jordanhillis/pvekclean/master/version.txt || echo "")
		# Unable to fetch remote version, so just skip the update check
		if [ -z "$remote_version" ]; then
			printf "${bold}[*]${reset} Failed to check for updates. Skipping update check.\n"
			return
		fi
		if [ "$remote_version" != "$version" ]; then
			printf "*** A new version $remote_version is available! ***\n"
			printf "${bold}[*]${reset} Do you want to update? [y/N] "
			read -n 1 -r
			printf "\n"
			if [[ $REPLY =~ ^[Yy]$ ]]; then
				local updated_script=$(curl -s -m 10 https://raw.githubusercontent.com/jordanhillis/pvekclean/master/pvekclean.sh)
				# Check if the updated script contains the shebang line
				if [[ "$updated_script" == "#!/bin/bash"* ]]; then
					echo "$updated_script" > "$0"  # Overwrite the current script
					printf "${bold}[*]${reset} Successfully updated to version $remote_version\n"
					exec "$0" "$@"
				else
					printf "${bold}[*]${reset} The updated script does not contain the expected shebang line.\n"
					printf "${bold}[*]${reset} Update aborted!\n"
				fi
			fi
		fi
	fi
}

This is the update function within the script that checks for updates on the version.txt. If it finds an update it asks the user if they want to install this update. If they select "y" it will grab the latest version of pvekclean.sh from the repo and overwrite whatever file they are using (could be any path or name) with the source code from this.

ptr727 commented

If you overwrite the file as part of an update, then using git to install is not appropriate.