Further tidying and making
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
|||||||
*.dotlock
|
.dotlock
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -1,3 +1,7 @@
|
|||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f .dotlock
|
rm -f .dotlock
|
||||||
|
|
||||||
|
.PHONY: run
|
||||||
|
run:
|
||||||
|
bash bootstrap.sh
|
||||||
40
bootstrap.sh
40
bootstrap.sh
@@ -6,31 +6,43 @@
|
|||||||
# `source path/to/bootstrap.sh`
|
# `source path/to/bootstrap.sh`
|
||||||
# `source <(wget path/to/bootstrap.sh)`
|
# `source <(wget path/to/bootstrap.sh)`
|
||||||
#
|
#
|
||||||
set -euf -o pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Set up variables and imports
|
# Set up variables and imports
|
||||||
repository="andrejusk/dotfiles"
|
readonly repository="andrejusk/dotfiles"
|
||||||
repository_url="https://github.com/$repository.git"
|
readonly repository_url="https://github.com/$repository.git"
|
||||||
workspace_dir="$HOME/workspace"
|
readonly workspace_dir="$HOME/workspace"
|
||||||
dotfiles_dir="$workspace_dir/dotfiles"
|
readonly dotfiles_dir="$workspace_dir/dotfiles"
|
||||||
lock_extension="dotlock"
|
readonly install_dir="$dotfiles_dir/install"
|
||||||
source "${dotfiles_dir}/utils.sh"
|
readonly lock_file="$dotfiles_dir/.dotlock"
|
||||||
|
source "$dotfiles_dir/utils.sh"
|
||||||
|
|
||||||
|
# Log execution
|
||||||
|
printf "Setting up ${C_CYAN}$repository${C_NC} with:\n"
|
||||||
|
printf " repository:\t ${C_YELLOW}$repository${C_NC}\n"
|
||||||
|
printf " repository_url: ${C_YELLOW}$repository_url${C_NC}\n"
|
||||||
|
printf " workspace_dir: ${C_YELLOW}$workspace_dir${C_NC}\n"
|
||||||
|
printf " dotfiles_dir:\t ${C_YELLOW}$dotfiles_dir${C_NC}\n"
|
||||||
|
printf " install_dir:\t ${C_YELLOW}$install_dir${C_NC}\n"
|
||||||
|
printf " lock_file:\t ${C_YELLOW}$lock_file${C_NC}\n\n"
|
||||||
|
|
||||||
# Ensure git is installed
|
# Ensure git is installed
|
||||||
if ! hash git 2>/dev/null; then
|
if ! hash git 2>/dev/null
|
||||||
|
then
|
||||||
sudo apt-get update -yqq
|
sudo apt-get update -yqq
|
||||||
sudo apt-get install -yqq git
|
sudo apt-get install -yqq git
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure repository is cloned
|
# Ensure repository is cloned
|
||||||
if [[ ! -d $dotfiles_dir ]]; then
|
if [[ ! -d "$dotfiles_dir" ]]
|
||||||
mkdir -p $workspace_dir
|
then
|
||||||
git clone $repository_url $dotfiles_dir
|
mkdir -p "$workspace_dir"
|
||||||
|
git clone -q "$repository_url" "$dotfiles_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure repository is up to date
|
# Ensure repository is up to date
|
||||||
cd $dotfiles_dir
|
cd "$dotfiles_dir"
|
||||||
# git pull origin master
|
git pull -q origin master || true
|
||||||
|
|
||||||
# Install dotfiles
|
# Install dotfiles
|
||||||
source $dotfiles_dir/install.sh
|
source "$dotfiles_dir/install.sh"
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
# Ensure fisher is installed
|
|
||||||
if not functions -q fisher
|
|
||||||
set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
|
|
||||||
curl https://git.io/fisher --create-dirs -sLo $XDG_CONFIG_HOME/fish/functions/fisher.fish
|
|
||||||
fish -c fisher
|
|
||||||
end
|
|
||||||
|
|
||||||
# Poetry
|
|
||||||
set -gx PATH $HOME/.poetry/bin $PATH
|
|
||||||
|
|
||||||
# Wipe greeting
|
|
||||||
set fish_greeting
|
|
||||||
1
fish/config.fish
Symbolic link
1
fish/config.fish
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/home/andrejus/.config/fish
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
rafaelrinaldi/pure
|
|
||||||
jorgebucaran/fish-nvm
|
|
||||||
1
fish/fishfile
Symbolic link
1
fish/fishfile
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/home/andrejus/.config/fish
|
||||||
17
install.sh
17
install.sh
@@ -8,25 +8,26 @@ printf "Installing ${C_CYAN}$repository${C_NC}"
|
|||||||
printf " as ${C_YELLOW}$USER${C_NC}\n\n"
|
printf " as ${C_YELLOW}$USER${C_NC}\n\n"
|
||||||
|
|
||||||
# Prevent running as root
|
# Prevent running as root
|
||||||
if [ "$USER" == "root" ]; then
|
if [ "$USER" == "root" ]
|
||||||
printf "Failed: ${C_RED}Running as $USER${C_NC}\n"
|
then
|
||||||
|
printf "Failed: ${C_RED}Running as root${C_NC}\n"
|
||||||
printf "Please run as user, not ${C_YELLOW}sudo${C_NC}\n"
|
printf "Please run as user, not ${C_YELLOW}sudo${C_NC}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Prevent concurrent scripts
|
# Prevent concurrent scripts
|
||||||
lock_file="$dotfiles_dir/.$lock_extension"
|
if [ -f "$lock_file" ]
|
||||||
if [ -f "$lock_file" ]; then
|
then
|
||||||
printf "Failed: ${C_RED}Script already running${C_NC}\n"
|
printf "Failed: ${C_RED}Script already running${C_NC}\n"
|
||||||
printf "Please wait for script to exit or ${C_YELLOW}make clean${C_NC}\n"
|
printf "Please wait for script to exit or ${C_YELLOW}make clean${C_NC}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
touch $lock_file # Requires clear
|
touch "$lock_file" # Requires clean
|
||||||
|
|
||||||
# Run all install scripts
|
# Run all install scripts
|
||||||
for script in "$dotfiles_dir/install/*.sh"; do
|
script_filter="$install_dir/*.sh"
|
||||||
|
for script in $script_filter
|
||||||
printf "$script\n\n"
|
do
|
||||||
|
|
||||||
# Avoid pattern matching self
|
# Avoid pattern matching self
|
||||||
[ -e "$script" ] || continue
|
[ -e "$script" ] || continue
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ DEBIAN_FRONTEND=noninteractive sudo apt-get \
|
|||||||
-o Dpkg::Options::="--force-confold" upgrade -y
|
-o Dpkg::Options::="--force-confold" upgrade -y
|
||||||
|
|
||||||
# Package installs
|
# Package installs
|
||||||
pkglist=$(cat $install_dir/00-apt-pkglist)
|
readonly apt_pkglist=$(cat $install_dir/00-apt-pkglist)
|
||||||
sudo apt-get install -y $pkglist
|
sudo apt-get install -y $apt_pkglist
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# 1. fish shell is installed
|
# 1. fish shell is installed
|
||||||
if [ ! hash fish ] 2>/dev/null; then
|
if [ is_missing fish ] 2>/dev/null
|
||||||
|
then
|
||||||
|
|
||||||
printf "Installing fish...\n"
|
printf "Installing fish...\n"
|
||||||
|
|
||||||
@@ -22,23 +23,20 @@ fi
|
|||||||
printf "fish is installed\n"
|
printf "fish is installed\n"
|
||||||
|
|
||||||
# 2. fish shell is default login shell
|
# 2. fish shell is default login shell
|
||||||
fish_path=$(which fish)
|
readonly fish_path=$(which fish)
|
||||||
if [ $SHELL != fish_path ]; then
|
if [ $SHELL != fish_path ]
|
||||||
|
then
|
||||||
|
|
||||||
printf "Setting fish as default...\n"
|
printf "Setting fish as default...\n"
|
||||||
|
|
||||||
# Update default login shell
|
# Update default login shell
|
||||||
chsh -s $fish_path $USER
|
|
||||||
usermod -s $fish_path $USER
|
usermod -s $fish_path $USER
|
||||||
|
|
||||||
fi
|
fi
|
||||||
printf "fish is default login shell\n"
|
printf "fish is default login shell\n"
|
||||||
|
|
||||||
# 3. fish dotfiles are symlinked
|
# 3. fish dotfiles are symlinked
|
||||||
target="$HOME/.config/fish"
|
readonly fish_source="$dotfiles_dir/fish/*"
|
||||||
for file in $(ls -d $script_dir/fish/*); do
|
readonly fish_target="$HOME/.config/fish"
|
||||||
rel_path=$(realpath --relative-to="$target" "$file")
|
link_folder "$fish_source" "$fish_target"
|
||||||
printf "Linking $file to $target as $rel_path...\n"
|
|
||||||
ln -sv $rel_path $target
|
|
||||||
done
|
|
||||||
printf "fish dotfiles linked\n"
|
printf "fish dotfiles linked\n"
|
||||||
|
|||||||
@@ -5,10 +5,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# 1. git dotfiles are symlinked
|
# 1. git dotfiles are symlinked
|
||||||
target="$HOME"
|
readonly git_source="$dotfiles_dir/git/*"
|
||||||
for file in $(ls -d $script_dir/git/*); do
|
readonly git_target="$HOME"
|
||||||
rel_path=$(realpath --relative-to="$target" "$file")
|
link_folder $git_source $git_target
|
||||||
printf "Linking $file to $target as $rel_path...\n"
|
|
||||||
ln -sv $rel_path $target
|
|
||||||
done
|
|
||||||
printf "git dotfiles linked\n"
|
printf "git dotfiles linked\n"
|
||||||
|
|||||||
@@ -5,12 +5,14 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# 1.keybase is installed
|
# 1.keybase is installed
|
||||||
if [ ! hash fish ] 2>/dev/null; then
|
if [ ! hash keybase ] 2>/dev/null
|
||||||
|
then
|
||||||
|
|
||||||
printf "Installing keybase...\n"
|
printf "Installing keybase...\n"
|
||||||
|
|
||||||
curl --remote-name https://prerelease.keybase.io/keybase_amd64.deb
|
curl --remote-name https://prerelease.keybase.io/keybase_amd64.deb
|
||||||
sudo apt install ./keybase_amd64.deb
|
sudo apt-get install -y ./keybase_amd64.deb
|
||||||
run_keybase
|
run_keybase
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
printf "keybase is installed\n"
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# 1. docker is installed
|
# 1. docker is installed
|
||||||
if ! hash docker 2>/dev/null; then
|
if ! hash docker 2>/dev/null
|
||||||
|
then
|
||||||
|
|
||||||
printf "Installing docker...\n"
|
printf "Installing docker...\n"
|
||||||
|
|
||||||
@@ -32,7 +33,8 @@ fi
|
|||||||
printf "docker is installed\n"
|
printf "docker is installed\n"
|
||||||
|
|
||||||
# 2. docker-compose if installed
|
# 2. docker-compose if installed
|
||||||
if ! hash docker-compose 2>/dev/null; then
|
if ! hash docker-compose 2>/dev/null
|
||||||
|
then
|
||||||
|
|
||||||
printf "Installing docker-compose...\n"
|
printf "Installing docker-compose...\n"
|
||||||
|
|
||||||
@@ -45,14 +47,16 @@ fi
|
|||||||
printf "docker-compose is installed\n"
|
printf "docker-compose is installed\n"
|
||||||
|
|
||||||
# 3. docker group exists
|
# 3. docker group exists
|
||||||
group='docker'
|
readonly docker_group='docker'
|
||||||
if ! grep -q $group /etc/group; then
|
if ! grep -q $docker_group /etc/group
|
||||||
sudo groupadd docker
|
then
|
||||||
|
sudo groupadd $docker_group
|
||||||
fi
|
fi
|
||||||
printf "group '$group' is created\n"
|
printf "group '$docker_group' is created\n"
|
||||||
|
|
||||||
# 4. user is in docker group
|
# 4. user is in docker group
|
||||||
if ! groups $USER | grep -q "\b$group\b"; then
|
if ! groups $USER | grep -q "\b$docker_group\b"
|
||||||
|
then
|
||||||
sudo usermod -aG docker $USER
|
sudo usermod -aG docker $USER
|
||||||
fi
|
fi
|
||||||
printf "user '$USER' is in '$group' group\n"
|
printf "user '$USER' is in '$docker_group' group\n"
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# 1. pyenv is installed
|
# 1. pyenv is installed
|
||||||
if ! hash pyenv 2>/dev/null; then
|
if ! hash pyenv 2>/dev/null
|
||||||
|
then
|
||||||
|
|
||||||
printf "Installing pyenv...\n"
|
printf "Installing pyenv...\n"
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# 1. python is installed
|
# 1. python is installed
|
||||||
if ! hash python 2>/dev/null; then
|
if ! hash python 2>/dev/null
|
||||||
|
then
|
||||||
|
|
||||||
printf "Installing python...\n"
|
printf "Installing python...\n"
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# 1. poetry is installed
|
# 1. poetry is installed
|
||||||
if ! hash poetry 2>/dev/null; then
|
if ! hash poetry 2>/dev/null
|
||||||
|
then
|
||||||
|
|
||||||
printf "Installing poetry...\n"
|
printf "Installing poetry...\n"
|
||||||
|
|
||||||
|
|||||||
24
utils.sh
24
utils.sh
@@ -1,5 +1,29 @@
|
|||||||
indent() { sed 's/^/ /'; }
|
indent() { sed 's/^/ /'; }
|
||||||
|
|
||||||
|
# Symlink contents of source folder to target
|
||||||
|
#
|
||||||
|
# @arg $1 source
|
||||||
|
# @arg $2 target
|
||||||
|
#
|
||||||
|
link_folder () {
|
||||||
|
|
||||||
|
source=$1
|
||||||
|
target=$2
|
||||||
|
|
||||||
|
for file in $(ls -d $source)
|
||||||
|
do
|
||||||
|
rel_path=$(realpath --relative-to="$target" "$file")
|
||||||
|
printf "Linking $file to $target as $rel_path...\n"
|
||||||
|
ln -sf $target $rel_path
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Return if specified binary is not in PATH
|
||||||
|
is_missing () {
|
||||||
|
return ! hash $1
|
||||||
|
}
|
||||||
|
|
||||||
C_BLACK='\033[0;30m'
|
C_BLACK='\033[0;30m'
|
||||||
C_DGRAY='\033[1;30m'
|
C_DGRAY='\033[1;30m'
|
||||||
C_RED='\033[0;31m'
|
C_RED='\033[0;31m'
|
||||||
|
|||||||
Reference in New Issue
Block a user