Skip to content

Commit

Permalink
[os] Make improvements and consistency changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alrra committed Jul 25, 2016
1 parent 4196225 commit 7f8798a
Show file tree
Hide file tree
Showing 37 changed files with 167 additions and 192 deletions.
4 changes: 1 addition & 3 deletions src/os/create_directories.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ create_directories() {
"$HOME/Downloads/torrents"
)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

for i in "${DIRECTORIES[@]}"; do
mkd "$i"
done
Expand All @@ -22,7 +20,7 @@ create_directories() {
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

main() {
print_info "Create directories"
print_in_purple "\n Create directories\n\n"
create_directories
}

Expand Down
2 changes: 1 addition & 1 deletion src/os/create_symbolic_links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ create_symlinks() {
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

main() {
print_info "Create symbolic links"
print_in_purple "\n Create symbolic links\n\n"
create_symlinks "$@"
}

Expand Down
13 changes: 9 additions & 4 deletions src/os/initialize_git_repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ cd "$(dirname "${BASH_SOURCE[0]}")" \

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

main() {
initialize_git_repository() {

declare -r GIT_ORIGIN="$1"

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

print_info "Initialize Git repository"

if [ -z "$GIT_ORIGIN" ]; then
print_error "Please provide a URL for the Git origin"
exit 1
Expand All @@ -23,7 +21,7 @@ main() {
if ! is_git_repository; then

# Run the following Git commands in the root of
# the dotfiles directory, not in the `os/` directory
# the dotfiles directory, not in the `os/` directory.

cd ../../ \
|| print_error "Failed to 'cd ../../'"
Expand All @@ -36,4 +34,11 @@ main() {

}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

main() {
print_in_purple "\n Initialize Git repository\n\n"
initialize_git_repository "$1"
}

main "$1"
35 changes: 10 additions & 25 deletions src/os/install/macos/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,14 @@ cd "$(dirname "${BASH_SOURCE[0]}")" \

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

add_path_to_login_shells_list() {

declare -r NEW_SHELL_PATH="$1"

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

if ! grep "$NEW_SHELL_PATH" < /etc/shells &> /dev/null; then
execute \
"printf '%s\n' '$NEW_SHELL_PATH' | sudo tee -a /etc/shells" \
"Bash (add '$NEW_SHELL_PATH' in '/etc/shells')"
fi

}

change_default_bash() {

local newShellPath=""

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Try to get the path of the `Bash`
# version installed through `Homebrew`
# version installed through `Homebrew`.

newShellPath="$(get_homebrew_bash_path)" \
|| return 1
Expand All @@ -44,21 +30,20 @@ change_default_bash() {
#
# http://www.linuxfromscratch.org/blfs/view/7.4/postlfs/etcshells.html

add_path_to_login_shells_list "$newShellPath"
if ! grep "$newShellPath" < /etc/shells &> /dev/null; then
execute \
"printf '%s\n' '$newShellPath' | sudo tee -a /etc/shells" \
"Bash (add '$newShellPath' in '/etc/shells')" \
|| return 1
fi

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Set latest version of `Bash` as the default
# (macOS uses by default an older version of `Bash`)

change_login_shell "$newShellPath"

}

change_login_shell() {
# (macOS uses by default an older version of `Bash`).

execute \
"sudo chsh -s '$1'" \
"sudo chsh -s '$newShellPath'" \
"Bash (use latest version)"

}
Expand All @@ -85,7 +70,7 @@ get_homebrew_bash_path() {

main() {

print_info " Bash"
print_in_purple "\n Bash\n\n"

brew_install "Bash" "bash" \
&& change_default_bash
Expand Down
12 changes: 6 additions & 6 deletions src/os/install/macos/homebrew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ get_homebrew_git_config_file_path() {
printf "%s" "$path"
return 0
else
print_error "brew (get config file path)"
print_error "Homebrew (get config file path)"
return 1
fi

Expand All @@ -31,7 +31,7 @@ install_homebrew() {
# └─ simulate the ENTER keypress
fi

print_result $? "brew"
print_result $? "Homebrew"

}

Expand All @@ -41,29 +41,29 @@ opt_out_of_analytics() {

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Try to get the path of the `Homebrew` git config file
# Try to get the path of the `Homebrew` git config file.

path="$(get_homebrew_git_config_file_path)" \
|| return 1

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Opt-out of Homebrew's analytics
# Opt-out of Homebrew's analytics.
# https://github.com/Homebrew/brew/blob/0c95c60511cc4d85d28f66b58d51d85f8186d941/share/doc/homebrew/Analytics.md#opting-out

if [ "$(git config --file="$path" --get homebrew.analyticsdisabled)" != "true" ]; then
git config --file="$path" --replace-all homebrew.analyticsdisabled true &> /dev/null
fi

print_result $? "brew (opt-out of analytics)"
print_result $? "Homebrew (opt-out of analytics)"

}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

main() {

print_info " Homebrew"
print_in_purple "\n Homebrew\n\n"

install_homebrew
opt_out_of_analytics
Expand Down
3 changes: 1 addition & 2 deletions src/os/install/macos/misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ install_apps() {

main() {

print_info " Miscellaneous"
print_in_purple "\n Miscellaneous\n\n"

install_apps

printf "\n"
brew_cleanup

Expand Down
19 changes: 10 additions & 9 deletions src/os/install/macos/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ brew_cleanup() {

# By default Homebrew does not uninstall older versions
# of formulas so, in order to remove them, `brew cleanup`
# needs to be used:
# needs to be used.
#
# https://github.com/Homebrew/brew/blob/496fff643f352b0943095e2b96dbc5e0f565db61/share/doc/homebrew/FAQ.md#how-do-i-uninstall-old-versions-of-a-formula

execute \
"brew cleanup" \
"brew (cleanup)"
"Homebrew (cleanup)"

execute \
"brew cask cleanup" \
"brew cask (cask cleanup)"
"homebrew (cask cleanup)"

}

Expand All @@ -32,16 +32,17 @@ brew_install() {

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Check if `Homebrew` is installed
# Check if `Homebrew` is installed.

if ! cmd_exists "brew"; then
print_error "$FORMULA_READABLE_NAME ('brew' is not installed)"
print_error "$FORMULA_READABLE_NAME ('Homebrew' is not installed)"
return 1
fi

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# If `brew tap` needs to be executed, check if it executed correctly
# If `brew tap` needs to be executed,
# check if it executed correctly.

if [ -n "$TAP_VALUE" ]; then
if ! brew_tap "$TAP_VALUE"; then
Expand All @@ -52,7 +53,7 @@ brew_install() {

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Install the specified formula
# Install the specified formula.

if brew "$CMD" list "$FORMULA" &> /dev/null; then
print_success "$FORMULA_READABLE_NAME"
Expand All @@ -72,14 +73,14 @@ brew_update() {

execute \
"brew update" \
"brew (update)"
"Homebrew (update)"

}

brew_upgrade() {

execute \
"brew upgrade --all" \
"brew (upgrade)"
"Homebrew (upgrade)"

}
20 changes: 11 additions & 9 deletions src/os/install/macos/xcode.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
#!/bin/bash

cd "$(dirname "${BASH_SOURCE[0]}")" \
&& . "../../utils.sh" \
&& . "./utils.sh"
&& . "../../utils.sh"

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

agree_with_xcode_licence() {

# Automatically agree to the terms of the Xcode license
# Automatically agree to the terms of the Xcode license.
# https://github.com/alrra/dotfiles/issues/10

execute \
"sudo xcodebuild -license accept" \
"Agree to the terms of the XCode Command Line Tools licence"
"Agree to the terms of the XCode licence"

}

install_xcode() {

# Prompt user to install the XCode Command Line Tools
# Prompt user to install the XCode Command Line Tools.

xcode-select --install &> /dev/null

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Wait until the XCode Command Line Tools are installed
# Wait until the XCode Command Line Tools are installed.

until is_xcode_installed; do
sleep 5
done

print_result $? "XCode Command Line Tools"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

print_result $? "XCode"

}

Expand All @@ -42,7 +43,8 @@ is_xcode_installed() {
set_xcode_developer_directory() {

# Point the `xcode-select` developer directory to
# the appropriate directory from within `Xcode.app`
# the appropriate directory from within `Xcode.app`.
#
# https://github.com/alrra/dotfiles/issues/13

execute \
Expand All @@ -55,7 +57,7 @@ set_xcode_developer_directory() {

main() {

print_info " XCode"
print_in_purple "\n XCode\n\n"

install_xcode
set_xcode_developer_directory
Expand Down
16 changes: 5 additions & 11 deletions src/os/install/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@ cd "$(dirname "${BASH_SOURCE[0]}")" \

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

main() {
print_in_purple "\n Installs\n"

print_in_purple "\n\n Install applications\n"

"./$(get_os)/main.sh"
./nvm.sh
./npm.sh
./vim.sh

}

main
"./$(get_os)/main.sh"
./nvm.sh
./npm.sh
./vim.sh
Loading

0 comments on commit 7f8798a

Please sign in to comment.