-
Notifications
You must be signed in to change notification settings - Fork 19
Improve install/uninstall scripts for non-root #50
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
Open
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3804c84
feat: improve install and uninstall scripts so that it is easier to h...
Barbiero 1b255df
feat: improve install spinner and use braille patterns
Barbiero 4224883
chore: simplify elevated variables
Barbiero 281c864
feat: ensure symlink dir exists
Barbiero 45f2d01
feat: remove phpctl.dev references
Barbiero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
.editorconfig
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [*.sh] | ||
| charset = utf-8 | ||
| trim_trailing_whitespace = true | ||
| indent_size = 4 | ||
| indent_style = space |
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
2 changes: 1 addition & 1 deletion
docs/_config.yml
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
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
204 changes: 179 additions & 25 deletions
docs/install.sh
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,200 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| INSTALL_DIR=~/.phpctl | ||
| if [ -z "1ドル" ]; then | ||
| SUDO=sudo | ||
| SYMLINK_DIR=/usr/local/bin | ||
| set_colors() { | ||
| # Initialize colors (if available) | ||
| if tput setaf 1 &>/dev/null; then | ||
| RED=$(tput setaf 1) | ||
| GREEN=$(tput setaf 2) | ||
| YELLOW=$(tput setaf 3) | ||
| BLUE=$(tput setaf 4) | ||
| NC=$(tput sgr0) # Reset attributes | ||
|
|
||
| TPUT_AVAILABLE=true | ||
| else | ||
| RED='033円[0;31m' | ||
| GREEN='033円[0;32m' | ||
| YELLOW='033円[0;33m' | ||
| BLUE='033円[0;34m' | ||
| NC='033円[0m' # No Color | ||
|
|
||
| TPUT_AVAILABLE=false | ||
| fi | ||
| } | ||
|
|
||
| ensure_dir() { | ||
| if [[ -e "${SYMLINK_DIR}" ]]; then | ||
| if [[ ! -d "${SYMLINK_DIR}" ]]; then | ||
| echo "${RED}Error: ${SYMLINK_DIR} exists but is not a directory. Please remove it or choose a different path.${NC}" | ||
| exit 1 | ||
| fi | ||
| return | ||
| fi | ||
|
|
||
| if [[ ! -d ${SYMLINK_DIR} ]]; then | ||
| echo "${YELLOW}$SYMLINK_DIR does not exist and will be created.${NC}" | ||
| mkdir -p "${SYMLINK_DIR}" 2>/dev/null | ||
| local success=$? | ||
|
|
||
| if [[ $success != 0 ]]; then | ||
| echo -e -n "${RED}Could not create $SYMLINK_DIR. Exit status: ${success}.${NC} Try again with sudo? (Y/n) " | ||
| read -r answer | ||
| if [ "$answer" != "${answer#[Nn]}" ]; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| sudo mkdir -p "${SYMLINK_DIR}" 2>/dev/null | ||
| success=$? | ||
| if [[ -n $success ]]; then | ||
| echo -e -n "${RED}Could not create $SYMLINK_DIR. Exit status: ${success}.${NC}" | ||
| exit ${success} | ||
| fi | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
| INSTALL_DIR="${HOME}/.phpctl" | ||
| SYMLINK_DIR="/usr/local/bin" | ||
| LOCAL_SOURCES_DIR="" | ||
|
|
||
| # --- Option Parsing --- | ||
| while getopts "hi:s:l:" opt; do | ||
| case $opt in | ||
| h) | ||
| echo "Install phpctl sources and creates symlinks for easy usage." | ||
| echo "" | ||
| echo "Usage: 0ドル [OPTIONS]" | ||
| echo "Options:" | ||
| echo " -h Display this help message and exit" | ||
| echo " -i <directory> Set the installation directory (default: $HOME/.phpctl)" | ||
| echo " -s <directory> Set the symlink directory (default: /usr/local/bin)" | ||
| echo " -l <directory> Set the local sources directory. If empty, will fetch sources from github. (default: empty string)" | ||
| exit 0 | ||
| ;; | ||
| i) | ||
| INSTALL_DIR="$OPTARG" | ||
| ;; | ||
| s) | ||
| SYMLINK_DIR="$OPTARG" | ||
| ;; | ||
| l) | ||
| LOCAL_SOURCES_DIR="$OPTARG" | ||
| ;; | ||
| \?) | ||
| echo "Error: Invalid option: -$OPTARG" >&2 | ||
| echo "Try '0ドル -h' for more information." >&2 | ||
| exit 1 | ||
| ;; | ||
| :) | ||
| echo "Error: Option -$OPTARG requires an argument." >&2 | ||
| echo "Try '0ドル -h' for more information." >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| set_colors | ||
|
|
||
| # Shift off the options and their arguments, so that any remaining | ||
| # positional parameters (if any) are correctly handled. | ||
| shift $((OPTIND - 1)) | ||
|
|
||
| # Compatibility with previous script version | ||
| if [[ $SYMLINK_DIR = "/usr/local/bin" && -n ${1} ]]; then | ||
| SYMLINK_DIR=1ドル | ||
| fi | ||
|
|
||
| ensure_dir | ||
|
|
||
| if [[ ! -w "${SYMLINK_DIR}" ]]; then | ||
| SUDO="sudo" | ||
| else | ||
| SUDO="" | ||
| SYMLINK_DIR=1ドル | ||
| fi | ||
|
|
||
| echo -e "033円[0;33mInstalling phpctl at 033円[0m$INSTALL_DIR" | ||
| if [ -d "$INSTALL_DIR" ]; then | ||
| echo "The install directory is not empty. Attempting to remove it..." | ||
| rm -rf $INSTALL_DIR | ||
| if [[ -n $SUDO ]]; then | ||
| echo "Running in elevated mode. This might require sudo for operations in ${SYMLINK_DIR}." | ||
| fi | ||
|
|
||
| echo -n "" | ||
| git clone --quiet https://github.com/opencodeco/phpctl.git $INSTALL_DIR & | ||
| PID=$! | ||
| while kill -0 $PID 2> /dev/null; do | ||
| for CHAR in '-' '/' '|' '\'; do | ||
| printf "\b$CHAR" | ||
| spinner() { | ||
| local i=0 | ||
| local sp="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏" | ||
| while true; do | ||
| printf "\r[%s] Cloning repository..." "${sp:i++%${#sp}:1}" | ||
| sleep 0.1 | ||
| done | ||
| done | ||
| printf "\r" | ||
| } | ||
|
|
||
| cleanup() { | ||
| if [[ -n "$SPINNER_PID" ]]; then | ||
| kill "$SPINNER_PID" 2>/dev/null | ||
| if $TPUT_AVAILABLE; then | ||
| printf "\r%*s\r" "$(tput cols)" "" | ||
| else | ||
| printf "\r033円[2K" | ||
| fi | ||
| fi | ||
| exit | ||
| } | ||
|
|
||
| if [ -z "1ドル" ]; then | ||
| echo -n "Sudo will be prompted to symlink the phpctl files." | ||
| else | ||
| echo -n "Files will be symlinked to ${SYMLINK_DIR}." | ||
| install_sources() { | ||
| echo -e "${YELLOW}Installing phpctl at ${NC}$INSTALL_DIR" | ||
| if [ -d "$INSTALL_DIR" ]; then | ||
| echo "The install directory is not empty. Attempting to remove it..." | ||
| rm -rf "$INSTALL_DIR" | ||
| fi | ||
|
|
||
| if [[ -n "$LOCAL_SOURCES_DIR" ]]; then | ||
| echo "Using local sources from: $LOCAL_SOURCES_DIR" | ||
| cp -r "$LOCAL_SOURCES_DIR" "$INSTALL_DIR" | ||
| else | ||
| GITHUB_REPO="https://github.com/opencodeco/phpctl.git" | ||
|
|
||
| trap cleanup EXIT INT TERM | ||
|
|
||
| spinner & | ||
| SPINNER_PID=$! | ||
| git clone --quiet "$GITHUB_REPO" "$INSTALL_DIR" & | ||
| PID=$! | ||
| wait "$PID" | ||
| _git_status=$? | ||
|
|
||
| kill "$SPINNER_PID" 2>/dev/null | ||
| # clear the spinner line one last time | ||
| if $TPUT_AVAILABLE; then | ||
| printf "\r%*s\r" "$(tput cols)" "" | ||
| else | ||
| printf "\r033円[2K" | ||
| fi | ||
|
|
||
| if [[ $_git_status -eq 0 ]]; then | ||
| echo "done." | ||
| else | ||
| echo "Failed to clone $GITHUB_REPO into $INSTALL_DIR." | ||
| echo "Error: git clone failed with status ${_git_status}" | ||
| exit 1 | ||
| fi | ||
| fi | ||
| echo "${GREEN}Success: ${NC}Operation completed successfully." | ||
| } | ||
|
|
||
| install_sources | ||
|
|
||
| echo -n "Files will be symlinked to ${SYMLINK_DIR}." | ||
| if [[ -n $SUDO ]]; then | ||
| echo -n " ${RED}Sudo will be prompted to symlink the phpctl files.${NC}" | ||
| fi | ||
| echo -e -n " 033円[0;32mDo you want to continue? (Y/n)033円[0m " | ||
|
|
||
| echo -e -n " ${GREEN}Do you want to continue? (Y/n)${NC} " | ||
| read -r answer | ||
| if [ "$answer" != "${answer#[Nn]}" ]; then | ||
| echo -e "033円[0;31mTo use phpctl globally, link the cloned script to your bin directory, like:033円[0m" | ||
| echo "" | ||
| echo -e "${RED}To use phpctl globally, link the cloned script to your bin directory, like:${NC}" | ||
| for file in "${INSTALL_DIR}"/bin/*; do | ||
| bin=$(basename "$file") | ||
| echo " ${SUDO} ln -sf ${INSTALL_DIR}/bin/$bin ${SYMLINK_DIR}/$bin" | ||
| done | ||
| echo -e "${YELLOW}Or add ${INSTALL_DIR}/bin to your PATH." | ||
| else | ||
| $SUDO ${INSTALL_DIR}/scripts/symlink-bins.sh${INSTALL_DIR} | ||
| $SUDO "${INSTALL_DIR}/scripts/symlink-bins.sh" "${INSTALL_DIR}" "${SYMLINK_DIR}" | ||
| fi | ||
|
|
||
| echo "${GREEN}Installation complete!${NC}" |
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
7 changes: 6 additions & 1 deletion
scripts/symlink-bins.sh
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| local_bin_path="${2:-/usr/local/bin}" | ||
| # Add a trailing slash if it's missing | ||
| local_bin_path="${local_bin_path%/}/" | ||
|
|
||
| for file in "${1:-.}"/bin/*; do | ||
| ln -sf "$(realpath "$file")" "/usr/local/bin/$(basename "$file")" | ||
| ln -sf "$(realpath "$file")" "${local_bin_path}$(basename "$file")" | ||
| done |
2 changes: 1 addition & 1 deletion
tests/install/docker-entrypoint.sh
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.