mirror of
https://github.com/wavetermdev/homebrew-cask.git
synced 2026-08-05 13:43:24 -07:00
Merge pull request #2563 from rolandwalker/devscript_functions
refactor bash scripts into functions
This commit is contained in:
@@ -3,54 +3,34 @@
|
||||
# develop_brew_cask
|
||||
#
|
||||
|
||||
set -e; # exit on any uncaught error
|
||||
set +o histexpand; # don't expand history expressions
|
||||
set -e; # exit on any uncaught error
|
||||
set +o histexpand; # don't expand history expressions
|
||||
shopt -s nocasematch; # case-insensitive regular expressions
|
||||
|
||||
tap_subdir="Library/Taps/phinze-cask"
|
||||
cd_to_project_root () {
|
||||
local script_dir="$(/usr/bin/dirname $0)"
|
||||
cd "$script_dir"
|
||||
local git_root="$(git rev-parse --show-toplevel)"
|
||||
if [[ -z "$git_root" ]]; then
|
||||
printf "Could not find git project root"
|
||||
exit 1;
|
||||
fi
|
||||
cd "$git_root"
|
||||
}
|
||||
|
||||
if [[ $1 =~ ^-+h(elp)?$ ]]; then
|
||||
printf "develop_brew_cask
|
||||
cd_to_version_dir () {
|
||||
local cellar_dir="$1"
|
||||
local version_dir="$2"
|
||||
if [ -z "$version_dir" ]; then
|
||||
printf "Can't get version dir under $cellar_dir/\n";
|
||||
exit 1;
|
||||
fi
|
||||
cd "$cellar_dir/$version_dir"
|
||||
}
|
||||
|
||||
Symlink private repo directories into Homebrew's Cellar, so
|
||||
that the 'brew cask' command will use the current development
|
||||
branch in your private repo.
|
||||
|
||||
Saves the production Homebrew directories under new names.
|
||||
|
||||
You can reverse this operation with 'production_brew_cask'.
|
||||
|
||||
Note: it is not safe to run 'brew update' while development
|
||||
mode is in effect.
|
||||
|
||||
"
|
||||
exit
|
||||
fi
|
||||
|
||||
script_dir="$(/usr/bin/dirname $0)"
|
||||
cd "$script_dir"
|
||||
|
||||
git_root="$(git rev-parse --show-toplevel)"
|
||||
brew_prefix="$(brew --prefix)"
|
||||
cellar_dir="$brew_prefix/Cellar/brew-cask"
|
||||
version_dir=$(/bin/ls "$cellar_dir/" | sort | tail -1)
|
||||
tap_dir="$brew_prefix/$tap_subdir"
|
||||
|
||||
# sanity check
|
||||
if [[ $(/usr/bin/stat -L -f '%i' "$tap_dir") -eq $(/usr/bin/stat -L -f '%i' "$git_root") ]]; then
|
||||
printf "\nERROR: run this script in your private repo, not inside Homebrew.\n"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ -z "$version_dir" ]; then
|
||||
echo "Can't get version dir under $cellar_dir/"
|
||||
exit 1;
|
||||
fi
|
||||
cd "$cellar_dir/$version_dir"
|
||||
|
||||
if [ -e "production_rubylib" ]; then
|
||||
echo "brew-cask is already set up for development"
|
||||
exit 1
|
||||
else
|
||||
create_dev_links () {
|
||||
local git_root="$1"
|
||||
local tap_dir="$2"
|
||||
mv rubylib production_rubylib
|
||||
mv Casks production_Casks
|
||||
ln -s "$git_root/Casks" .
|
||||
@@ -60,10 +40,58 @@ else
|
||||
mv Casks production_Casks
|
||||
ln -s "$git_root/Casks" .
|
||||
ln -s "$git_root/lib" .
|
||||
}
|
||||
|
||||
echo "brew-cask is now in development mode"
|
||||
echo "Note: it is not safe 'brew update' while in development mode"
|
||||
_develop_brew_cask () {
|
||||
|
||||
# configurable
|
||||
local tap_subdir="Library/Taps/phinze-cask"
|
||||
|
||||
# initialization
|
||||
cd_to_project_root;
|
||||
local git_root=`pwd`
|
||||
local brew_prefix="$(brew --prefix)"
|
||||
local cellar_dir="$brew_prefix/Cellar/brew-cask"
|
||||
local version_dir=$(/bin/ls "$cellar_dir/" | sort | tail -1)
|
||||
local tap_dir="$brew_prefix/$tap_subdir"
|
||||
|
||||
# sanity check
|
||||
if [[ $(/usr/bin/stat -L -f '%i' "$tap_dir") -eq $(/usr/bin/stat -L -f '%i' "$git_root") ]]; then
|
||||
printf "\nERROR: run this script in your private repo, not inside Homebrew.\n";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# action
|
||||
cd_to_version_dir "$cellar_dir" "$version_dir";
|
||||
if [ -e "production_rubylib" ]; then
|
||||
printf "brew-cask is already set up for development\n";
|
||||
exit 1
|
||||
else
|
||||
create_dev_links "$git_root" "$tap_dir";
|
||||
printf "brew-cask is now in development mode\n"
|
||||
printf "Note: it is not safe to run 'brew update' while in development mode\n"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
if [[ $1 =~ ^-+h(elp)?$ ]]; then
|
||||
printf "develop_brew_cask
|
||||
|
||||
Symlink private repo directories into Homebrew's Cellar, so
|
||||
that the 'brew cask' command will use the current development
|
||||
branch in your private repo.
|
||||
|
||||
Saves the production Homebrew directories under new names.
|
||||
|
||||
You can reverse this operation with 'production_brew_cask'.
|
||||
|
||||
Note: it is not safe to run 'brew update' while development
|
||||
mode is in effect.
|
||||
|
||||
"
|
||||
exit
|
||||
fi
|
||||
|
||||
_develop_brew_cask "$@";
|
||||
|
||||
#
|
||||
|
||||
@@ -26,29 +26,29 @@ _extract_pkg_ids () {
|
||||
}
|
||||
|
||||
if [[ $1 =~ ^-+h(elp)?$ || -z "$1" ]]; then
|
||||
printf "extract_pkg_ids <file.pkg>
|
||||
printf "extract_pkg_ids <file.pkg>
|
||||
|
||||
Given a package file, extract a list of candidate Package IDs
|
||||
which may be useful in a Cask uninstall stanza, eg
|
||||
Given a package file, extract a list of candidate Package IDs
|
||||
which may be useful in a Cask uninstall stanza, eg
|
||||
|
||||
uninstall :pkgutil => 'package.id.goes.here'
|
||||
uninstall :pkgutil => 'package.id.goes.here'
|
||||
|
||||
The given package file need not be installed.
|
||||
The given package file need not be installed.
|
||||
|
||||
The output of this script should be overly inclusive -- not
|
||||
every candidate package id in the output will be needed at
|
||||
uninstall time.
|
||||
The output of this script should be overly inclusive -- not
|
||||
every candidate package id in the output will be needed at
|
||||
uninstall time.
|
||||
|
||||
Package IDs designated by Apple or the Sparkle framework will
|
||||
be omitted.
|
||||
Package IDs designated by Apple or the Sparkle framework will
|
||||
be omitted.
|
||||
|
||||
If a package id is already installed, it will be followed by
|
||||
a plus symbol '(+)' in the output. This can be verified via
|
||||
the command
|
||||
If a package id is already installed, it will be followed by
|
||||
a plus symbol '(+)' in the output. This can be verified via
|
||||
the command
|
||||
|
||||
/usr/sbin/pkgutil --pkg-info 'package.id.goes.here'
|
||||
/usr/sbin/pkgutil --pkg-info 'package.id.goes.here'
|
||||
|
||||
See CONTRIBUTING.md and 'man pkgutil' for more information.
|
||||
See CONTRIBUTING.md and 'man pkgutil' for more information.
|
||||
|
||||
"
|
||||
exit
|
||||
|
||||
@@ -3,46 +3,33 @@
|
||||
# production_brew_cask
|
||||
#
|
||||
|
||||
set -e; # exit on any uncaught error
|
||||
set +o histexpand; # don't expand history expressions
|
||||
set -e; # exit on any uncaught error
|
||||
set +o histexpand; # don't expand history expressions
|
||||
shopt -s nocasematch; # case-insensitive regular expressions
|
||||
|
||||
tap_subdir="Library/Taps/phinze-cask"
|
||||
cd_to_project_root () {
|
||||
local script_dir="$(/usr/bin/dirname $0)"
|
||||
cd "$script_dir"
|
||||
local git_root="$(git rev-parse --show-toplevel)"
|
||||
if [[ -z "$git_root" ]]; then
|
||||
printf "Could not find git project root"
|
||||
exit 1;
|
||||
fi
|
||||
cd "$git_root"
|
||||
}
|
||||
|
||||
if [[ $1 =~ ^-+h(elp)?$ ]]; then
|
||||
printf "production_brew_cask
|
||||
cd_to_version_dir () {
|
||||
local cellar_dir="$1"
|
||||
local version_dir="$2"
|
||||
if [ -z "$version_dir" ]; then
|
||||
printf "Can't get version dir under $cellar_dir/\n";
|
||||
exit 1;
|
||||
fi
|
||||
cd "$cellar_dir/$version_dir"
|
||||
}
|
||||
|
||||
Undo all symlinks created by 'develop_brew_cask' so that
|
||||
the 'brew cask' command will use only released code within
|
||||
Homebrew.
|
||||
|
||||
After running this command it is safe to run 'brew update'.
|
||||
|
||||
"
|
||||
exit
|
||||
fi
|
||||
|
||||
script_dir="$(/usr/bin/dirname $0)"
|
||||
cd "$script_dir"
|
||||
|
||||
git_root="$(git rev-parse --show-toplevel)"
|
||||
brew_prefix="$(brew --prefix)"
|
||||
cellar_dir="$brew_prefix/Cellar/brew-cask"
|
||||
version_dir=$(/bin/ls "$cellar_dir/" | sort | tail -1)
|
||||
tap_dir="$brew_prefix/$tap_subdir"
|
||||
|
||||
# sanity check
|
||||
if [[ $(/usr/bin/stat -L -f '%i' "$tap_dir") -eq $(/usr/bin/stat -L -f '%i' "$git_root") ]]; then
|
||||
printf "\nERROR: run this script in your private repo, not inside Homebrew.\n"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ -z "$version_dir" ]; then
|
||||
echo "Can't get version dir under $cellar_dir/"
|
||||
exit 1;
|
||||
fi
|
||||
cd "$cellar_dir/$version_dir"
|
||||
|
||||
if [ -e "production_rubylib" ]; then
|
||||
remove_dev_links () {
|
||||
local tap_dir="$1"
|
||||
rm rubylib Casks
|
||||
mv production_rubylib rubylib
|
||||
mv production_Casks Casks
|
||||
@@ -50,11 +37,53 @@ if [ -e "production_rubylib" ]; then
|
||||
rm lib Casks
|
||||
mv production_lib lib
|
||||
mv production_Casks Casks
|
||||
echo "brew-cask is now in production mode"
|
||||
echo "It is safe to run 'brew update'"
|
||||
else
|
||||
echo "brew-cask is already set up for production"
|
||||
exit 1
|
||||
}
|
||||
|
||||
_production_brew_cask () {
|
||||
|
||||
# configurable
|
||||
local tap_subdir="Library/Taps/phinze-cask"
|
||||
|
||||
# initialization
|
||||
cd_to_project_root;
|
||||
local git_root=`pwd`
|
||||
local brew_prefix="$(brew --prefix)"
|
||||
local cellar_dir="$brew_prefix/Cellar/brew-cask"
|
||||
local version_dir=$(/bin/ls "$cellar_dir/" | sort | tail -1)
|
||||
local tap_dir="$brew_prefix/$tap_subdir"
|
||||
|
||||
# sanity check
|
||||
if [[ $(/usr/bin/stat -L -f '%i' "$tap_dir") -eq $(/usr/bin/stat -L -f '%i' "$git_root") ]]; then
|
||||
printf "\nERROR: run this script in your private repo, not inside Homebrew.\n"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# action
|
||||
cd_to_version_dir "$cellar_dir" "$version_dir";
|
||||
if [ -e "production_rubylib" ]; then
|
||||
remove_dev_links "$tap_dir";
|
||||
printf "brew-cask is now in production mode\n"
|
||||
printf "It is safe to run 'brew update'\n"
|
||||
else
|
||||
printf "brew-cask is already set up for production\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
if [[ $1 =~ ^-+h(elp)?$ ]]; then
|
||||
printf "production_brew_cask
|
||||
|
||||
Undo all symlinks created by 'develop_brew_cask' so that
|
||||
the 'brew cask' command will use only released code within
|
||||
Homebrew.
|
||||
|
||||
After running this command it is safe to run 'brew update'.
|
||||
|
||||
"
|
||||
exit
|
||||
fi
|
||||
|
||||
_production_brew_cask "$@";
|
||||
|
||||
#
|
||||
|
||||
+93
-78
@@ -5,98 +5,113 @@
|
||||
# stats on project/release from git database
|
||||
#
|
||||
|
||||
set -e # exit on any uncaught error
|
||||
set +o histexpand # don't expand history expressions
|
||||
shopt -s nocasematch
|
||||
set -e; # exit on any uncaught error
|
||||
set +o histexpand; # don't expand history expressions
|
||||
shopt -s nocasematch; # case-insensitive regular expressions
|
||||
|
||||
start_object="5a0d1d5556e3f963a0d34da46e16ecffa59ea2fc" # initial commit
|
||||
end_object="HEAD"
|
||||
cd_to_project_root () {
|
||||
local script_dir="$(/usr/bin/dirname $0)"
|
||||
cd "$script_dir"
|
||||
local git_root="$(git rev-parse --show-toplevel)"
|
||||
if [[ -z "$git_root" ]]; then
|
||||
printf "Could not find git project root"
|
||||
exit 1;
|
||||
fi
|
||||
cd "$git_root"
|
||||
}
|
||||
|
||||
# these paths relative to project root
|
||||
cask_paths="Casks"
|
||||
code_paths="bin developer lib test brew-cask.rb Rakefile Gemfile Gemfile.lock"
|
||||
doc_paths="LICENSE *.md"
|
||||
warn_if_off_branch () {
|
||||
local branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||
local wanted_branch='master'
|
||||
if [[ -n "$1" ]]; then
|
||||
wanted_branch="$1"
|
||||
fi
|
||||
if [[ "$branch" != "$wanted_branch" ]]; then
|
||||
printf "\nWARNING: you are running from branch '$branch', not '$wanted_branch'\n\n"
|
||||
fi
|
||||
}
|
||||
|
||||
# cd to project root
|
||||
script_dir="$(/usr/bin/dirname $0)"
|
||||
cd "$script_dir"
|
||||
git_root="$(git rev-parse --show-toplevel)"
|
||||
cd "$git_root"
|
||||
verify_git_object () {
|
||||
if ! git rev-parse --verify "$1" > /dev/null 2>/dev/null; then
|
||||
printf "\nERROR: No such commit object: $1\n\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# remember initial commit hash
|
||||
git_log_alltime="git log --format='%ae' ${start_object}..${end_object}"
|
||||
_homebrew_cask_project_stats () {
|
||||
|
||||
###
|
||||
### main
|
||||
###
|
||||
local initial_commit="5a0d1d5556e3f963a0d34da46e16ecffa59ea2fc"
|
||||
local start_object="$initial_commit"
|
||||
local end_object="HEAD"
|
||||
|
||||
# these paths relative to project root
|
||||
local cask_paths="Casks"
|
||||
local code_paths="bin developer lib test brew-cask.rb Rakefile Gemfile Gemfile.lock"
|
||||
local doc_paths="LICENSE *.md"
|
||||
|
||||
cd_to_project_root;
|
||||
warn_if_off_branch 'master';
|
||||
|
||||
if [[ "$1" = 'release' ]]; then
|
||||
start_object="$(git describe --tags --abbrev=0)"
|
||||
elif [[ -n "$1" ]]; then
|
||||
start_object="$1"
|
||||
fi
|
||||
verify_git_object "$start_object";
|
||||
|
||||
printf "Unique contributors"
|
||||
if [[ "$start_object" != "$initial_commit" ]]; then
|
||||
printf " since $start_object"
|
||||
fi
|
||||
printf "\n"
|
||||
|
||||
local git_log_cmd="git log --format='%ae' ${start_object}..${end_object}"
|
||||
|
||||
local cask_authors="$($git_log_cmd -- $cask_paths | sort | uniq | wc -l)"
|
||||
printf " Casks\t$cask_authors\n"
|
||||
printf " code\t"
|
||||
$git_log_cmd -- $code_paths | sort | uniq | wc -l
|
||||
printf " docs\t"
|
||||
$git_log_cmd -- $doc_paths | sort | uniq | wc -l
|
||||
printf " any\t"
|
||||
$git_log_cmd -- . | sort | uniq | wc -l
|
||||
if [[ "$start_object" != "$initial_commit" ]]; then
|
||||
printf "\nAll-time contributors\t"
|
||||
git log --format='%ae' ${initial_commit}..${end_object} -- . | sort | uniq | wc -l
|
||||
fi
|
||||
|
||||
printf "\n"
|
||||
|
||||
if [[ "$start_object" != "$initial_commit" ]]; then
|
||||
local new_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^A.*\.rb' | cut -f2 | sort | uniq | wc -l)"
|
||||
local updated_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^M.*\.rb' | cut -f2 | sort | uniq | wc -l)"
|
||||
# arithmetic removes whitespace
|
||||
((cask_authors += 0))
|
||||
((new_casks += 0))
|
||||
((updated_casks += 0))
|
||||
printf "$new_casks Casks added ($updated_casks updated) by $cask_authors contributors since $start_object\n"
|
||||
fi
|
||||
|
||||
printf "Total current Casks in HEAD\t"
|
||||
find $cask_paths -name '*.rb' | wc -l
|
||||
|
||||
}
|
||||
|
||||
if [[ $1 =~ ^-+h(elp)?$ ]]; then
|
||||
printf "project_stats
|
||||
printf "project_stats [ <commit-object> ]
|
||||
|
||||
Usage:
|
||||
With optional single argument, (eg a tag or commit-hash)
|
||||
show statistics since that commit object.
|
||||
|
||||
project_stats [ <commit-object> ]
|
||||
Use the special argument 'release' to calculate since the
|
||||
most recent tag (usually the same as the last release).
|
||||
|
||||
With optional single argument, (eg a tag or commit-hash)
|
||||
show statistics since that commit object.
|
||||
|
||||
Use the special argument 'release' to calculate since the
|
||||
most recent tag (usually the same as the last release).
|
||||
|
||||
Without argument, show statistics since first commit.
|
||||
Without argument, show statistics since first commit.
|
||||
|
||||
"
|
||||
exit
|
||||
fi
|
||||
|
||||
branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||
if [[ "$branch" != "master" ]]; then
|
||||
printf "\nWARNING: you are running from branch '$branch', not 'master'\n\n"
|
||||
fi
|
||||
|
||||
printf "Unique contributors"
|
||||
if [[ "$1" = 'release' ]]; then
|
||||
start_object="$(git describe --tags --abbrev=0)"
|
||||
printf " since $start_object"
|
||||
elif [[ -n "$1" ]]; then
|
||||
start_object="$1"
|
||||
printf " since $start_object"
|
||||
fi
|
||||
printf "\n"
|
||||
|
||||
if ! git rev-parse --verify "$start_object" > /dev/null 2>/dev/null; then
|
||||
printf "\nERROR: No such commit object: $start_object\n\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git_log="git log --format='%ae' ${start_object}..${end_object}"
|
||||
|
||||
cask_authors="$($git_log -- $cask_paths | sort | uniq | wc -l)"
|
||||
printf " Casks\t$cask_authors\n"
|
||||
|
||||
printf " code\t"
|
||||
$git_log -- $code_paths | sort | uniq | wc -l
|
||||
printf " docs\t"
|
||||
$git_log -- $doc_paths | sort | uniq | wc -l
|
||||
printf " any\t"
|
||||
$git_log -- . | sort | uniq | wc -l
|
||||
if [[ -n "$1" ]]; then
|
||||
printf "\nAll-time contributors\t"
|
||||
$git_log_alltime -- . | sort | uniq | wc -l
|
||||
fi
|
||||
|
||||
printf "\n"
|
||||
|
||||
if [[ -n "$1" ]]; then
|
||||
new_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^A.*\.rb' | cut -f2 | sort | uniq | wc -l)"
|
||||
updated_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^M.*\.rb' | cut -f2 | sort | uniq | wc -l)"
|
||||
((cask_authors += 0))
|
||||
((new_casks += 0))
|
||||
((updated_casks += 0))
|
||||
printf "$new_casks Casks added ($updated_casks updated) by $cask_authors contributors since $start_object\n"
|
||||
fi
|
||||
|
||||
printf "Total current Casks in HEAD\t"
|
||||
find $cask_paths -name '*.rb' | wc -l
|
||||
_homebrew_cask_project_stats "$@";
|
||||
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user