hwakabh / dotfiles

Personal Configuration files
0 stars 0 forks source link

Create initial scripts for OSX #4

Open hwakabh opened 3 years ago

hwakabh commented 3 years ago

For considering factory reset, it's required to implement setup scritps, for example:

hwakabh commented 1 year ago

Essentials for script installations

brew

brew official documents

# Install
% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Create profile for adding PATH
% (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> $HOME/.zprofile

# Load config
% eval "$(/opt/homebrew/bin/brew shellenv)"

# Check
% which brew
/opt/homebrew/bin/brew
% brew --version
Homebrew 4.1.20
$ brew --prefix
/opt/homebrew

mas

$ brew install mas
$ which mas
/opt/homebrew/bin/mas

wget

$ brew install wget
$ wget --version
hwakabh commented 1 year ago

Visual Studio Code

Note that code CLI tools would be also installed to the system.

# Install
$ brew install visual-studio-code --cask

# Check application configuration directory
$ ls -al $HOME/.vscode

# Verify
$ which code
/opt/homebrew/bin/code
$ code --version
1.73.1
6261075646f055b99068d3688932416f2346dd3b
arm64
hwakabh commented 1 year ago

Hammerspoon

Note that it requires that Accessiblity permissions to Hammerspoon apps in System Preferences > Security & Privacy > Privacy menu, after installing app.

# Install
% brew install hammerspoon --cask
% open /Applications/Hammerspoon.app
#-> Required permission to `Accessibility`

# Check and create if not exists
% mkdir -p $HOME/.hammerspoon
% curl -X GET https://raw.githubusercontent.com/hwakabh/dotfiles/main/hammerspoon/init.lua > $HOME/.hammerspoon/init.lua

# Restart hammerspoon application
#-> Hammerspoon app is launching from `/Applications/Hammerspoon.app/Contents/MacOS/Hammerspoon`
#-> You can confirm this with `ps -ef` command output
% pgrep Hammerspoon
1627
% kill -9 $(pgrep Hammerspoon) && open /Applications/Hammerspoon.app 
% pgrep Hammerspoon
1669

# Check hs command is available and reload
# Ref: https://github.com/Hammerspoon/hammerspoon/issues/947
% which hs
/opt/homebrew/bin/hs
% hs -c "hs.reload()"
hwakabh commented 1 year ago

Docker

Note that Docker requires root permissions and also need interactive subscription agreements via UI instead of CLI. Following steps would be done by manually after launching application.

# Install
$ brew install docker --cask
$ ls -al /Applications/Docker.app

# Launch application
$ open /Applications/Docker.app

# Verify
$ which docker
/usr/local/bin/docker
$ docker --version
Docker version 20.10.21, build baeda1f
hwakabh commented 1 year ago

Change hostname with scutil

Note that first time to modify Preferences with scutil, it requires to enter root password interactively.

$ export NAME='hwakabayashi-vmw-mbp'

# Change ComputeName
$ scutil --get ComputerName
$ sudo scutil --set ComputerName $NAME

# Change LocalHostName
$ scutil --get LocalHostName
$ sudo scutil --set LocalHostName $NAME

# Change HostName, note that aligned to default one
$ scutil --get HostName
$ sudo scutil --set HostName "$NAME.vmware.com"
hwakabh commented 1 year ago

Native git

Install native git instead of apple-git, which installed in OSX by default. Note that with adding configs of PATH search order to .zprofile, all the binaries installed by brew and located in /opt/homebrew, where defined in brew --prefix, are taking priorities in finding command binaries.

# Check apple-git default path
$ which git
/usr/bin/git
$ /usr/bin/git --version
git version 2.37.1 (Apple Git-137.1)

# Add native git via brew
$ brew install git

# Check
$ ls -al /opt/homebrew/bin/git
lrwxr-xr-x  1 hwakabayashi  admin  28 Nov 14 01:32 /opt/homebrew/bin/git -> ../Cellar/git/2.38.1/bin/git
$ /opt/homebrew/bin/git --version
git version 2.38.1

# Replace orders in PATH
$ echo 'export PATH="$(brew --prefix)/bin:${PATH}"' >> $HOME/.zprofile
$ source $HOME/.zprofile
$ which git
/opt/homebrew/bin/git

# Fetch dotfiles
$ curl -s -X GET https://raw.githubusercontent.com/hwakabh/dotfiles/main/gitconf/.gitconfig > $HOME/.gitconfig
hwakabh commented 1 year ago

PowerShell

# Install
$ brew install powershell --cask

# Check
$ which pwsh
/usr/local/bin/pwsh
$ pwsh --version
PowerShell 7.3.0

# Added alias
$ echo 'alias powershell="pwsh"' >> $HOME/.zprofile

For installation of PowerCLI for managing VMware softwares, additional command would be required.

# Install modules
$ Install-Module -Name VMware.PowerCLI -Scope CurrentUser

# Initial configurations to disable some warnings
$ Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$ Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -Confirm:$false
hwakabh commented 1 year ago

Finder Config

# Enable `Show all filename extensions` in Finder Advanced Preferences
$ defaults write NSGlobalDomain AppleShowAllExtensions -bool true
$ killall Finder

# Change default directories to open with iCloud Drive
$ defaults write com.apple.finder NewWindowTarget -string 'PfID'
$ defaults write com.apple.finder NewWindowTargetPath -string "file://$HOME/Library/Mobile\ Documents/com~apple~CloudDocs"
$ killall Finder

# Show hidden items
# Keyboard Shortcut: `Cmd` + `Shift` + `.`
$ defaults write com.apple.finder AppleShowAllFiles -bool true
$ killall Finder
hwakabh commented 1 year ago

Python

# Install pyenv for changing Python version
$ brew install pyenv
$ cat >> $HOME/.zprofile << EOF
# Python
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
EOF
$ source .zprofile
$ python -V

# Install poetry for splitting dev-dependencies
$ export GET_POETRY_IGNORE_DEPRECATION=1
$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
$ echo 'export PATH="$PATH:$HOME/.poetry/bin"' >> $HOME/.zprofile
$ source $HOME/.zprofile
$ poetry -v

Note that get-poetry.py, installer of poetry, would be depreciated, in this script, using exceptions to set flags, so that upgrading poetry itself with cli. Reference: https://github.com/python-poetry/poetry/issues/6377 By official references, alternatives for this should be to use script in install.python-poetry.org.

hwakabh commented 1 year ago

1Password

Downloading installer binaries for OSX, instead of using 1Password CLI. Note that latest version of 1Password 8 is only available from downloading binaries, meaning we can install 1Password 7 via AppStore using mas command, but this option would not be adopted for now.

% wget https://downloads.1password.com/mac/1Password.zip
% unzip ./1Password.zip

# After opening installer app, it automatically starts installing with popup modal, 
# Then, installer would ask you to sign in interactively, so you need to provide your credentials manually.
% open '1Password Installer.app'

# Clean up
% rm -rf ./1Password.zip