Compare commits

25 Commits
main ... prod

Author SHA1 Message Date
3c285298eb Add more output. 2025-10-23 20:02:49 -07:00
a9c9f3b784 Add check on whether any zips were successful. 2025-10-23 19:59:52 -07:00
53fbb829a3 Properly handle removing the failed files. 2025-10-23 19:50:49 -07:00
28219c97ed Add production backup pulling logic to Termux from Ansible. 2025-10-23 19:47:03 -07:00
876a106ea0 Add ls alias for only showing size, not all the file data. 2025-10-14 08:18:24 -07:00
3554a40622 All ll for Android. 2025-10-14 07:15:36 -07:00
b0fcdb9429 Add trailing folder to SS. Add sorting on check-trashed. 2025-10-09 07:32:12 -07:00
0a26a3b3e8 Change ss to no longer use ~. 2025-10-09 07:19:17 -07:00
663079c0cd Change trashed commands to hit the main Android storage. 2025-10-09 07:16:04 -07:00
33c60504bd Add methods to easily start a video project and pull files over. 2025-10-09 07:06:47 -07:00
a5791e2bc6 Add 'trashed*' file cleanup for Android. 2025-10-09 06:59:27 -07:00
3763fc6000 Add a comment to explain the swap between commands. 2025-09-16 13:57:38 -07:00
49d9c95c85 Alter the update function and move / edit some of its aliases. 2025-09-16 13:55:51 -07:00
6220e70480 Add TODO for changing apt to pkg. 2025-09-16 10:32:46 -07:00
2324acb6d6 Allow skipping the pkg commands. 2025-08-14 16:36:43 -07:00
e27924f062 Only delete the project if deleteme is in the name. 2025-08-14 16:26:23 -07:00
d3dc527b26 -m 2025-08-14 16:21:17 -07:00
7ceb1f436b Add Code directory and some helpers to seed and sync it. 2025-08-14 16:12:04 -07:00
8ef92669cd Add scanning alias for analyzing network systems. 2025-07-23 05:49:19 -07:00
d793218215 Add extra switches to dist-upgrade like on desktop. 2025-01-03 12:32:11 -07:00
bb0bcc27c8 Upgrade the update alias to a function like done for desktops. 2025-01-03 12:23:27 -07:00
bdd7e7855b Modify project to use Gitea URLs. 2025-01-03 11:59:53 -07:00
060a3b25d8 Add zip!! 2025-01-01 12:44:27 -07:00
6b3975176a Fix videos not compressing properly. 2024-07-05 12:31:17 -07:00
67ef7d128f Allow old usage of making the video bitrate something specific. 2024-07-03 18:28:37 -07:00
3 changed files with 183 additions and 26 deletions

View File

@@ -7,7 +7,7 @@ Hyperling's scripts for a productive Termux environment.
1. Download the repository.
```sh
git clone https://github.com/Hyperling/Termux termux
git clone https://git.hyperling.com/me/env-termux env-termux
```
1. Dive into the directory.

165
bashrc.sh
View File

@@ -19,8 +19,14 @@ alias reload-bash="source ~/.bashrc"
alias bash-reload="reload-bash"
alias reload="reload-bash"
alias l='ls'
alias ll='ls -alh'
alias lh='ls -ash'
# Easily get to storage devices.
export SS="~/storage/shared"
cd storage/shared
export SS="`pwd`/"
cd
alias ss="cd $SS"
alias sd="ss"
alias storage="ss"
@@ -34,35 +40,93 @@ alias dcim="cd $DCIM"
export CODE="$SS/Code"
alias code="cd $CODE"
function code-projects {
cat <<- EOF
env-termux dev
env-ansible dev
env-docker dev
nodejs-website dev
hugo-jackanope main
EOF
}
function code-reseed {
cd ~/Code
code-projects | while read project branch; do
git clone ssh://git@$GIT_SERVER:$GIT_PORT/$GIT_USER/$project --branch $branch --recurse-submodules
done
}
alias reseed-code="code-reseed"
function check-code {
cd ~/Code
ls | while read project; do
echo "Checking $project..."
cd $project
if [[ -d .git ]]; then
git pull
git push
else
echo "* Not a valid git project, skipping."
fi
cd ..
done
}
alias code-check="check-code"
# Shortcuts for TRASH.
export TRASH="$SS/TRASH"
alias trash="cd $TRASH"
alias clean-trash="bash -c 'rm -rfv $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.
alias cp="cp -v"
alias mv="mv -v"
alias rm="echo 'Move to ~/storage/shared/TRASH/ instead!'"
# Quickies
alias update="pkg update && pkg upgrade"
alias bye="exit"
alias goodbye="update -y && bye"
alias install="pkg install"
alias uninstall="pkg uninstall"
alias remove="uninstall"
alias scan="nmap -A -p- --script=vuln"
## Functions ##
function update {
params="$1"
echo "******* Apt / Pkg *******" &&
echo "*** Update Cache ***" &&
apt update &&
echo -e "\n*** Auto Remove ***" &&
apt autoremove $params &&
echo -e "\n*** Clean ***" &&
pkg clean $params &&
echo -e "Cleaned!\n\n*** Fix Broken/Missing ***" &&
apt --fix-broken --fix-missing install &&
echo -e "\n*** Upgrade ***" &&
# No longer using `apt`, in favor of Termux's wrapper `pkg`.
#apt dist-upgrade --allow-downgrades --fix-broken --fix-missing $params &&
pkg upgrade
echo -e "\n******* Mission Complete!! *******"
}
alias upgrade="update"
alias goodbye="update -y && bye"
# Optimize the bitrate and audio levels for an edited video.
function process-video-usage {
echo "USAGE: process-video oldFile newFile [videoBitrate] [audioBitrate] [sizeRating]"
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. "
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 "- 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"
@@ -75,6 +139,7 @@ function process-video {
audio="$4"
size="$5"
passes="$6"
force="$7"
# Validations
if [[ -z $file || ! -e $file ]]; then
@@ -93,13 +158,17 @@ function process-video {
process-video-usage
return 1
fi
echo "`date` - Converting '$file' to '$newfile'."
if [[ -z $video ]]; then
video="2000k"
fi
video="-maxrate $video"
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"
@@ -110,7 +179,7 @@ function process-video {
size="720"
fi
size="-filter:v scale=-1:$size"
if [[ -z $passes ]]; then
passes=1
fi
@@ -138,7 +207,7 @@ function process-video {
return 1
fi
fi
set -x &&
ffmpeg -nostdin -hide_banner -loglevel quiet \
-i "$file" $size $video $audio \
@@ -148,7 +217,7 @@ function process-video {
status="$?"
set +x
echo "`date` - Done with the final pass."
if [[ $passes == 2 && $status == 0 ]]; then
mv -v ffmpeg2pass*.log* ~/TRASH/
fi
@@ -184,7 +253,8 @@ function commit {
# Otherwise can just source this file unless testing setup.sh.
function test-termux {
sh -c "rm -rf ~/termux-deleteme ~/TRASH/termux-deleteme" 2>/dev/null
git clone https://github.com/Hyperling/Termux ~/termux-deleteme --branch=dev
git clone https://git.hyperling.com/me/env-termux \
--branch=dev ~/termux-deleteme
chmod 755 ~/termux-deleteme/*.sh
~/termux-deleteme/setup.sh
}
@@ -295,5 +365,74 @@ alias pa="v2a"
# Go to normal storage. DISABLED, use shortcut aliases instead.
#cd ~/storage/shared/
# Shortcuts for starting a video project.
function init-video {
dir="$1"
if [[ ! -z $"dir" && ! -e "$dir" ]]; then
mkdir -p "$dir"
cd $dir
fi
touch readme.md
mv -v "$SS/Movies/youcut/*" ./
mv -v "$SS/Pictures/Screenshots/*" ./
}
alias pull-video="init-video"
alias pull-screenshot="init-video"
alias pull-sc="pull-screenshot"
alias video-readme="init-video"
# Backup Related Activities #
function now {
date "+%Y%m%d-%H%M%S"
}
function today {
date "+%Y%m%d"
}
export BACKUP_DIR="/srv/backup"
export BACKUP="Backup"
export SYSTEM="System"
function pull_prod_backup {
if [[ -z "$1" || ("$1" != "$BACKUP" && "$1" != "$SYSTEM") ]]; then
echo "ERROR: Parameter 1 not correct, expecting '$BACKUP' or '$SYSTEM'."
return 1
fi
backup_type="$1"
mkdir -pv tmp
scp -P $PROD_PORT \
$PROD_USER@$PROD_NAME:"$BACKUP_DIR/*${backup_type}*.zip" \
tmp/
if [[ "$?" == "0" ]]; then
echo "Succeeded!"
mv -v "tmp/*${backup_type}*.zip" ./
rmdir -v tmp
else
echo "Failed!"
mv tmp "$TRASH/tmp_`now`"
fi
}
function pull_prod_backups {
dir="ProductionBackups-Pulled`today`"
mkdir -pv "$dir"
cd "$dir"
pull_prod_backup "$BACKUP"
pull_prod_backup "$SYSTEM"
du -h *.zip
status="$?"
cd ..
if [[ "$status" != 0 ]]; then
echo "Failed to find zip files, removing folder."
rmdir -v "$dir"
return 1
fi
echo "Done!"
}
alias pull-prod-backups="pull_prod_backups"
alias pull-backups="pull_prod_backups"
alias prod-backups="pull_prod_backups"
alias prod-backup="pull_prod_backups"
alias pull-prod="pull_prod_backups"
alias prod-pull="pull_prod_backups"
# Complete!
PROG="$(basename -- "${BASH_SOURCE[0]}")"
echo "'$PROG' completed!"

View File

@@ -9,11 +9,16 @@ cd $DIR
DIR="`pwd`"
echo "Working in '$DIR'."
echo -e "\n`date` - Upgrade Package Repos"
pkg update &&
pkg upgrade -y
if [[ $1 == "skip" ]]; then
echo "\n`date` - Skipping Updates"
else
echo -e "\n`date` - Upgrade Package Repos"
pkg update &&
pkg upgrade -y
fi
echo -e "\n`date` - Check Storage Permission"
if [[ ! -e ~/storage/shared ]]; then
sleep 3
termux-setup-storage
@@ -27,14 +32,19 @@ else
echo "Everything looks good already, pal."
fi
echo -e "\n`date` - Install Software"
pkg install -y \
openssh tsu vim htop git cronie man \
nmap traceroute wget \
ffmpeg imagemagick \
kotlin php nodejs python libllvm
if [[ $1 == "skip" ]]; then
echo "\n`date` - Skipping Installs"
else
echo -e "\n`date` - Install Software"
pkg install -y \
openssh tsu vim htop git cronie man zip \
nmap traceroute wget \
ffmpeg imagemagick \
kotlin php nodejs python libllvm hugo
fi
echo -e "\n`date` - BASH Environment"
if [[ ! -e ~/.env ]]; then
if [[ -e env.example ]]; then
mv -v env.example ~/.env
@@ -52,7 +62,8 @@ else
echo "ERROR: bashrc.sh not found, skipping." >&2
fi
echo -e "\n`date` - Cleanup"
echo -e "\n`date` - Directoriee"
if [[ -d ~/TRASH ]]; then
rm -rfv ~/TRASH
fi
@@ -61,10 +72,17 @@ if [[ ! -e ~/storage/shared/TRASH ]]; then
fi
ln -s ~/storage/shared/TRASH ~/TRASH
if [[ -n $DIR && $DIR != "/" && -d .git ]]; then
if [[ ! -d ~/Code && ! -d ~/storage/shared/Code ]]; then
mkdir -pv ~/Code
ln -s ~/Code ~/storage/shared/Code
fi
echo -e "\n`date` - Cleanup"
if [[ -n $DIR && $DIR != "/" && $DIR == *"deleteme" && -d .git ]]; then
echo "We are in a git clone, remove the project."
cd ..
mv -v $DIR ~/TRASH/termux-"`date +'%Y%m%d%H%M%S'`" |
mv -v $DIR ~/TRASH/termux-"`date +'%Y%m%d%H%M%S'`" |
grep -v '/.git/'
else
echo "File was used individually, remove it."