Compare commits

..

23 Commits

Author SHA1 Message Date
16aa8b17cd Change the Termux project to stay put rather than use deleteme's. Add an update checker similar to shared project. 2026-05-05 09:45:11 -07:00
fea3756a0e Download the shared code to its proper location rather than doing a deleteme dump. Use /sdcard/ rather than shared storage links from home directory. 2026-05-05 09:36:29 -07:00
a84fba5a1c Be more consistent about only pulling files with today's date (screenshots, memes, edited photos). 2026-05-05 09:23:11 -07:00
6c9112ef23 Move trash related code to shared env. 2026-04-25 10:33:14 -07:00
c9f2802359 Fix single quote location. 2026-04-18 10:47:42 -07:00
3486e238d4 Add a parameter for the branch that's preferred. 2026-04-17 15:46:21 -07:00
3ed66ea059 Add exporting of all functions, same as done in env-shared. 2026-04-13 19:28:32 -07:00
46e6b205a9 Hide output from .git folder deletion. 2026-03-28 15:17:45 -07:00
ea40967e2b Install the vimrc from shared env project. 2026-03-28 15:13:24 -07:00
86ad8c5b5c Add exports to env setup. 2026-03-28 15:00:41 -07:00
fd227c810c Add verbosity to deleting shared env. 2026-03-28 14:58:23 -07:00
4744d996a1 Fix path to TRASH. 2026-03-28 14:56:48 -07:00
bd0c01fda6 Fix single quote location. 2026-03-28 14:55:44 -07:00
c323748cec Add date to file completion output. 2026-03-28 14:51:51 -07:00
6226d00a1c Change brackets from purple to gray. 2026-03-28 14:49:54 -07:00
f199605915 Remove test code, skip is working now. 2026-03-28 14:48:44 -07:00
6356497cb6 Add more test code to troubleshoot skipping updates. 2026-03-28 14:46:50 -07:00
b7d189af66 Pass reload-termux params to setup.sh. 2026-03-28 14:44:48 -07:00
dbc0a711c4 Add text code to see why skip is not working. 2026-03-28 14:43:21 -07:00
ae636f4fbe Fix deleting shared env project. 2026-03-28 14:39:24 -07:00
42f4ef919f Move now and today t shared env. 2026-03-28 14:24:20 -07:00
2662966098 Move scan to be in shared env. 2026-03-28 14:18:49 -07:00
16ded2672e Move ffmpeg functions to shared. 2026-03-28 14:17:19 -07:00
3 changed files with 80 additions and 285 deletions

296
bashrc.sh
View File

@@ -19,9 +19,14 @@ fi
if [[ "`whoami`" == "root" ]]; then if [[ "`whoami`" == "root" ]]; then
export PS1='\[$BOLD\]\[$ORANGE\][\[$SCARLET\]\t \[$RED\]\w\[$ORANGE\]]\[$GRAY\]\$ \[$RESET\]' export PS1='\[$BOLD\]\[$ORANGE\][\[$SCARLET\]\t \[$RED\]\w\[$ORANGE\]]\[$GRAY\]\$ \[$RESET\]'
else else
export PS1='\[$BOLD\]\[$PURPLE\][\[$ORANGE\]\t \[$GREEN\]\w\[$PURPLE\]]\[$RESET\]\$ ' export PS1='\[$BOLD\]\[$GRAY\][\[$ORANGE\]\t \[$GREEN\]\w\[$GRAY\]]\[$RESET\]\$ '
fi fi
if [[ -z "$BRANCH" ]]; then
export BRANCH="dev"
fi
## Aliases ## ## Aliases ##
# Quickly log onto production server. # Quickly log onto production server.
@@ -53,17 +58,6 @@ alias dcim="cd $DCIM"
export CODE="$SS/Code" export CODE="$SS/Code"
alias code="cd $CODE" alias code="cd $CODE"
# Shortcuts for TRASH.
export TRASH="$SS/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"
alias trash-check="check-trash"
alias clean-trashed='find "$SS" -name ".trashed*" -exec du -h {} \; -delete | sort -h'
alias check-trashed='find "$SS" -name ".trashed*" -exec du -h {} \; -exec mv -v {} ~/TRASH/ \; | sort -h'
# Help prevent mistakes. # Help prevent mistakes.
alias cp="cp -v " alias cp="cp -v "
alias mv="mv -v " alias mv="mv -v "
@@ -74,7 +68,6 @@ function bye { exit; }
alias install="pkg install " alias install="pkg install "
alias uninstall="pkg uninstall " alias uninstall="pkg uninstall "
alias remove="uninstall " alias remove="uninstall "
alias scan="nmap -A -p- --script=vuln "
### Functions ### ### Functions ###
@@ -130,16 +123,26 @@ function commit {
# Easily test this project after committing changes. # Easily test this project after committing changes.
# Otherwise can just source this file unless testing setup.sh. # Otherwise can just source this file unless testing setup.sh.
project="$HOME/.git-env-termux"
function test-termux { function test-termux {
sh -c "rm -rf ~/termux-deleteme ~/TRASH/termux-deleteme" 2>/dev/null if [[ -d "$project" ]]; then
git clone https://git.hyperling.com/me/env-termux \ log "`date` - Updating '$project'.\n"
--branch=dev ~/termux-deleteme git -C "$project" switch "$branch"
chmod 755 ~/termux-deleteme/*.sh git -C "$project" pull --recurse-submodules || \
~/termux-deleteme/setup.sh ( echo "Failed to pull project, exiting." && return 1 )
else
log "`date` - Downloading '$project'.\n"
git clone https://git.hyperling.com/me/env-termux \
--branch=$BRANCH "$project"
fi
chmod 755 "$project"/*.sh
"$project"/setup.sh "$@"
} }
alias reload-termux="test-termux" alias reload-termux="test-termux "
alias termux-test="test-termux" alias termux-test="test-termux "
alias termux-reload="reload-termux" alias termux-reload="reload-termux "
alias termux-update="reload-termux "
alias update-termux="reload-termux "
# Pulled from /me/env-ansible, need to make a shared library between it and Termux. # Pulled from /me/env-ansible, need to make a shared library between it and Termux.
@@ -230,241 +233,21 @@ alias upgrade="update"
alias goodbye="update -y && bye" alias goodbye="update -y && bye"
## Videk Related ## ## Video Related ##
# Optimize the bitrate and audio levels for an edited video.
function process-video-usage {
echo "USAGE: process-video oldFile newFile [videoBitrate] [audioBitrate] [sizeRating] [numPasses] [forceBitrate]"
echo -n "Purpose: Call ffmpeg with preferred video posting settings. "
echo -n "Bitrates default to 2000k and 192k, size is 720, passes is 1, and force is N."
echo "These work well on Odysee and are fairly small as backups."
echo "Examples:"
echo "- Create a small file for quick streaming."
echo " process-video youcut.mp4 20240210.mp4 1200k 128k 480"
echo "- Create a larger file for something like YouTube."
echo " process-video youcut.mp4 20240210_1080p.mp4 5000k 256k 1080"
}
function process-video {
# Parameters
file="$1"
newfile="$2"
video="$3"
audio="$4"
size="$5"
passes="$6"
force="$7"
# Validations
if [[ -z $file || ! -e $file ]]; then
echo "ERROR: Original file '$file' does not exist." >&2
process-video-usage
return 1
fi
if [[ -z $newfile ]]; then
echo "ERROR: New file's name must be provided." >&2
process-video-usage
return 1
elif [[ -e $newfile ]]; then
echo "ERROR: New file '$newfile' already exists." >&2
du -h "$newfile"
process-video-usage
return 1
fi
echo "`date` - Converting '$file' to '$newfile'."
if [[ -z $video ]]; then
video="2000k"
fi
if [[ $force == "Y" ]]; then
video="-b:v $video"
else
video="-b:v $video -minrate 0 -maxrate $video -bufsize $video"
fi
if [[ -z $audio ]]; then
audio="192k"
fi
audio="-b:a $audio"
if [[ -z $size ]]; then
size="720"
fi
size="-filter:v scale=-1:$size"
if [[ -z $passes ]]; then
passes=1
fi
pass=""
if [[ $passes != 1 ]]; then
passes=2
pass="-pass 2"
fi
## Main ##
# More information on two-pass processing with ffmpeg
# https://cinelerra-gg.org/download/CinelerraGG_Manual/Two_pass_Encoding_with_FFmp.html
if [[ $passes == 2 ]]; then
set -x
ffmpeg -nostdin -hide_banner -loglevel quiet \
-i "$file" $size $video $audio \
-filter:a "dynaudnorm=f=33:g=65:p=0.66:m=33.3" \
-vcodec libx264 -movflags +faststart \
-pass 1 -f mp4 /dev/null -y
status=$?
set +x
echo "`date` - Done with the first pass."
if [[ $status != 0 ]]; then
echo "Received unsuccessful status, exiting."
return 1
fi
fi
set -x &&
ffmpeg -nostdin -hide_banner -loglevel quiet \
-i "$file" $size $video $audio \
-filter:a "dynaudnorm=f=33:g=65:p=0.66:m=33.3" \
-vcodec libx264 -movflags +faststart \
$pass "$newfile"
status="$?"
set +x
echo "`date` - Done with the final pass."
if [[ $passes == 2 && $status == 0 ]]; then
mv -v ffmpeg2pass*.log* ~/TRASH/
fi
sync
sleep 10
sync
if [[ -s $newfile ]]; then
echo "`date` - Getting file sizes."
du -h "$file"
du -h "$newfile"
else
echo "ERROR: New file not created or has a 0 size." >&2
fi
echo -e "\n`date` - Finished with status '$status'."
return $status
}
alias pv="process-video"
alias qpv="pv ./raw/YouCut*.mp4 `basename $(pwd)`.mp4"
# Allow converting video to audio ad other smaller
# tasks than what process-video is intended to do.
function basic-process-usage {
echo "basic-process INPUT OUTPUT NORMALIZE [EXTRA]"
echo -n "Pass a file through ffmpeg with the option"
echo "to easily normalize the audio with a Y."
echo "Examples:"
echo "- Normalize audio on a video."
echo " basic-process video.mp4 normalized.mp4 Y"
echo "- Convert a video to audio at 192k."
echo " basic-process video.mp4 audio.mp3 N '-b:a 192k'"
}
function basic-process {
# Parameters
input="$1"
output="$2"
typeset -u normalize
normalize="$3"
extra="$4"
echo "`date` - Starting basic-process"
# Validations
if [[ -z $input || ! -e $input ]]; then
echo "ERROR: Input file '$input' does not exist." >&2
basic-process-usage
return 1
fi
if [[ -z $output ]]; then
echo "ERROR: Output file's name must be provided." >&2
basic-process-usage
return 1
elif [[ -e $output ]]; then
echo "ERROR: Output file '$output' already exists." >&2
du -h "$output"
basic-process-usage
return 1
fi
if [[ $normalize == "Y" ]]; then
echo "Normalize set to TRUE."
normal="-filter:a dynaudnorm=f=33:g=65:p=0.66:m=33.3"
else
echo "No audio normalization is being done."
fi
# Main
echo "`date` - Converting '$input' to '$output'."
set -x
ffmpeg -nostdin -hide_banner -loglevel quiet \
-i "$input" $extra $normal "$output"
status=$?
set +x
if [[ $status != 0 ]]; then
echo "`date` - WARNING: ffmpeg exited with status '$status'." >&2
fi
# Finish
if [[ ! -s $output ]]; then
echo "`date` - ERROR: Output '$output' not created or has 0 size." >&2
return 1
fi
sync
echo "`date` - '$output' has been created successfully."
sleep 3
du -h "$input"
du -h "$output"
echo "`date` - Finished basic-process"
return 0
}
alias bp="basic-process"
alias bv="bp"
# Function to automatically append tbe Y.
function fix-audio {
basic-process "$1" Y
}
# Function to easily turn a video to audio without typing the audio name.
function convert-to-audio {
video="$1"
audio="$2"
if [[ -z "$2" || "$2" == "Y" ]]; then
audio="${1//mp4/mp3}"
fi
volume=""
if [[ ( "$2" == "Y" && -z "$3" ) || "$3" == "Y" ]]; then
$volume="Y"
fi
basic-process "$video" "$audio" $volume
}
alias v2a="convert-to-audio"
alias vta="v2a"
alias va="v2a"
alias pa="v2a"
alias pull-content="mv -v $SS/DCIM/Camera/`date +"%Y-%m-%d"`* ./raw/" alias pull-content="mv -v $SS/DCIM/Camera/`date +"%Y-%m-%d"`* ./raw/"
alias pull-screenshots="mv -v $SS/Pictures/Screenshots/* ./raw/" alias pull-screenshots="mv -v $SS/Pictures/Screenshots/*`date +"%Y%m%d"`* ./raw/"
alias pull-screenshot="pull-screenshots" alias pull-screenshot="pull-screenshots"
alias pull-sc="pull-screenshots" alias pull-sc="pull-screenshots"
alias pull-crops="mv -v $SS/Documents/*/`date +"%Y%m%d"`*.{jpg,png} ./raw/" alias pull-crops="mv -v $SS/Documents/*/`date +"%Y%m%d"`*.{jpg,png} ./raw/"
alias pull-youcuts="mv -v $SS/Movies/youcut/* ./raw/" alias pull-youcuts="mv -v $SS/Movies/youcut/*`date +"%Y%m%d"`* ./raw/"
alias pull-youcut="pull-youcuts" alias pull-youcut="pull-youcuts"
alias pull-yc="pull-youcut" alias pull-yc="pull-youcut"
alias pull-memes="mv -v $SS/Pictures/memetastic/memes/*.jpg ./" alias pull-memes="mv -v $SS/Pictures/memetastic/memes/*`date +"%Y%m%d"`*.jpg ./"
alias pull-meme="pull-memes" alias pull-meme="pull-memes"
alias pull-icon="pull-meme" alias pull-icon="pull-meme"
@@ -494,12 +277,6 @@ alias qv="qvd"
## Backup Related ## ## Backup Related ##
function now {
date "+%Y%m%d-%H%M%S"
}
function today {
date "+%Y%m%d"
}
export BACKUP_DIR="/srv/backup" export BACKUP_DIR="/srv/backup"
export DOCKER="Docker" export DOCKER="Docker"
export SYSTEM="System" export SYSTEM="System"
@@ -554,6 +331,21 @@ alias prod-backup="pull_prod_backups"
alias pull-prod="pull_prod_backups" alias pull-prod="pull_prod_backups"
alias prod-pull="pull_prod_backups" alias prod-pull="pull_prod_backups"
## Finalize ##
# Export all functions! #
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` - Updates to env-termux are available via 'reload-termux'."
log " '$status'"
done
fi & )
# Complete! # Complete!
PROG="$(basename -- "${BASH_SOURCE[0]}")" PROG="$(basename -- "${BASH_SOURCE[0]}")"
echo "'$PROG' completed!" echo "`date` - '$PROG' completed!"

View File

@@ -1,17 +1,18 @@
# Variables for fast-access of production server. # Variables for fast-access of production server.
PROD_HOST=example.com export PROD_HOST=example.com
PROD_PORT=2222 export PROD_PORT=2222
PROD_USER=user export PROD_USER=user
PROD_GIT_HOST=git.example.com export PROD_GIT_HOST=git.example.com
PROD_GIT_PORT=8080 export PROD_GIT_PORT=8080
PROD_GIT_USER=git export PROD_GIT_USER=git
export PROD_GIT_BRANCH=main
PROD_DATA_HOST=sftp.example.com export PROD_DATA_HOST=sftp.example.com
PROD_DATA_PORT=2200 export PROD_DATA_PORT=2200
PROD_DATA_USER=data export PROD_DATA_USER=data
PROD_DATA_DIR=/srv/sftp export PROD_DATA_DIR=/srv/sftp
PROG="$(basename -- "${BASH_SOURCE[0]}")" PROG="$(basename -- "${BASH_SOURCE[0]}")"
echo "'$PROG' completed!" echo "`date` - '$PROG' completed!"

View File

@@ -12,9 +12,6 @@ echo "Working in '$DIR'."
skip="false" skip="false"
if [[ "$1" == "skip" || "$2" == "skip" || "$3" == "skip" ]]; then if [[ "$1" == "skip" || "$2" == "skip" || "$3" == "skip" ]]; then
echo "1='$1'"
echo "2='$2'"
echo "3='$3'"
skip="true" skip="true"
fi fi
@@ -59,17 +56,16 @@ echo -e "\n`date` - BASH Environment"
if [[ ! -e ~/.env ]]; then if [[ ! -e ~/.env ]]; then
if [[ -e example.env ]]; then if [[ -e example.env ]]; then
mv -v example.env ~/.env cp -v example.env ~/.env
else else
echo "ERROR: Neither .env or example.env found." >&2 echo "ERROR: Neither .env or example.env found." >&2
fi fi
else else
echo "'.env' already exists. Good job!" echo "'.env' already exists. Good job!"
rm -v example.env
fi fi
if [[ -e bashrc.sh ]]; then if [[ -e bashrc.sh ]]; then
mv -v bashrc.sh ~/.bashrc cp -v bashrc.sh ~/.bashrc
else else
echo "ERROR: bashrc.sh not found, skipping." >&2 echo "ERROR: bashrc.sh not found, skipping." >&2
fi fi
@@ -80,27 +76,32 @@ echo -e "\n`date` - Directories"
if [[ -d ~/TRASH ]]; then if [[ -d ~/TRASH ]]; then
rm -rfv ~/TRASH rm -rfv ~/TRASH
fi fi
if [[ ! -e ~/storage/shared/TRASH ]]; then if [[ ! -e ~/sdcard/TRASH ]]; then
mkdir -pv ~/storage/shared/TRASH mkdir -pv /sdcard/TRASH
fi fi
ln -s ~/storage/shared/TRASH ~/TRASH ln -s /sdcard/TRASH ~/TRASH
if [[ ! -d ~/Code && ! -d ~/storage/shared/Code ]]; then if [[ ! -d ~/Code && ! -d ~/sdcard/Code ]]; then
mkdir -pv ~/Code mkdir -pv ~/Code
ln -s ~/Code ~/storage/shared/Code ln -s ~/Code /sdcard/Code
fi fi
echo -e "\n`date` - env-shared" env_shared_dir="$HOME/.env-shared"
if [[ ! -d "$env_shared_dir" ]]; then
env_shared_dir="env-shared-dev-deleteme" echo -e "\n`date` - env-shared"
git clone https://git.hyperling.com/me/env-shared \ if [[ -z "$BRANCH" ]]; then
--branch=dev ~/$env_shared_dir export BRANCH="dev"
cp -v ~/$env_shared_dir/rc_shared.sh ~/.rc_shared fi
if [[ ! -d ~/bin ]]; then git clone https://git.hyperling.com/me/env-shared \
mkdir -pv ~/bin --branch=$BRANCH ~/$env_shared_dir
cp -v ~/$env_shared_dir/rc_shared.sh ~/.rc_shared
cp -v ~/$env_shared_dir/vimrc.vim ~/.vimrc
if [[ ! -d ~/bin ]]; then
mkdir -pv ~/bin
fi
cp -v ~/$env_shared_dir/bin-shared/* ~/bin/
fi fi
cp -v ~/$env_shared_dir/bin-shared/* ~/bin/
echo -e "\n`date` - Cleanup" echo -e "\n`date` - Cleanup"
@@ -108,8 +109,9 @@ echo -e "\n`date` - Cleanup"
if [[ -n $DIR && $DIR != "/" && $DIR == *"deleteme" && -d .git ]]; then if [[ -n $DIR && $DIR != "/" && $DIR == *"deleteme" && -d .git ]]; then
echo "We are in a git clone, remove the project." echo "We are in a git clone, remove the project."
cd .. cd ..
mv -v $DIR ~/TRASH/termux-"`date +'%Y%m%d%H%M%S'`" | mv -v $DIR \
grep -v '/.git/' ~/TRASH/termux-"`date +'%Y%m%d%H%M%S'`" \
| grep -v '/.git/'
else else
echo "File was used individually, remove it." echo "File was used individually, remove it."
mv "$PROG" ~/TRASH/ mv "$PROG" ~/TRASH/