Compare commits

...

64 Commits

Author SHA1 Message Date
bd7ac08dfe Move clone and ls aliases to shared. 2026-03-28 13:34:47 -07:00
b1a0586df7 Use source keyword to be more explicit. 2026-03-28 13:24:23 -07:00
09aec0e5d0 Move sourcing shared RC to beginning so variables are available. 2026-03-28 13:22:24 -07:00
891822aad3 Remove extra newline. 2026-03-28 13:04:36 -07:00
6d728dd9ad Fix PS1 prompts to use single quotes and remove colors since they are in env-shared. 2026-03-28 12:09:13 -07:00
f0a2c39bf8 Try fixing ability to skip. 2026-03-28 11:33:22 -07:00
132ae721e7 Add custom PS1 settings. 2026-03-28 11:28:29 -07:00
d25e94d267 Add tput to Termux environment for changing PS1 colors. 2026-03-28 11:28:12 -07:00
226aa5dd6d Add local bin to PATH if it exists. 2026-03-27 18:50:25 -07:00
b8e4b9bfc3 Add code to install env-shared. 2026-03-27 18:49:02 -07:00
83f3288031 Change the order of the variables and add a DIR for the data server. 2026-03-27 18:36:30 -07:00
a8952795bd Change setup.sh to use renamed example.env which has now been created. 2026-03-27 17:31:04 -07:00
9bde085ab4 Change PROD_NAME to PROD_HOST to be more specific. 2026-03-27 17:26:07 -07:00
7e7214eaf7 Add an example file for .env setup as well as new env variables. 2026-03-27 17:25:21 -07:00
ab396a9739 Change bye to be a function. Add spaces to the end of some aliases. Fix indentation to consistently be tabs. 2026-03-27 17:13:14 -07:00
abc56b57cd Add loading the shared RC config if it exists. 2026-03-23 12:17:20 -07:00
68fea2f314 Try fixing the qpv video getting named 'home.mp4'. 2026-01-26 13:58:06 -07:00
7237184456 Add a newline to Termux code-check. 2026-01-09 17:40:55 -07:00
ee651659aa Also pull recordings and cropped photos. 2026-01-09 08:10:13 -07:00
aa5a6e7b77 Improve and streamline video production aliases. 2026-01-08 17:42:40 -07:00
0485f27205 Add baller alias to easily transcode the video with the proper name. 2026-01-08 17:34:23 -07:00
f811070949 Add shortcut to pull memetastic icons. Add shortcut to pull all content types at once. 2026-01-08 17:18:47 -07:00
1e3f6a7402 Fix pulling screenshots and youcuts. /sdcard/ works way better than storage/shared/. 2026-01-08 17:11:22 -07:00
37db32a78b Build ss alias without leaving current directory. 2026-01-04 20:09:46 -07:00
40af484ddd Remove duplicated code. Something weird happened to this file? 2026-01-04 20:06:21 -07:00
fa98b50827 Remove bad text, again. Squircle not working properly. 2026-01-04 20:01:45 -07:00
7f9494411b Remove bad text. 2026-01-04 19:57:28 -07:00
1957f4fdab -m 2026-01-04 17:16:31 -07:00
14d8a61f49 -m 2026-01-04 17:10:27 -07:00
07ca207fd1 -m 2026-01-04 16:59:50 -07:00
0494b05bb7 -m 2026-01-04 16:51:08 -07:00
55102cc9fd Add the load-branch command from desktop env project env-ansible. 2026-01-03 14:34:12 -07:00
4d740d7d2f Add rsync to package list. 2025-11-30 17:59:39 -07:00
080669359a Add clone alias from env-ansible project. 2025-11-30 17:46:49 -07:00
4cfeb6073c Add missing params variable to final update command. 2025-11-25 07:28:10 -07:00
74bdd45ef7 Add sort. 2025-10-24 15:25:59 -07:00
98fc25a132 Bring over enhancements and fixed from Ansible side. 2025-10-24 15:19:54 -07:00
a0962cb04d Add more aliases for reloading shell. 2025-10-24 14:55:26 -07:00
e85947cb0c Additional enhancements to pulling Production backups. 2025-10-24 14:53:41 -07:00
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
5 changed files with 388 additions and 75 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.

348
bashrc.sh
View File

@@ -1,30 +1,49 @@
# 2024-02-10 Hyperling
## Environment Setup ##
export PATH="~/bin:$PATH"
if [[ -e ~/.env ]]; then
source ~/.env
fi
if [ -f ~/.rc_shared ]; then
source ~/.rc_shared
fi
# PS1
# This helps to determine the color palette numbers:
# https://robotmoon.com/bash-prompt-generator/
# Colors are in env-shared.
if [[ "`whoami`" == "root" ]]; then
export PS1='\[$BOLD\]\[$ORANGE\][\[$SCARLET\]\t \[$RED\]\w\[$ORANGE\]]\[$GRAY\]\$ \[$RESET\]'
else
export PS1='\[$BOLD\]\[$PURPLE\][\[$ORANGE\]\t \[$GREEN\]\w\[$PURPLE\]]\[$RESET\]\$ '
fi
## Aliases ##
# Quickly log onto production server.
# Setting up ssh-keygen and ssh-copy-id make this even faster!
if [[ -n $PROD_PORT && -n $PROD_USER && -n $PROD_NAME ]]; then
alias prod="ssh -p $PROD_PORT $PROD_USER@$PROD_NAME"
if [[ -n $PROD_PORT && -n $PROD_USER && -n $PROD_HOST ]]; then
alias prod="ssh -p $PROD_PORT $PROD_USER@$PROD_HOST"
else
alias prod="echo 'ERROR: .env not set up properly, please fix and reload RC.'"
fi
# Quickies
alias reload-bash="source ~/.bashrc"
alias bash-reload="reload-bash"
alias reload="reload-bash"
# Easily get to storage devices.
export SS="~/storage/shared"
curr="`pwd`"
cd
cd storage/shared
#export SS="`pwd`"
export SS="/sdcard"
cd
alias ss="cd $SS"
alias sd="ss"
alias storage="ss"
alias home="ss"
cd "$curr"
# Shortcut to media.
export DCIM="$SS/DCIM/Camera"
@@ -37,29 +56,187 @@ alias code="cd $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 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"
function bye { exit; }
alias install="pkg install "
alias uninstall="pkg uninstall "
alias remove="uninstall "
alias scan="nmap -A -p- --script=vuln "
## Functions ##
### Functions ###
## Code Related ##
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 -e "\nChecking $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"
# Quickly commit code to a repo.
function commit {
message="$1"
if [[ -z "$message" ]]; then
echo "ERROR: A message is required." >&2
echo 'USAGE: commit "My commit message."' >&2
return 1
fi
if [[ "$1" == "-m" ]]; then
message="$2"
fi
git add . && git commit -m "$message" && git push
}
# Easily test this project after committing changes.
# 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://git.hyperling.com/me/env-termux \
--branch=dev ~/termux-deleteme
chmod 755 ~/termux-deleteme/*.sh
~/termux-deleteme/setup.sh
}
alias reload-termux="test-termux"
alias termux-test="test-termux"
alias termux-reload="reload-termux"
# Pulled from /me/env-ansible, need to make a shared library between it and Termux.
# Change a branch to point at another.
function load-branch {
rcvr="$1" # branch which we want to modify
base="$2" # branch with the changes we want
if [[ "$rcvr" == "main" ]]; then
echo "*** ERROR: Are you nuts, fool!? Not main! Do it manually! ***"
return 1
fi
if [[ -z "$base" ]]; then
if [[ "$rcvr" == "prod" ]]; then
base="stage"
elif [[ "$rcvr" == "stage" ]]; then
base="dev"
else
echo "* Unsure which branch to use for '$rcvr'. Please specify."
return 1
fi
echo "* Base was not specified, using '$base' for '$rcvr'."
else
echo "* Requested pointing '$rcvr' branch to '$base'."
fi
echo -e "\n* Ensuring we are on base branch '$base'." &&
git switch "$base" &&
echo -e "\n* Changing pointer for '$rcvr' to '$base'." &&
git branch -f "$rcvr" "$base" &&
#echo -e "\n* Switching to branch '$rcvr'." &&
#git switch "$rcvr" &&
echo -e "\n* Forcing push on branch '$rcvr'." &&
git push --force --set-upstream origin "$rcvr" &&
echo -e "\n* Done! Displaying list of remote branches." &&
git ls-remote --heads | sort
if [[ "$base" != "dev" ]]; then
echo -e "\n* Checking if a dev branch exists."
git ls-remote --exit-code --heads origin dev
dev_exists="$?"
if [[ "$dev_exists" == 0 ]]; then
echo -e "\n* Switching back to dev."
git switch dev
elif [[ "$dev_exists" == 2 ]]; then
echo -e "\n* Switching back to main."
git switch main
else
echo "*** ERROR: Unknown status for dev_exists, '$dev_exists'. ***"
fi
fi
echo -e "\n* Verifying which branch we're on."
git branch
}
alias load-prod="load-branch prod"
alias load-stage="load-branch stage"
alias rollback-prod="load-branch prod main"
alias rollback-stage="load-branch stage prod"
alias rollback-dev="load-branch dev stage"
alias reset-prod="load-branch prod main"
alias reset-stage="load-branch stage main"
alias reset-dev="load-branch dev main"
## Termux Related ##
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 $params
echo -e "\n******* Mission Complete!! *******"
}
alias upgrade="update"
alias goodbye="update -y && bye"
## Videk Related ##
# 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."
@@ -75,6 +252,7 @@ function process-video {
audio="$4"
size="$5"
passes="$6"
force="$7"
# Validations
if [[ -z $file || ! -e $file ]]; then
@@ -99,7 +277,11 @@ function process-video {
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"
@@ -168,29 +350,7 @@ function process-video {
return $status
}
alias pv="process-video"
# Quickly commit code to a repo.
function commit {
message="$1"
if [[ -z $message ]]; then
echo "ERROR: A message is required." >&2
echo 'USAGE: commit "My commit message."' >&2
return 1
fi
git add . && git commit -m "$message" && git push
}
# Easily test this project after committing changes.
# 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
chmod 755 ~/termux-deleteme/*.sh
~/termux-deleteme/setup.sh
}
alias reload-termux="test-termux"
alias termux-test="test-termux"
alias termux-reload="reload-termux"
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.
@@ -292,8 +452,108 @@ alias vta="v2a"
alias va="v2a"
alias pa="v2a"
# Go to normal storage. DISABLED, use shortcut aliases instead.
#cd ~/storage/shared/
alias pull-content="mv -v $SS/DCIM/Camera/`date +"%Y-%m-%d"`* ./raw/"
alias pull-screenshots="mv -v $SS/Pictures/Screenshots/* ./raw/"
alias pull-screenshot="pull-screenshots"
alias pull-sc="pull-screenshots"
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-youcut="pull-youcuts"
alias pull-yc="pull-youcut"
alias pull-memes="mv -v $SS/Pictures/memetastic/memes/*.jpg ./"
alias pull-meme="pull-memes"
alias pull-icon="pull-meme"
function init-video-contents {
if [[ -n "$1" ]]; then
mkdir "$1"
cd "$1"
fi
touch README.md
#touch title.md
#touch desc.md
#touch tags.md
mkdir -pv raw
}
alias init-video="init-video-contents"
alias init-vid="init-video"
alias initvid="init-vid"
alias mkvid="init-video; pull-content; pull-yc; pull-sc; pull-crops; pull-icon; qpv"
alias mkv="mkvid"
alias qvd="mkv"
alias qv="qvd"
## End Video Section ##
## Backup Related ##
function now {
date "+%Y%m%d-%H%M%S"
}
function today {
date "+%Y%m%d"
}
export BACKUP_DIR="/srv/backup"
export DOCKER="Docker"
export SYSTEM="System"
function pull_prod_backup {
if [[ -z "$1" || ("$1" != "$DOCKER" && "$1" != "$SYSTEM") ]]; then
echo "ERROR: Parameter 1 not correct, expecting '$DOCKER' or '$SYSTEM'."
return 1
fi
backup_type="$1"
echo "Looking for '*${backup_type}*.zip'"
ls -lh *${backup_type}*.zip 2>/dev/null
status="$?"
if [[ "$status" == "0" ]]; then
echo "File already downloaded, skipping."
return 0
else
echo "File still needed, downloading to local tmp/."
fi
mkdir -pv tmp
scp -P $PROD_PORT \
$PROD_USER@$PROD_HOST:"$BACKUP_DIR/*${backup_type}*.zip" \
tmp/
if [[ "$?" == "0" ]]; then
echo "Succeeded!"
mv -v tmp/*.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 "$DOCKER"
pull_prod_backup "$SYSTEM"
du -h *.zip | sort -h
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

@@ -1,9 +0,0 @@
# 2024-02-10 Hyperling
# Variables for a fast-access SSH alias.
PROD_USER=username
PROD_NAME=example.com
PROD_PORT=2222
PROG="$(basename -- "${BASH_SOURCE[0]}")"
echo "'$PROG' completed!"

17
example.env Normal file
View File

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

View File

@@ -9,11 +9,26 @@ cd $DIR
DIR="`pwd`"
echo "Working in '$DIR'."
echo -e "\n`date` - Upgrade Package Repos"
pkg update &&
pkg upgrade -y
skip="false"
if [[ "$1" == "skip" || "$2" == "skip" || "$3" == "skip" ]]; then
echo "1='$1'"
echo "2='$2'"
echo "3='$3'"
skip="true"
fi
if [[ "$skip" == "true" ]]; 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,23 +42,30 @@ 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 [[ "$skip" == "true" ]]; then
echo "\n`date` - Skipping Installs"
else
echo -e "\n`date` - Install Software"
pkg install -y \
openssh tsu vim htop git cronie man zip ncurses-utils \
nmap traceroute wget rsync \
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
if [[ -e example.env ]]; then
mv -v example.env ~/.env
else
echo "ERROR: Neither .env or env.example found." >&2
echo "ERROR: Neither .env or example.env found." >&2
fi
else
echo "'.env' already exists. Good job!"
rm -v env.example
rm -v example.env
fi
if [[ -e bashrc.sh ]]; then
@@ -52,7 +74,9 @@ else
echo "ERROR: bashrc.sh not found, skipping." >&2
fi
echo -e "\n`date` - Cleanup"
echo -e "\n`date` - Directories"
if [[ -d ~/TRASH ]]; then
rm -rfv ~/TRASH
fi
@@ -61,7 +85,27 @@ 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` - env-shared"
env_shared_dir="env-shared-dev-deleteme"
git clone https://git.hyperling.com/me/env-shared \
--branch=dev ~/$env_shared_dir
cp -v ~/$env_shared_dir/rc_shared.sh ~/.rc_shared
if [[ ! -d ~/bin ]]; then
mkdir -pv ~/bin
fi
cp -v ~/$env_shared_dir/bin-shared/* ~/bin/
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'`" |
@@ -71,6 +115,7 @@ else
mv "$PROG" ~/TRASH/
fi
echo -e "\n*******"
echo "Don't forget to reload your environment!"
echo " source ~/.bashrc"