Last active
September 26, 2021 15:50
-
-
Save SomajitDey/49020a74635914f402c829b79b746a16 to your computer and use it in GitHub Desktop.
Install files locally. Download and install: chmod +x linstall; ./linstall linstall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Brief: Install locally without sudo | |
| # Usage: install [file-path or download-link] | |
| file="${@}" | |
| [[ -n "${file}" ]] || read -rep'Drag-n-drop file or put download link here: ' file | |
| file="${file/#\"/}" ; file="${file/%\"/}" # Quote (") removal, if any | |
| if [[ "${file}" =~ ^http[s]?://.*$ ]];then | |
| tmp=$(mktemp -d .linstallXXXXX); trap "rm -rf ${tmp}" exit | |
| (cd "${tmp}" ; curl -sfSLNO "${file}") || exit 1 | |
| file="${tmp}/$(ls ${tmp})" | |
| else | |
| convert="$(wslpath "${file}" 2>/dev/null)" | |
| file="${convert:-"${file}"}" | |
| file="${file/#~\//${HOME}\/}" # Tilde expansion | |
| file="${file/#~-\//${OLDPWD}\/}" # Tilde expansion | |
| fi | |
| [[ -f "${file}" ]] || { echo "File: ${file} doesn't exist" >&2; exit 1;} | |
| chmod +x "${file}" || exit 1 | |
| dest="${HOME}/.bin" | |
| cmd="export PATH=\"\${PATH}:${dest}\"" | |
| mkdir -p "${dest}" | |
| read -rep 'Install as what? Ans: ' -i "${file##*/}" install_as | |
| cp -i "${file}" "${dest}/${install_as}" &&\ | |
| (grep -q "^${cmd}" "${HOME}/.bashrc" || echo "${cmd}" >> "${HOME}/.bashrc") && eval "${cmd}" && \ | |
| echo "${install_as} installed locally" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment