generated from me/template-mit
Compare commits
39 Commits
be0469fb94
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e4f76dc58 | |||
| eb63e0321c | |||
| c9889f6a23 | |||
| 20b130e931 | |||
| de6ca756da | |||
| 332631e3dd | |||
| a6b5cd9297 | |||
| 14ce936e9b | |||
| 79a35be993 | |||
| 0c54259a38 | |||
| 4791e1c168 | |||
| 9d604c6e90 | |||
| cf1b7a160a | |||
| 74d727faa9 | |||
| 56969e9ee9 | |||
| 340667329c | |||
| e1d9b6cf94 | |||
| 71875470c2 | |||
| 1989377b8b | |||
| 6887a1e131 | |||
| 209af03777 | |||
| 21b2ddf4a5 | |||
| 890bc05e4d | |||
| e2ec550fab | |||
| 495a140805 | |||
| 9d609568f7 | |||
| 391b0a0b09 | |||
| a76cb8b5ec | |||
| a87c205a80 | |||
| 186519fb0e | |||
| 7fa1430b34 | |||
| 074f0a29bf | |||
| bdb06cd0b4 | |||
| ec9b74d3d8 | |||
| 0bfdc8d411 | |||
| 89c0d0589c | |||
| 3edd062852 | |||
| bc81d1bedd | |||
| c859b4dcd8 |
@@ -13,8 +13,8 @@ dir="`basename $DIR`"
|
|||||||
|
|
||||||
## Validations ##
|
## Validations ##
|
||||||
|
|
||||||
if [[ "$DIR" != *"-clone" ]]; then
|
if [[ "$DIR" != *"-clone" && "$DIR" != *"-SYNC" ]]; then
|
||||||
echo "'$DIR' is not labeled as a clone. Skipping download."
|
echo "'$DIR' is not labeled as a CLONE or SYNC. Skipping download."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ dir="`basename $DIR`"
|
|||||||
|
|
||||||
## Validations ##
|
## Validations ##
|
||||||
|
|
||||||
if [[ "$DIR" != *"-MASTER" ]]; then
|
if [[ "$DIR" != *"-MASTER" && "$DIR" != *"-SYNC" ]]; then
|
||||||
echo "'$DIR' is not labeled as a MASTER. Skipping upload."
|
echo "'$DIR' is not labeled as a MASTER or SYNC. Skipping upload."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
270
rc_shared.sh
270
rc_shared.sh
@@ -37,6 +37,20 @@ alias l='ls '
|
|||||||
alias ll='ls -alh '
|
alias ll='ls -alh '
|
||||||
alias lh='ls -ash '
|
alias lh='ls -ash '
|
||||||
|
|
||||||
|
function cl {
|
||||||
|
if [[ -d /sdcard ]]; then
|
||||||
|
cd /sdcard/Library/Clones
|
||||||
|
else
|
||||||
|
cd $HOME/Clones
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
alias clones="cl"
|
||||||
|
alias cdl="cl"
|
||||||
|
alias cdc="cl"
|
||||||
|
|
||||||
|
alias library="clones && cd .."
|
||||||
|
alias lib="library"
|
||||||
|
|
||||||
# Networking #
|
# Networking #
|
||||||
|
|
||||||
alias scan="nmap -A -p- --script=vuln "
|
alias scan="nmap -A -p- --script=vuln "
|
||||||
@@ -46,11 +60,19 @@ alias scan="nmap -A -p- --script=vuln "
|
|||||||
|
|
||||||
# Related specifically to this project. #
|
# Related specifically to this project. #
|
||||||
|
|
||||||
function update-shared {
|
branch="$BRANCH"
|
||||||
log "`date` - Reloading the '~/.rc_shared' file from env-shared.\n"
|
if [[ -z "$branch" ]]; then
|
||||||
branch="$1"
|
branch="$PROD_GIT_BRANCH"
|
||||||
if [[ -z "$branch" ]]; then
|
fi
|
||||||
|
if [[ -z "$branch" ]]; then
|
||||||
branch="dev"
|
branch="dev"
|
||||||
|
fi
|
||||||
|
|
||||||
|
function update-shared-old {
|
||||||
|
log "`date` - Reloading the '~/.rc_shared' file from env-shared.\n"
|
||||||
|
|
||||||
|
if [[ -n "$1" ]]; then
|
||||||
|
branch="$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dir="shared-rc-deleteme"
|
dir="shared-rc-deleteme"
|
||||||
@@ -60,18 +82,123 @@ function update-shared {
|
|||||||
|
|
||||||
mv -v $dir/rc_shared.sh ~/.rc_shared
|
mv -v $dir/rc_shared.sh ~/.rc_shared
|
||||||
|
|
||||||
|
local_bin="$HOME/bin"
|
||||||
|
remote_bin="shared-rc-deleteme/bin-shared"
|
||||||
|
if [[ -d "$local_bin" ]]; then
|
||||||
|
log "\n`date` - Found '$local_bin', adding scripts.\n"
|
||||||
|
mv -v $remote_bin/*.sh "$local_bin"/
|
||||||
|
|
||||||
|
refactor_script="refactor_music_library.sh"
|
||||||
|
wget -O "$refactor_script" \
|
||||||
|
https://git.hyperling.com/me/shell-music-refactor-library/raw/branch/main/refactor_music_library.sh
|
||||||
|
mv -v $refactor_script "$local_bin"/
|
||||||
|
|
||||||
|
chmod 755 -Rv "$local_bin"
|
||||||
|
else
|
||||||
|
echo "Did not find '$local_bin', did not copy scripts."
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "\n`date` - Done! Removing git clone.\n"
|
||||||
mv -v $dir ~/TRASH/"$dir-`date "+%Y%m%d-%H%M%S"`"
|
mv -v $dir ~/TRASH/"$dir-`date "+%Y%m%d-%H%M%S"`"
|
||||||
|
|
||||||
log "\n`date` - Complete! Please note this does NOT update bin files."
|
log "\n`date` - Complete!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project="$HOME/.env-shared"
|
||||||
|
function update-shared2 {
|
||||||
|
if [[ -d $project ]]; then
|
||||||
|
log "`date` - Updating '$project'.\n"
|
||||||
|
git -C "$project" switch "$branch"
|
||||||
|
git -C "$project" pull --recurse-submodules || \
|
||||||
|
( echo "Failed to pull project, exiting." && return 1 )
|
||||||
|
else
|
||||||
|
log "`date` - Downloading '$project'.\n"
|
||||||
|
git clone https://git.hyperling.com/me/env-shared \
|
||||||
|
"$project" --branch=$branch
|
||||||
|
fi
|
||||||
|
|
||||||
|
local_bin="$HOME/bin"
|
||||||
|
remote_bin="$project/bin-shared"
|
||||||
|
if [[ -d "$local_bin" ]]; then
|
||||||
|
log "\n`date` - Found '$local_bin', adding scripts.\n"
|
||||||
|
cp -v $remote_bin/*.sh "$local_bin"/
|
||||||
|
|
||||||
|
refactor_script="refactor_music_library.sh"
|
||||||
|
wget -O "$refactor_script" \
|
||||||
|
https://git.hyperling.com/me/shell-music-refactor-library/raw/branch/main/refactor_music_library.sh
|
||||||
|
mv -v $refactor_script "$local_bin"/
|
||||||
|
|
||||||
|
chmod 755 -Rv "$local_bin"
|
||||||
|
else
|
||||||
|
echo "Did not find '$local_bin', did not copy scripts."
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "\n`date` - Complete!"
|
||||||
|
}
|
||||||
|
alias shared-update2="update-shared2"
|
||||||
|
alias reload-shared2="update-shared2"
|
||||||
|
alias shared-reload2="update-shared2"
|
||||||
|
|
||||||
|
alias update-shared="update-shared2"
|
||||||
alias shared-update="update-shared"
|
alias shared-update="update-shared"
|
||||||
alias reload-shared="update-shared"
|
alias reload-shared="update-shared"
|
||||||
alias shared-reload="update-shared"
|
alias shared-reload="update-shared"
|
||||||
|
|
||||||
|
function reload-all {
|
||||||
|
log "`date` - Reloading BASH"
|
||||||
|
reload-bash
|
||||||
|
|
||||||
|
log "\n`date` - Reloading Main (Termux/Ansible)"
|
||||||
|
if [[ -d /sdcard ]]; then
|
||||||
|
reload-termux
|
||||||
|
else
|
||||||
|
scm.sh
|
||||||
|
fi
|
||||||
|
reload-bash
|
||||||
|
|
||||||
|
log "\n`date` - Reloading Shared"
|
||||||
|
reload-shared
|
||||||
|
reload-bash
|
||||||
|
}
|
||||||
|
alias all-reload="reload-all"
|
||||||
|
|
||||||
|
function update-all {
|
||||||
|
log "`date` - Updating env projects..."
|
||||||
|
reload-all
|
||||||
|
|
||||||
|
log "\n\n\n`date` - Running system updates..."
|
||||||
|
update -y
|
||||||
|
|
||||||
|
if [[ $(type -t update-sdk 2>/dev/null 1>&2) ]]; then
|
||||||
|
log "\n\n\n`date` - Updating SDKs..."
|
||||||
|
update-sdk
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "\n\n\n`date` - Done with update-all!"
|
||||||
|
}
|
||||||
|
alias all-update="update-all"
|
||||||
|
|
||||||
# Shortcuts #
|
# Shortcuts #
|
||||||
|
|
||||||
function send-master { send_master.sh; }
|
function send-master { send_master.sh; }
|
||||||
|
alias push-master="send-master"
|
||||||
|
alias sync-master="send-master"
|
||||||
|
|
||||||
function pull-clone { pull_clone.sh; }
|
function pull-clone { pull_clone.sh; }
|
||||||
|
alias get-clone="pull-clone"
|
||||||
|
alias sync-clone="pull-clone"
|
||||||
|
|
||||||
|
alias send-sync="send-master"
|
||||||
|
alias push-sync="send-master"
|
||||||
|
alias pull-sync="pull-clone"
|
||||||
|
alias get-sync="pull-clone"
|
||||||
|
function sync-sync {
|
||||||
|
cat <<- EOF
|
||||||
|
Command not implemented, too dangerous guessing the state of the folder.
|
||||||
|
|
||||||
|
Please use push-sync and pull-sync in the correct order for its current state.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
function goodbye { update -y; bye; }
|
function goodbye { update -y; bye; }
|
||||||
|
|
||||||
@@ -82,11 +209,32 @@ function clone {
|
|||||||
function now { date "+%Y%m%d-%H%M%S"; }
|
function now { date "+%Y%m%d-%H%M%S"; }
|
||||||
function today { date "+%Y%m%d"; }
|
function today { date "+%Y%m%d"; }
|
||||||
|
|
||||||
|
function log { echo -e "$1"; }
|
||||||
|
function blog { echo -e "\n\n$1\n\n"; }
|
||||||
|
|
||||||
|
function pull {
|
||||||
|
if [[ -d .git ]]; then
|
||||||
|
git pull --recurse-submodules
|
||||||
|
else
|
||||||
|
pull-clone
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function push {
|
||||||
|
if [[ -d .git ]]; then
|
||||||
|
git push && load-stage && load-prod
|
||||||
|
else
|
||||||
|
send-master
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Enhance Bin Scripts #
|
# Enhance Bin Scripts #
|
||||||
|
|
||||||
|
# MASTER and CLONE folders.
|
||||||
|
|
||||||
function send-masters {
|
function send-masters {
|
||||||
echo -e "`date` - Looping through MASTER directories."
|
echo -e "`date` - Looping through MASTER directories."
|
||||||
ls | grep '\-MASTER' | while read dir; do
|
ls | grep "\-MASTER" | while read dir; do
|
||||||
echo -e "\n`date` - Found '$dir'..."
|
echo -e "\n`date` - Found '$dir'..."
|
||||||
cd $dir
|
cd $dir
|
||||||
send-master
|
send-master
|
||||||
@@ -94,10 +242,12 @@ function send-masters {
|
|||||||
done
|
done
|
||||||
echo -e "\n`date` - Done checking for MASTER directories."
|
echo -e "\n`date` - Done checking for MASTER directories."
|
||||||
}
|
}
|
||||||
|
alias push-masters="send-masters"
|
||||||
|
alias sync-masters="send-masters"
|
||||||
|
|
||||||
function pull-clones {
|
function pull-clones {
|
||||||
echo -e "`date` - Looping through clone directories."
|
echo -e "`date` - Looping through clone directories."
|
||||||
ls | grep '\-clone' | while read dir; do
|
ls | grep "\-clone" | while read dir; do
|
||||||
echo -e "\n`date` - Found '$dir'..."
|
echo -e "\n`date` - Found '$dir'..."
|
||||||
cd $dir
|
cd $dir
|
||||||
pull-clone
|
pull-clone
|
||||||
@@ -105,6 +255,71 @@ function pull-clones {
|
|||||||
done
|
done
|
||||||
echo -e "\n`date` - Done checking for clone directories."
|
echo -e "\n`date` - Done checking for clone directories."
|
||||||
}
|
}
|
||||||
|
alias get-clones="pull-clones"
|
||||||
|
alias sync-clones="pull-clones"
|
||||||
|
|
||||||
|
function sync-all {
|
||||||
|
push-masters
|
||||||
|
echo -e "\n"
|
||||||
|
pull-clones
|
||||||
|
|
||||||
|
echo -e "\n`date` - Skipping SYNC folders! Please do their loads separately."
|
||||||
|
ls | grep "\-SYNC" | while read dir; do
|
||||||
|
echo "- $dir"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "`date` - Done.\n"
|
||||||
|
}
|
||||||
|
function sync-all-loop {
|
||||||
|
typeset -i sleep_time
|
||||||
|
if [[ "$1" ]]; then
|
||||||
|
sleep_time="$1"
|
||||||
|
fi
|
||||||
|
if [[ -z "$sleep_time" || "$sleep_time" == 0 ]]; then
|
||||||
|
sleep_time="300"
|
||||||
|
fi
|
||||||
|
log "`date` - Sleep timer set for '$sleep_time' seconds."
|
||||||
|
while true; do
|
||||||
|
sync-all
|
||||||
|
echo -e "\n\n*** Sleeping... ***\n\n"
|
||||||
|
sleep 300
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# SYNC folders.
|
||||||
|
|
||||||
|
function send-syncs {
|
||||||
|
echo -e "`date` - Looping through SYNC directories."
|
||||||
|
ls | grep "\-SYNC" | while read dir; do
|
||||||
|
echo -e "\n`date` - Found '$dir'..."
|
||||||
|
cd $dir
|
||||||
|
send-master
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
echo -e "\n`date` - Done checking for SYNC directories."
|
||||||
|
}
|
||||||
|
alias push-syncs="send-syncs"
|
||||||
|
|
||||||
|
function pull-syncs {
|
||||||
|
echo -e "`date` - Looping through SYNC directories."
|
||||||
|
ls | grep "\-SYNC" | while read dir; do
|
||||||
|
echo -e "\n`date` - Found '$dir'..."
|
||||||
|
cd $dir
|
||||||
|
pull-clone
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
echo -e "\n`date` - Done checking for SYNC directories."
|
||||||
|
}
|
||||||
|
alias get-syncs="pull-syncs"
|
||||||
|
|
||||||
|
function sync-syncs {
|
||||||
|
cat <<- EOF
|
||||||
|
Command not implemented, too dangerous guessing the state of the folder.
|
||||||
|
|
||||||
|
Please use push-syncs and pull-syncs in the correct order for its current state.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Audio #
|
# Audio #
|
||||||
|
|
||||||
@@ -213,9 +428,11 @@ function process-video {
|
|||||||
mv -v ffmpeg2pass*.log* ~/TRASH/
|
mv -v ffmpeg2pass*.log* ~/TRASH/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "`date` - Syncing data."
|
||||||
sync
|
sync
|
||||||
sleep 10
|
sleep 10
|
||||||
sync
|
sync
|
||||||
|
|
||||||
if [[ -s $newfile ]]; then
|
if [[ -s $newfile ]]; then
|
||||||
echo "`date` - Getting file sizes."
|
echo "`date` - Getting file sizes."
|
||||||
du -h "$file"
|
du -h "$file"
|
||||||
@@ -228,7 +445,7 @@ function process-video {
|
|||||||
return $status
|
return $status
|
||||||
}
|
}
|
||||||
alias pv="process-video"
|
alias pv="process-video"
|
||||||
alias qpv="pv ./raw/YouCut*.mp4 `basename $(pwd)`.mp4"
|
alias qpv="pv ./raw/YouCut*.mp4 $(basename `pwd`).mp4"
|
||||||
|
|
||||||
# Allow converting video to audio and other smaller
|
# Allow converting video to audio and other smaller
|
||||||
# tasks than what process-video is intended to do.
|
# tasks than what process-video is intended to do.
|
||||||
@@ -329,9 +546,46 @@ alias vta="v2a"
|
|||||||
alias pull-audio="v2a"
|
alias pull-audio="v2a"
|
||||||
alias pa="v2a"
|
alias pa="v2a"
|
||||||
|
|
||||||
|
|
||||||
|
## Trash Related ##
|
||||||
|
|
||||||
|
TRASH_ROOT="/"
|
||||||
|
if [[ -d "/sdcard" ]]; then
|
||||||
|
# Android / Termux
|
||||||
|
TRASH_ROOT="/sdcard"
|
||||||
|
else
|
||||||
|
# Desktop
|
||||||
|
TRASH_ROOT="$HOME"
|
||||||
|
fi
|
||||||
|
TRASH="$TRASH_ROOT/TRASH"
|
||||||
|
|
||||||
|
alias trash="cd $TRASH"
|
||||||
|
|
||||||
|
alias clean-trash="bash -c 'rm -rfv "$TRASH"/*'; clean-trashed"
|
||||||
|
alias trash-clean="clean-trash"
|
||||||
|
|
||||||
|
alias check-trash='du -h $TRASH; find "$TRASH_ROOT" -name .Trash"*" -exec du -h {} \; -exec mv -v {} "$TRASH"/ \;'
|
||||||
|
alias trash-check="check-trash"
|
||||||
|
|
||||||
|
alias check-trashed='find "$TRASH_ROOT" -name ".trashed*" -exec du -h {} \; -exec mv -v {} "$TRASH"/ \; | sort -h'
|
||||||
|
alias clean-trashed='find "$TRASH_ROOT" -name ".trashed*" -exec du -h {} \; -delete | sort -h'
|
||||||
|
|
||||||
|
|
||||||
|
## Finalize ##
|
||||||
|
|
||||||
# Export all functions! #
|
# Export all functions! #
|
||||||
eval "$(declare -F | grep -v _ | sed 's/-f /-fx /')"
|
eval "$(declare -F | grep -v _ | sed 's/-f /-fx /')"
|
||||||
|
|
||||||
|
# Run update checker in background.
|
||||||
|
( if [[ -d "$project" ]]; then
|
||||||
|
git -C "$project" fetch >/dev/null 2>&1 && git -C "$project" status | grep "is behind" \
|
||||||
|
| while read status; do
|
||||||
|
log "\n\n`date` - env-shared has been improved."
|
||||||
|
log " '$status'"
|
||||||
|
log "\n\n`date` - Run 'update-shared' to update."
|
||||||
|
done
|
||||||
|
fi & )
|
||||||
|
|
||||||
|
|
||||||
## Complete! ##
|
## Complete! ##
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user