mirror of
https://github.com/wavetermdev/homebrew-cask.git
synced 2026-08-05 13:43:24 -07:00
devscripts: general hardening of shell scripts
- full paths to utils - $() construct - quoting - prefer double square brackets
This commit is contained in:
@@ -21,7 +21,7 @@ cd_to_project_root () {
|
||||
cd_to_version_dir () {
|
||||
local cellar_dir="$1"
|
||||
local version_dir="$2"
|
||||
if [ -z "$version_dir" ]; then
|
||||
if [[ -z "$version_dir" ]]; then
|
||||
printf "Can't get version dir under $cellar_dir/\n";
|
||||
exit 1;
|
||||
fi
|
||||
@@ -31,15 +31,15 @@ cd_to_version_dir () {
|
||||
create_dev_links () {
|
||||
local git_root="$1"
|
||||
local tap_dir="$2"
|
||||
mv rubylib production_rubylib
|
||||
mv Casks production_Casks
|
||||
ln -s "$git_root/Casks" .
|
||||
ln -s "$git_root/lib" rubylib
|
||||
/bin/mv rubylib production_rubylib
|
||||
/bin/mv Casks production_Casks
|
||||
/bin/ln -s "$git_root/Casks" .
|
||||
/bin/ln -s "$git_root/lib" rubylib
|
||||
cd "$tap_dir"
|
||||
mv lib production_lib
|
||||
mv Casks production_Casks
|
||||
ln -s "$git_root/Casks" .
|
||||
ln -s "$git_root/lib" .
|
||||
/bin/mv lib production_lib
|
||||
/bin/mv Casks production_Casks
|
||||
/bin/ln -s "$git_root/Casks" .
|
||||
/bin/ln -s "$git_root/lib" .
|
||||
}
|
||||
|
||||
_develop_brew_cask () {
|
||||
@@ -49,21 +49,21 @@ _develop_brew_cask () {
|
||||
|
||||
# initialization
|
||||
cd_to_project_root;
|
||||
local git_root=`pwd`
|
||||
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 version_dir="$(/bin/ls "$cellar_dir/" | /usr/bin/sort | /usr/bin/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
|
||||
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
|
||||
if [[ -e "production_rubylib" ]]; then
|
||||
printf "brew-cask is already set up for development\n";
|
||||
exit 1
|
||||
else
|
||||
|
||||
@@ -21,7 +21,7 @@ cd_to_project_root () {
|
||||
cd_to_version_dir () {
|
||||
local cellar_dir="$1"
|
||||
local version_dir="$2"
|
||||
if [ -z "$version_dir" ]; then
|
||||
if [[ -z "$version_dir" ]]; then
|
||||
printf "Can't get version dir under $cellar_dir/\n";
|
||||
exit 1;
|
||||
fi
|
||||
@@ -30,13 +30,13 @@ cd_to_version_dir () {
|
||||
|
||||
remove_dev_links () {
|
||||
local tap_dir="$1"
|
||||
rm rubylib Casks
|
||||
mv production_rubylib rubylib
|
||||
mv production_Casks Casks
|
||||
/bin/rm rubylib Casks
|
||||
/bin/mv production_rubylib rubylib
|
||||
/bin/mv production_Casks Casks
|
||||
cd "$tap_dir"
|
||||
rm lib Casks
|
||||
mv production_lib lib
|
||||
mv production_Casks Casks
|
||||
/bin/rm lib Casks
|
||||
/bin/mv production_lib lib
|
||||
/bin/mv production_Casks Casks
|
||||
}
|
||||
|
||||
_production_brew_cask () {
|
||||
@@ -46,21 +46,21 @@ _production_brew_cask () {
|
||||
|
||||
# initialization
|
||||
cd_to_project_root;
|
||||
local git_root=`pwd`
|
||||
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 version_dir="$(/bin/ls "$cellar_dir/" | /usr/bin/sort | /usr/bin/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
|
||||
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
|
||||
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"
|
||||
|
||||
@@ -67,25 +67,25 @@ _homebrew_cask_project_stats () {
|
||||
|
||||
local git_log_cmd="git log --no-merges --format='%ae' ${start_object}..${end_object}"
|
||||
|
||||
local cask_authors="$($git_log_cmd -- $cask_paths | sort | uniq | wc -l)"
|
||||
local cask_authors="$($git_log_cmd -- $cask_paths | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l)"
|
||||
printf " Casks\t$cask_authors\n"
|
||||
printf " code\t"
|
||||
$git_log_cmd -- $code_paths | sort | uniq | wc -l
|
||||
$git_log_cmd -- $code_paths | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l
|
||||
printf " docs\t"
|
||||
$git_log_cmd -- $doc_paths | sort | uniq | wc -l
|
||||
$git_log_cmd -- $doc_paths | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l
|
||||
printf " any\t"
|
||||
$git_log_cmd -- . | sort | uniq | wc -l
|
||||
$git_log_cmd -- . | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l
|
||||
if [[ "$start_object" != "$initial_commit" ]]; then
|
||||
printf "\nAll-time contributors\t"
|
||||
git log --no-merges --format='%ae' ${initial_commit}..${end_object} -- . | sort | uniq | wc -l
|
||||
git log --no-merges --format='%ae' ${initial_commit}..${end_object} -- . | /usr/bin/sort | /usr/bin/uniq | /usr/bin/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 deleted_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^D.*\.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)"
|
||||
local new_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^A.*\.rb' | cut -f2 | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l)"
|
||||
local deleted_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^D.*\.rb' | cut -f2 | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l)"
|
||||
local updated_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^M.*\.rb' | cut -f2 | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l)"
|
||||
# arithmetic removes whitespace
|
||||
((cask_authors += 0))
|
||||
((deleted_casks += 0))
|
||||
@@ -95,7 +95,7 @@ _homebrew_cask_project_stats () {
|
||||
fi
|
||||
|
||||
printf "Total current Casks in HEAD\t"
|
||||
find $cask_paths -name '*.rb' | wc -l
|
||||
/usr/bin/find $cask_paths -name '*.rb' | /usr/bin/wc -l
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user