mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-05-11 05:55:37 +00:00
tools/install: support "--prefix" for the system-wide installation
This commit is contained in:
10
README.md
10
README.md
@@ -134,6 +134,16 @@ the default shell, and also won't run `bash` when the installation has finished.
|
|||||||
bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)" --unattended
|
bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)" --unattended
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### System-wide installation
|
||||||
|
|
||||||
|
For example, Oh My Bash can be installed to `/usr/local/share/oh-my-bash` for the system-wide installation by specifying the option `--prefix=PATH`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)" --prefix=/usr/local
|
||||||
|
```
|
||||||
|
|
||||||
|
The Bash startup file `.bashrc` needs to be manually set up by each user.
|
||||||
|
|
||||||
#### Manual Installation
|
#### Manual Installation
|
||||||
|
|
||||||
##### 1. Clone the repository:
|
##### 1. Clone the repository:
|
||||||
|
@@ -34,11 +34,19 @@ fi
|
|||||||
|
|
||||||
# Set OSH_CUSTOM to the path where your custom config files
|
# Set OSH_CUSTOM to the path where your custom config files
|
||||||
# and plugins exists, or else we will use the default custom/
|
# and plugins exists, or else we will use the default custom/
|
||||||
: "${OSH_CUSTOM:=$OSH/custom}"
|
if [[ ! ${OSH_CUSTOM-} ]]; then
|
||||||
|
OSH_CUSTOM=$OSH/custom
|
||||||
|
[[ -d $OSH_CUSTOM && -O $OSH_CUSTOM ]] ||
|
||||||
|
OSH_CUSTOM=${XDG_DATA_HOME:-$HOME/.local/share}/oh-my-bash/custom
|
||||||
|
fi
|
||||||
|
|
||||||
# Set OSH_CACHE_DIR to the path where cache files should be created
|
# Set OSH_CACHE_DIR to the path where cache files should be created
|
||||||
# or else we will use the default cache/
|
# or else we will use the default cache/
|
||||||
: "${OSH_CACHE_DIR:=$OSH/cache}"
|
if [[ ! ${OSH_CACHE_DIR-} ]]; then
|
||||||
|
OSH_CACHE_DIR=$OSH/cache
|
||||||
|
[[ -d $OSH_CACHE_DIR && -O $OSH_CACHE_DIR ]] ||
|
||||||
|
OSH_CACHE_DIR=${XDG_STATE_HOME:-$HOME/.local/state}/oh-my-bash/cache
|
||||||
|
fi
|
||||||
|
|
||||||
_omb_module_loaded=
|
_omb_module_loaded=
|
||||||
_omb_module_require() {
|
_omb_module_require() {
|
||||||
|
149
tools/install.sh
149
tools/install.sh
@@ -45,14 +45,37 @@ _omb_install_print_help() {
|
|||||||
' --usage show usage' \
|
' --usage show usage' \
|
||||||
' --dry-run do not perform the actual installation' \
|
' --dry-run do not perform the actual installation' \
|
||||||
' --unattended do not fall in to the new Bash session after the install' \
|
' --unattended do not fall in to the new Bash session after the install' \
|
||||||
|
' --prefix=PATH install oh-my-bash into "PATH/share/oh-my-bash"' \
|
||||||
''
|
''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## @fn _omb_install_readargs [options...]
|
||||||
|
## @var[out] install_opts
|
||||||
|
## @var[out] install_prefix
|
||||||
_omb_install_readargs() {
|
_omb_install_readargs() {
|
||||||
|
install_opts=
|
||||||
|
install_prefix=
|
||||||
while (($#)); do
|
while (($#)); do
|
||||||
local arg=$1; shift
|
local arg=$1; shift
|
||||||
if [[ :$install_opts: != *:literal:* ]]; then
|
if [[ :$install_opts: != *:literal:* ]]; then
|
||||||
case $arg in
|
case $arg in
|
||||||
|
--prefix=*)
|
||||||
|
arg=${arg#*=}
|
||||||
|
if [[ $arg ]]; then
|
||||||
|
install_prefix=$arg
|
||||||
|
else
|
||||||
|
install_opts+=:error
|
||||||
|
printf 'install (oh-my-bash): %s\n' "$RED$BOLD[Error]$NORMAL ${RED}the option argument for '--prefix' is empty.$NORMAL" >&2
|
||||||
|
fi
|
||||||
|
continue ;;
|
||||||
|
--prefix)
|
||||||
|
if (($#)); then
|
||||||
|
install_prefix=$1; shift
|
||||||
|
else
|
||||||
|
install_opts+=:error
|
||||||
|
printf 'install (oh-my-bash): %s\n' "$RED$BOLD[Error]$NORMAL ${RED}an option argument for '$arg' is missing.$NORMAL" >&2
|
||||||
|
fi
|
||||||
|
continue ;;
|
||||||
--help | --usage | --unattended | --dry-run)
|
--help | --usage | --unattended | --dry-run)
|
||||||
install_opts+=:${arg#--}
|
install_opts+=:${arg#--}
|
||||||
continue ;;
|
continue ;;
|
||||||
@@ -65,16 +88,16 @@ _omb_install_readargs() {
|
|||||||
-*)
|
-*)
|
||||||
install_opts+=:error
|
install_opts+=:error
|
||||||
if [[ $arg == -[!-]?* ]]; then
|
if [[ $arg == -[!-]?* ]]; then
|
||||||
printf 'install (oh-my-bash): %s\n' "$RED$BOLD[Error]$NORMAL ${RED}unrecognized options '$arg'.$NORMAL"
|
printf 'install (oh-my-bash): %s\n' "$RED$BOLD[Error]$NORMAL ${RED}unrecognized options '$arg'.$NORMAL" >&2
|
||||||
else
|
else
|
||||||
printf 'install (oh-my-bash): %s\n' "$RED$BOLD[Error]$NORMAL ${RED}unrecognized option '$arg'.$NORMAL"
|
printf 'install (oh-my-bash): %s\n' "$RED$BOLD[Error]$NORMAL ${RED}unrecognized option '$arg'.$NORMAL" >&2
|
||||||
fi
|
fi
|
||||||
continue ;;
|
continue ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
install_opts+=:error
|
install_opts+=:error
|
||||||
printf 'install (oh-my-bash): %s\n' "$RED$BOLD[Error]$NORMAL unrecognized argument '$arg'."
|
printf 'install (oh-my-bash): %s\n' "$RED$BOLD[Error]$NORMAL unrecognized argument '$arg'." >&2
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +110,69 @@ _omb_install_run() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_omb_install_banner() {
|
||||||
|
# MOTD message :)
|
||||||
|
printf '%s' "$GREEN"
|
||||||
|
printf '%s\n' \
|
||||||
|
' __ __ __ ' \
|
||||||
|
' ____ / /_ ____ ___ __ __ / /_ ____ ______/ /_ ' \
|
||||||
|
' / __ \/ __ \ / __ `__ \/ / / / / __ \/ __ `/ ___/ __ \' \
|
||||||
|
'/ /_/ / / / / / / / / / / /_/ / / /_/ / /_/ (__ ) / / /' \
|
||||||
|
'\____/_/ /_/ /_/ /_/ /_/\__, / /_.___/\__,_/____/_/ /_/ ' \
|
||||||
|
' /____/ .... is now installed!'
|
||||||
|
printf '%s' "$NORMAL"
|
||||||
|
}
|
||||||
|
|
||||||
|
## @fn _omb_install_user_bashrc
|
||||||
|
## @var[in] install_opts
|
||||||
|
## @var[in] OSH
|
||||||
|
_omb_install_user_bashrc() {
|
||||||
|
printf "${BLUE}Looking for an existing bash config...${NORMAL}\n"
|
||||||
|
if [[ -f ~/.bashrc || -h ~/.bashrc ]]; then
|
||||||
|
local bashrc_backup=~/.bashrc.omb-backup-$(date +%Y%m%d%H%M%S)
|
||||||
|
printf "${YELLOW}Found ~/.bashrc.${NORMAL} ${GREEN}Backing up to $bashrc_backup${NORMAL}\n"
|
||||||
|
_omb_install_run mv ~/.bashrc "$bashrc_backup"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "${BLUE}Using the Oh My Bash template file and adding it to ~/.bashrc${NORMAL}\n"
|
||||||
|
_omb_install_run cp "$OSH"/templates/bashrc.osh-template ~/.bashrc
|
||||||
|
sed "/^export OSH=/ c\\
|
||||||
|
export OSH=$OSH
|
||||||
|
" ~/.bashrc >| ~/.bashrc.omb-temp
|
||||||
|
_omb_install_run mv -f ~/.bashrc.omb-temp ~/.bashrc
|
||||||
|
|
||||||
|
set +e
|
||||||
|
_omb_install_banner
|
||||||
|
printf '%s\n' "${GREEN}Please look over the ~/.bashrc file to select a theme, plugins, completions, aliases, and options${NORMAL}"
|
||||||
|
printf "${BLUE}${BOLD}%s${NORMAL}\n" "To keep up on the latest news and updates, follow us on GitHub: https://github.com/ohmybash/oh-my-bash"
|
||||||
|
|
||||||
|
if [[ :$install_opts: == *:dry-run:* ]]; then
|
||||||
|
printf '%s\n' "$GREEN$BOLD[dryrun]$NORMAL Sample bashrc is created at '$BOLD$HOME/.bashrc-ombtemp$NORMAL'."
|
||||||
|
elif [[ :$install_opts: != *:unattended:* ]]; then
|
||||||
|
if [[ $- == *i* ]]; then
|
||||||
|
# In case install.sh is sourced from the interactive Bash
|
||||||
|
source ~/.bashrc
|
||||||
|
else
|
||||||
|
exec bash
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_omb_install_system_bashrc() {
|
||||||
|
printf "${BLUE}Creating a bashrc template at '$OSH/bashrc'...${NORMAL}\n"
|
||||||
|
local q=\' Q="'\''"
|
||||||
|
local osh="'${OSH//$q/$Q}'"
|
||||||
|
osh=${osh//$'\n'/$'\\\n'}
|
||||||
|
local sed_script='/^export OSH=.*/c \
|
||||||
|
'"export OSH=$osh"
|
||||||
|
_omb_install_run sed "$sed_script" "$OSH"/templates/bashrc.osh-template >| "$OSH"/bashrc
|
||||||
|
|
||||||
|
_omb_install_banner
|
||||||
|
printf '%s\n' "${GREEN}To enable Oh My Bash, please copy '${BOLD}$OSH/bashrc${NORMAL}${GREEN}' to '${BOLD}~/.bashrc${NORMAL}${GREEN}'.${NORMAL}"
|
||||||
|
printf '%s\n' "${GREEN}Please look over the ~/.bashrc file to select a theme, plugins, completions, aliases, and options${NORMAL}"
|
||||||
|
printf "${BLUE}${BOLD}%s${NORMAL}\n" "To keep up on the latest news and updates, follow us on GitHub: https://github.com/ohmybash/oh-my-bash"
|
||||||
|
}
|
||||||
|
|
||||||
_omb_install_main() {
|
_omb_install_main() {
|
||||||
# Use colors, but only if connected to a terminal, and that terminal
|
# Use colors, but only if connected to a terminal, and that terminal
|
||||||
# supports them.
|
# supports them.
|
||||||
@@ -110,7 +196,7 @@ _omb_install_main() {
|
|||||||
local NORMAL=""
|
local NORMAL=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local install_opts=
|
local install_opts install_prefix
|
||||||
_omb_install_readargs "$@"
|
_omb_install_readargs "$@"
|
||||||
|
|
||||||
if [[ :$install_opts: == *:error:* ]]; then
|
if [[ :$install_opts: == *:error:* ]]; then
|
||||||
@@ -136,18 +222,22 @@ _omb_install_main() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $install_prefix ]]; then
|
||||||
|
[[ $install_prefix == /* ]] ||
|
||||||
|
install_prefix=$PWD/$install_prefix
|
||||||
|
local OSH=$install_prefix/share/oh-my-bash
|
||||||
|
elif [[ ! $OSH ]]; then
|
||||||
|
OSH=~/.oh-my-bash
|
||||||
|
fi
|
||||||
|
|
||||||
# Only enable exit-on-error after the non-critical colorization stuff,
|
# Only enable exit-on-error after the non-critical colorization stuff,
|
||||||
# which may fail on systems lacking tput or terminfo
|
# which may fail on systems lacking tput or terminfo
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [[ ! $OSH ]]; then
|
|
||||||
OSH=~/.oh-my-bash
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -d $OSH ]]; then
|
if [[ -d $OSH ]]; then
|
||||||
printf "${YELLOW}You already have Oh My Bash installed.${NORMAL}\n"
|
printf '%s\n' "${YELLOW}You already have Oh My Bash installed.${NORMAL}" >&2
|
||||||
printf "You'll need to remove $OSH if you want to re-install.\n"
|
printf '%s\n' "You'll need to remove '$OSH' if you want to re-install it." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -176,43 +266,10 @@ _omb_install_main() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
printf "${BLUE}Looking for an existing bash config...${NORMAL}\n"
|
if [[ $install_prefix ]]; then
|
||||||
if [[ -f ~/.bashrc || -h ~/.bashrc ]]; then
|
_omb_install_system_bashrc
|
||||||
local bashrc_backup=~/.bashrc.omb-backup-$(date +%Y%m%d%H%M%S)
|
|
||||||
printf "${YELLOW}Found ~/.bashrc.${NORMAL} ${GREEN}Backing up to $bashrc_backup${NORMAL}\n"
|
|
||||||
_omb_install_run mv ~/.bashrc "$bashrc_backup"
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf "${BLUE}Using the Oh My Bash template file and adding it to ~/.bashrc${NORMAL}\n"
|
|
||||||
_omb_install_run cp "$OSH"/templates/bashrc.osh-template ~/.bashrc
|
|
||||||
sed "/^export OSH=/ c\\
|
|
||||||
export OSH=$OSH
|
|
||||||
" ~/.bashrc >| ~/.bashrc.omb-temp
|
|
||||||
_omb_install_run mv -f ~/.bashrc.omb-temp ~/.bashrc
|
|
||||||
|
|
||||||
set +e
|
|
||||||
|
|
||||||
# MOTD message :)
|
|
||||||
printf '%s' "$GREEN"
|
|
||||||
printf '%s\n' \
|
|
||||||
' __ __ __ ' \
|
|
||||||
' ____ / /_ ____ ___ __ __ / /_ ____ ______/ /_ ' \
|
|
||||||
' / __ \/ __ \ / __ `__ \/ / / / / __ \/ __ `/ ___/ __ \' \
|
|
||||||
'/ /_/ / / / / / / / / / / /_/ / / /_/ / /_/ (__ ) / / /' \
|
|
||||||
'\____/_/ /_/ /_/ /_/ /_/\__, / /_.___/\__,_/____/_/ /_/ ' \
|
|
||||||
' /____/ .... is now installed!' \
|
|
||||||
"Please look over the ~/.bashrc file to select plugins, themes, and options"
|
|
||||||
printf "${BLUE}${BOLD}%s${NORMAL}\n" "To keep up on the latest news and updates, follow us on GitHub: https://github.com/ohmybash/oh-my-bash"
|
|
||||||
|
|
||||||
if [[ :$install_opts: == *:dry-run:* ]]; then
|
|
||||||
printf '%s\n' "$GREEN$BOLD[dryrun]$NORMAL Sample bashrc is created at '$BOLD$HOME/.bashrc-ombtemp$NORMAL'."
|
|
||||||
elif [[ :$install_opts: != *:unattended:* ]]; then
|
|
||||||
if [[ $- == *i* ]]; then
|
|
||||||
# In case install.sh is sourced from the interactive Bash
|
|
||||||
source ~/.bashrc
|
|
||||||
else
|
else
|
||||||
exec bash
|
_omb_install_user_bashrc
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user