Compare commits

...

2 Commits

8 changed files with 226 additions and 105 deletions

View File

@@ -1,88 +0,0 @@
#!/bin/sh
#
# Usage:
#
# sh install.sh
#
# Environment variables: VERBOSE, CP, LN, MKDIR, RM, DIRNAME.
#
# env VERBOSE=1 sh install.sh
#
# DO NOT EDIT THIS FILE
#
# This file is generated by rcm(7) as:
#
# rcup -B 0 -g
#
# To update it, re-run the above command.
#
: ${VERBOSE:=0}
: ${CP:=/bin/cp}
: ${LN:=/bin/ln}
: ${MKDIR:=/bin/mkdir}
: ${RM:=/bin/rm}
: ${DIRNAME:=/usr/bin/dirname}
verbose()
{
if [ "$VERBOSE" -gt 0 ]; then
echo "$@"
fi
}
handle_file_cp()
{
if [ -e "$2" ]; then
printf "%s " "overwrite $2? [yN]"
read overwrite
case "$overwrite" in
y)
$RM -rf "$2"
;;
*)
echo "skipping $2"
return
;;
esac
fi
verbose "'$1' -> '$2'"
$MKDIR -p "$($DIRNAME "$2")"
$CP -R "$1" "$2"
}
handle_file_ln()
{
if [ -e "$2" ]; then
printf "%s " "overwrite $2? [yN]"
read overwrite
case "$overwrite" in
y)
$RM -rf "$2"
;;
*)
echo "skipping $2"
return
;;
esac
fi
verbose "'$1' -> '$2'"
$MKDIR -p "$($DIRNAME "$2")"
$LN -sf "$1" "$2"
}
handle_file_ln "~/.dotfiles/bash_profile" "~/.bash_profile"
handle_file_ln "~/.dotfiles/bashrc" "~/.bashrc"
handle_file_ln "~/.dotfiles/config/alias" "~/.config/alias"
handle_file_ln "~/.dotfiles/config/antigen.zsh" "~/.config/antigen.zsh"
handle_file_ln "~/.dotfiles/config/exports" "~/.config/exports"
handle_file_ln "~/.dotfiles/config/functions" "~/.config/functions"
handle_file_ln "~/.dotfiles/config/gh/config.yml" "~/.config/gh/config.yml"
handle_file_ln "~/.dotfiles/config/git/config" "~/.config/git/config"
handle_file_ln "~/.dotfiles/config/git/gitignore" "~/.config/git/gitignore"
handle_file_ln "~/.dotfiles/config/wtf/config.yml" "~/.config/wtf/config.yml"
handle_file_ln "~/.dotfiles/git_profiles" "~/.git_profiles"
handle_file_ln "~/.dotfiles/huskyrc" "~/.huskyrc"
handle_file_ln "~/.dotfiles/local/bin/dotfiles" "~/.local/bin/dotfiles"
handle_file_ln "~/.dotfiles/local/bin/x-check-git-attributes" "~/.local/bin/x-check-git-attributes"
handle_file_ln "~/.dotfiles/local/bin/x-open-ports" "~/.local/bin/x-open-ports"
handle_file_ln "~/.dotfiles/rcrc" "~/.rcrc"
handle_file_ln "~/.dotfiles/ssh/allowed_signers" "~/.ssh/allowed_signers"
handle_file_ln "~/.dotfiles/ssh/config" "~/.ssh/config"
handle_file_ln "~/.dotfiles/vuerc" "~/.vuerc"
handle_file_ln "~/.dotfiles/zshrc" "~/.zshrc"

View File

@@ -1,29 +1,27 @@
#!/usr/bin/env bash
#
# Dotfiles and install helper
# Dotfiles manager and install helper
# (c) Ismo Vuorinen <https://github.com/ivuorinen> 2022
# Licensed under MIT, see LICENSE
#
# shellcheck source-path=SCRIPTDIR
# shellcheck source-path=$HOME/.dotfiles/local/bin
#
# Helper variables, override with ENVs like `VERBOSE=1 helpers.sh help`
# Helper variables, override with ENVs like `VERBOSE=1 dfm help`
: "${VERBOSE:=0}"
: "${DOTFILES:=$HOME/.dotfiles}"
: "${INSTALL_SCRIPT:=$DOTFILES/install.sh}"
: "${INSTALL_SCRIPT:=$DOTFILES/scripts/install.sh}"
: "${BREWFILE:=$DOTFILES/Brewfile}"
function usage
{
echo $"Usage: $0 [install | brew | dotfiles]"
echo $" All commands have their own subcommands."
echo $" When in doubt run the subcommand to show list."
}
SCRIPT=$(basename "$0")
function section_install
{
USAGE_PREFIX="Usage: $0 install"
USAGE_PREFIX="-> $SCRIPT install"
case "$1" in
all)
bash "$DOTFILES/scripts/settler.sh" && echo "🎉 Done!"
;;
antigen)
curl -L git.io/antigen > "$DOTFILES/config/antigen.zsh" && echo "🎉 Done!"
;;
@@ -44,7 +42,7 @@ function section_install
function section_brew
{
USAGE_PREFIX="Usage: $0 brew"
USAGE_PREFIX="-> $SCRIPT brew"
if ! command -v brew &> /dev/null; then
echo "brew could not be found, please install it first"
@@ -79,18 +77,18 @@ function section_brew
function section_dotfiles
{
USAGE_PREFIX="Usage: $0 dotfiles"
USAGE_PREFIX="-> $SCRIPT dotfiles"
case "$1" in
link)
rcup -B "$HOSTNAME" -v && echo "🎉 Done!"
;;
update)
# Updates .dotfiles/install.sh and formats it
# Updates .dotfiles/scripts/install.sh and formats it
rcup -B 0 -g \
| tee "$INSTALL_SCRIPT" 1> /dev/null \
&& shfmt -w -l "$INSTALL_SCRIPT" \
&& sed -i '' "s|$HOME|\~|g" "$INSTALL_SCRIPT" \
&& sed -i '' "s|$HOME|\$HOME|g" "$INSTALL_SCRIPT" \
&& echo "🎉 Done!"
;;
shfmt)
@@ -123,6 +121,18 @@ function section_dotfiles
esac
}
function usage
{
echo $"Usage: $SCRIPT [install | brew | dotfiles]"
echo $" All commands have their own subcommands."
echo ""
section_install
echo ""
section_brew
echo ""
section_dotfiles
}
# The main loop. first keyword after $0 triggers section, or help.
case "$1" in
install) section_install "$2" ;;

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env bash
#
# Backup local MySQL Database tables with certain prefix.
# Ismo Vuorinen <https://github.com/ivuorinen> 2018
#
SCRIPT=$(basename "$0")
PREFIX=$1
FILENAME=$2
DATABASE=$3
: "${VERBOSE:=0}"
: "${DEFAULT_DATABASE:="wordpress"}"
if [ -z "${PREFIX}" ]; then
echo "(!) TABLE_PREFIX (first argument) is missing"
echo "(>) Usage: $SCRIPT <TABLE_PREFIX> <FILENAME_PREFIX> [<DATABASE>]"
echo " * <TABLE_PREFIX> = database table prefix, e.g. 'wp_'"
echo " * <FILENAME_PREFIX> = FILENAME prefix, defaults to table prefix. Use something descriptive e.g. 'wordpress'"
echo " * <DATABASE> = [optional] Third argument DATABASE, defaults to '$DEFAULT_DATABASE'."
exit 0
fi
if [ -z "${FILENAME}" ]; then
# echo "FILENAME (second argument) is missing, using PREFIX ($PREFIX)"
FILENAME=$PREFIX
fi
if [ -z "${DATABASE}" ]; then
# echo "DATABASE (third argument) is missing, using default ($DEFAULT_DATABASE)"
DATABASE=$DEFAULT_DATABASE
fi
TIMESTAMP=$(date "+%Y%m%d_%H%M%S")
FILENAME_TIMESTAMP="${DATABASE}_${FILENAME}_${TIMESTAMP}.sql"
mysqldump \
${DATABASE} \
"$(
echo "show tables like '${PREFIX}%';" \
| mysql ${DATABASE} \
| sed '/Tables_in/d'
)" > "${FILENAME_TIMESTAMP}"

View File

@@ -1,6 +1,16 @@
#!/usr/bin/env bash
#
# Check git repo's files .gitattributes and are all of them mapped.
# Ismo Vuorinen <https://github.com/ivuorinen> 2022
#
if ! command -v git &> /dev/null; then
echo "git could not be found, please install it first"
exit
fi
missing_attributes=$(git ls-files | git check-attr -a --stdin | grep "text: auto")
if [[ "$missing_attributes" ]]; then
echo ".gitattributes rule missing for the following files:"
echo "$missing_attributes"

View File

@@ -0,0 +1,52 @@
#!/usr/bin/env bash
##
# This script contains helper for sha256 validating your downloads
#
# Source: https://gist.github.com/onnimonni/b49779ebc96216771a6be3de46449fa1
# Author: Onni Hakala
# License: MIT
#
# Updated by Ismo Vuorinen <https://github.com/ivuorinen> 2022
##
if ! command -v sha256 &> /dev/null; then
echo "git could not be found, please install it first"
exit
fi
# Stop program and give error message
# $1 - error message (string)
function error
{
echo "(!) ERROR: $1"
exit 1
}
# return sha256sum for file
# $1 - filename (string)
function get_sha256sum
{
sha256sum "$1" | head -c 64
}
# Good variable names pls
filename=$1
file_hash=$2
# Check input
if [ -z "$filename" ]; then
error "You need to provide filename in first parameter"
fi
if [ -z "$file_hash" ]; then
error "You need to provide sha256sum in second parameter"
fi
# Check if the file is valid
if [ ! -f "$filename" ]; then
error "File $filename doesn't exist"
elif [ "$(get_sha256sum "$filename")" = "$file_hash" ]; then
echo "(*) Success: $filename matches provided sha256sum"
else
error "$filename doesn't match provided sha256sum"
fi

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env bash
# Install GitHub CLI extensions
if ! command -v gh &> /dev/null; then
echo "gh (GitHub Client) could not be found, please install it first"
exit 1
fi
extensions=(
# GitHub CLI extension for reviewing Dependabot PRs.
einride/gh-dependabot

88
scripts/install.sh Normal file
View File

@@ -0,0 +1,88 @@
#!/bin/sh
#
# Usage:
#
# sh install.sh
#
# Environment variables: VERBOSE, CP, LN, MKDIR, RM, DIRNAME.
#
# env VERBOSE=1 sh install.sh
#
# DO NOT EDIT THIS FILE
#
# This file is generated by rcm(7) as:
#
# rcup -B 0 -g
#
# To update it, re-run the above command.
#
: ${VERBOSE:=0}
: ${CP:=/bin/cp}
: ${LN:=/bin/ln}
: ${MKDIR:=/bin/mkdir}
: ${RM:=/bin/rm}
: ${DIRNAME:=/usr/bin/dirname}
verbose()
{
if [ "$VERBOSE" -gt 0 ]; then
echo "$@"
fi
}
handle_file_cp()
{
if [ -e "$2" ]; then
printf "%s " "overwrite $2? [yN]"
read overwrite
case "$overwrite" in
y)
$RM -rf "$2"
;;
*)
echo "skipping $2"
return
;;
esac
fi
verbose "'$1' -> '$2'"
$MKDIR -p "$($DIRNAME "$2")"
$CP -R "$1" "$2"
}
handle_file_ln()
{
if [ -e "$2" ]; then
printf "%s " "overwrite $2? [yN]"
read overwrite
case "$overwrite" in
y)
$RM -rf "$2"
;;
*)
echo "skipping $2"
return
;;
esac
fi
verbose "'$1' -> '$2'"
$MKDIR -p "$($DIRNAME "$2")"
$LN -sf "$1" "$2"
}
handle_file_ln "$HOME/.dotfiles/bash_profile" "$HOME/.bash_profile"
handle_file_ln "$HOME/.dotfiles/bashrc" "$HOME/.bashrc"
handle_file_ln "$HOME/.dotfiles/config/alias" "$HOME/.config/alias"
handle_file_ln "$HOME/.dotfiles/config/antigen.zsh" "$HOME/.config/antigen.zsh"
handle_file_ln "$HOME/.dotfiles/config/exports" "$HOME/.config/exports"
handle_file_ln "$HOME/.dotfiles/config/functions" "$HOME/.config/functions"
handle_file_ln "$HOME/.dotfiles/config/gh/config.yml" "$HOME/.config/gh/config.yml"
handle_file_ln "$HOME/.dotfiles/config/git/config" "$HOME/.config/git/config"
handle_file_ln "$HOME/.dotfiles/config/git/gitignore" "$HOME/.config/git/gitignore"
handle_file_ln "$HOME/.dotfiles/config/wtf/config.yml" "$HOME/.config/wtf/config.yml"
handle_file_ln "$HOME/.dotfiles/git_profiles" "$HOME/.git_profiles"
handle_file_ln "$HOME/.dotfiles/huskyrc" "$HOME/.huskyrc"
handle_file_ln "$HOME/.dotfiles/local/bin/dotfiles" "$HOME/.local/bin/dotfiles"
handle_file_ln "$HOME/.dotfiles/local/bin/x-check-git-attributes" "$HOME/.local/bin/x-check-git-attributes"
handle_file_ln "$HOME/.dotfiles/local/bin/x-open-ports" "$HOME/.local/bin/x-open-ports"
handle_file_ln "$HOME/.dotfiles/rcrc" "$HOME/.rcrc"
handle_file_ln "$HOME/.dotfiles/ssh/allowed_signers" "$HOME/.ssh/allowed_signers"
handle_file_ln "$HOME/.dotfiles/ssh/config" "$HOME/.ssh/config"
handle_file_ln "$HOME/.dotfiles/vuerc" "$HOME/.vuerc"
handle_file_ln "$HOME/.dotfiles/zshrc" "$HOME/.zshrc"

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash
#
# Settler - my macOS setup automator
# Ismo Vuorinen <https://github.com/ivuorinen> 2018
# Ask for the administrator password upfront
sudo -v
@@ -42,8 +43,8 @@ else
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
bash ../local/bin/dotfiles brew install && "Installed Brewfile contents"
bash ../local/bin/dotfiles dotfiles link && "Linked all dotfiles"
bash ../local/bin/dfm brew install && "Installed Brewfile contents"
bash ../local/bin/dfm dotfiles link && "Linked all dotfiles"
read -r -p "Do you want to set macOS defaults? (y/N) " yn