Compare commits

..
87 Commits
Author SHA1 Message Date
me 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
me 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
me a84fba5a1c Be more consistent about only pulling files with today's date (screenshots, memes, edited photos). 2026-05-05 09:23:11 -07:00
me 6c9112ef23 Move trash related code to shared env. 2026-04-25 10:33:14 -07:00
me c9f2802359 Fix single quote location. 2026-04-18 10:47:42 -07:00
me 3486e238d4 Add a parameter for the branch that's preferred. 2026-04-17 15:46:21 -07:00
me 3ed66ea059 Add exporting of all functions, same as done in env-shared. 2026-04-13 19:28:32 -07:00
me 46e6b205a9 Hide output from .git folder deletion. 2026-03-28 15:17:45 -07:00
me ea40967e2b Install the vimrc from shared env project. 2026-03-28 15:13:24 -07:00
me 86ad8c5b5c Add exports to env setup. 2026-03-28 15:00:41 -07:00
me fd227c810c Add verbosity to deleting shared env. 2026-03-28 14:58:23 -07:00
me 4744d996a1 Fix path to TRASH. 2026-03-28 14:56:48 -07:00
me bd0c01fda6 Fix single quote location. 2026-03-28 14:55:44 -07:00
me c323748cec Add date to file completion output. 2026-03-28 14:51:51 -07:00
me 6226d00a1c Change brackets from purple to gray. 2026-03-28 14:49:54 -07:00
me f199605915 Remove test code, skip is working now. 2026-03-28 14:48:44 -07:00
me 6356497cb6 Add more test code to troubleshoot skipping updates. 2026-03-28 14:46:50 -07:00
me b7d189af66 Pass reload-termux params to setup.sh. 2026-03-28 14:44:48 -07:00
me dbc0a711c4 Add text code to see why skip is not working. 2026-03-28 14:43:21 -07:00
me ae636f4fbe Fix deleting shared env project. 2026-03-28 14:39:24 -07:00
me 42f4ef919f Move now and today t shared env. 2026-03-28 14:24:20 -07:00
me 2662966098 Move scan to be in shared env. 2026-03-28 14:18:49 -07:00
me 16ded2672e Move ffmpeg functions to shared. 2026-03-28 14:17:19 -07:00
me bd7ac08dfe Move clone and ls aliases to shared. 2026-03-28 13:34:47 -07:00
me b1a0586df7 Use source keyword to be more explicit. 2026-03-28 13:24:23 -07:00
me 09aec0e5d0 Move sourcing shared RC to beginning so variables are available. 2026-03-28 13:22:24 -07:00
me 891822aad3 Remove extra newline. 2026-03-28 13:04:36 -07:00
me 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
me f0a2c39bf8 Try fixing ability to skip. 2026-03-28 11:33:22 -07:00
me 132ae721e7 Add custom PS1 settings. 2026-03-28 11:28:29 -07:00
me d25e94d267 Add tput to Termux environment for changing PS1 colors. 2026-03-28 11:28:12 -07:00
me 226aa5dd6d Add local bin to PATH if it exists. 2026-03-27 18:50:25 -07:00
me b8e4b9bfc3 Add code to install env-shared. 2026-03-27 18:49:02 -07:00
me 83f3288031 Change the order of the variables and add a DIR for the data server. 2026-03-27 18:36:30 -07:00
me a8952795bd Change setup.sh to use renamed example.env which has now been created. 2026-03-27 17:31:04 -07:00
me 9bde085ab4 Change PROD_NAME to PROD_HOST to be more specific. 2026-03-27 17:26:07 -07:00
me 7e7214eaf7 Add an example file for .env setup as well as new env variables. 2026-03-27 17:25:21 -07:00
me 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
me abc56b57cd Add loading the shared RC config if it exists. 2026-03-23 12:17:20 -07:00
me 68fea2f314 Try fixing the qpv video getting named 'home.mp4'. 2026-01-26 13:58:06 -07:00
me 7237184456 Add a newline to Termux code-check. 2026-01-09 17:40:55 -07:00
me ee651659aa Also pull recordings and cropped photos. 2026-01-09 08:10:13 -07:00
me aa5a6e7b77 Improve and streamline video production aliases. 2026-01-08 17:42:40 -07:00
me 0485f27205 Add baller alias to easily transcode the video with the proper name. 2026-01-08 17:34:23 -07:00
me f811070949 Add shortcut to pull memetastic icons. Add shortcut to pull all content types at once. 2026-01-08 17:18:47 -07:00
me 1e3f6a7402 Fix pulling screenshots and youcuts. /sdcard/ works way better than storage/shared/. 2026-01-08 17:11:22 -07:00
me 37db32a78b Build ss alias without leaving current directory. 2026-01-04 20:09:46 -07:00
me 40af484ddd Remove duplicated code. Something weird happened to this file? 2026-01-04 20:06:21 -07:00
me fa98b50827 Remove bad text, again. Squircle not working properly. 2026-01-04 20:01:45 -07:00
me 7f9494411b Remove bad text. 2026-01-04 19:57:28 -07:00
me 1957f4fdab -m 2026-01-04 17:16:31 -07:00
me 14d8a61f49 -m 2026-01-04 17:10:27 -07:00
me 07ca207fd1 -m 2026-01-04 16:59:50 -07:00
me 0494b05bb7 -m 2026-01-04 16:51:08 -07:00
me 55102cc9fd Add the load-branch command from desktop env project env-ansible. 2026-01-03 14:34:12 -07:00
me 4d740d7d2f Add rsync to package list. 2025-11-30 17:59:39 -07:00
me 080669359a Add clone alias from env-ansible project. 2025-11-30 17:46:49 -07:00
me 4cfeb6073c Add missing params variable to final update command. 2025-11-25 07:28:10 -07:00
me 74bdd45ef7 Add sort. 2025-10-24 15:25:59 -07:00
me 98fc25a132 Bring over enhancements and fixed from Ansible side. 2025-10-24 15:19:54 -07:00
me a0962cb04d Add more aliases for reloading shell. 2025-10-24 14:55:26 -07:00
me e85947cb0c Additional enhancements to pulling Production backups. 2025-10-24 14:53:41 -07:00
me 3c285298eb Add more output. 2025-10-23 20:02:49 -07:00
me a9c9f3b784 Add check on whether any zips were successful. 2025-10-23 19:59:52 -07:00
me 53fbb829a3 Properly handle removing the failed files. 2025-10-23 19:50:49 -07:00
me 28219c97ed Add production backup pulling logic to Termux from Ansible. 2025-10-23 19:47:03 -07:00
me 876a106ea0 Add ls alias for only showing size, not all the file data. 2025-10-14 08:18:24 -07:00
me 3554a40622 All ll for Android. 2025-10-14 07:15:36 -07:00
me b0fcdb9429 Add trailing folder to SS. Add sorting on check-trashed. 2025-10-09 07:32:12 -07:00
me 0a26a3b3e8 Change ss to no longer use ~. 2025-10-09 07:19:17 -07:00
me 663079c0cd Change trashed commands to hit the main Android storage. 2025-10-09 07:16:04 -07:00
me 33c60504bd Add methods to easily start a video project and pull files over. 2025-10-09 07:06:47 -07:00
me a5791e2bc6 Add 'trashed*' file cleanup for Android. 2025-10-09 06:59:27 -07:00
me 3763fc6000 Add a comment to explain the swap between commands. 2025-09-16 13:57:38 -07:00
me 49d9c95c85 Alter the update function and move / edit some of its aliases. 2025-09-16 13:55:51 -07:00
me 6220e70480 Add TODO for changing apt to pkg. 2025-09-16 10:32:46 -07:00
me 2324acb6d6 Allow skipping the pkg commands. 2025-08-14 16:36:43 -07:00
me e27924f062 Only delete the project if deleteme is in the name. 2025-08-14 16:26:23 -07:00
me d3dc527b26 -m 2025-08-14 16:21:17 -07:00
me 7ceb1f436b Add Code directory and some helpers to seed and sync it. 2025-08-14 16:12:04 -07:00
me 8ef92669cd Add scanning alias for analyzing network systems. 2025-07-23 05:49:19 -07:00
me d793218215 Add extra switches to dist-upgrade like on desktop. 2025-01-03 12:32:11 -07:00
me bb0bcc27c8 Upgrade the update alias to a function like done for desktops. 2025-01-03 12:23:27 -07:00
me bdd7e7855b Modify project to use Gitea URLs. 2025-01-03 11:59:53 -07:00
me 060a3b25d8 Add zip!! 2025-01-01 12:44:27 -07:00
me 6b3975176a Fix videos not compressing properly. 2024-07-05 12:31:17 -07:00
me 67ef7d128f Allow old usage of making the video bitrate something specific. 2024-07-03 18:28:37 -07:00
5 changed files with 372 additions and 264 deletions

No files matched your search

+1 -1
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.
+285 -233
View File
@@ -1,30 +1,54 @@
# 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\]\[$GRAY\][\[$ORANGE\]\t \[$GREEN\]\w\[$GRAY\]]\[$RESET\]\$ '
fi
if [[ -z "$BRANCH" ]]; then
export BRANCH="dev"
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"
@@ -34,266 +58,294 @@ alias dcim="cd $DCIM"
export CODE="$SS/Code"
alias code="cd $CODE"
# Shortcuts for TRASH.
export TRASH="$SS/TRASH"
alias trash="cd $TRASH"
alias clean-trash="bash -c 'rm -rfv $TRASH/*'"
alias trash-clean="clean-trash"
alias check-trash="du -h $TRASH"
alias trash-check="check-trash"
# 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 "
## Functions ##
# Optimize the bitrate and audio levels for an edited video.
function process-video-usage {
echo "USAGE: process-video oldFile newFile [videoBitrate] [audioBitrate] [sizeRating]"
echo -n "Purpose: Call ffmpeg with preferred video posting settings. "
echo -n "Bitrates default to 2000k and 192k, size is 720. "
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"
### 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 process-video {
# Parameters
file="$1"
newfile="$2"
video="$3"
audio="$4"
size="$5"
passes="$6"
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"
# 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
video="-maxrate $video"
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
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
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
cd ..
done
}
alias pv="process-video"
alias code-check="check-code"
# Quickly commit code to a repo.
function commit {
message="$1"
if [[ -z $message ]]; then
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.
project="$HOME/.git-env-termux"
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"
# 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"
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
echo "No audio normalization is being done."
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 termux-test="test-termux "
alias termux-reload="reload-termux "
alias termux-update="reload-termux "
alias update-termux="reload-termux "
# 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
# 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
# Finish
if [[ ! -s $output ]]; then
echo "`date` - ERROR: Output '$output' not created or has 0 size." >&2
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
sync
echo "`date` - '$output' has been created successfully."
sleep 3
du -h "$input"
du -h "$output"
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
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}"
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
volume=""
if [[ ( "$2" == "Y" && -z "$3" ) || "$3" == "Y" ]]; then
$volume="Y"
fi
basic-process "$video" "$audio" $volume
fi
echo -e "\n* Verifying which branch we're on."
git branch
}
alias v2a="convert-to-audio"
alias vta="v2a"
alias va="v2a"
alias pa="v2a"
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"
# Go to normal storage. DISABLED, use shortcut aliases instead.
#cd ~/storage/shared/
## 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"
## Video Related ##
alias pull-content="mv -v $SS/DCIM/Camera/`date +"%Y-%m-%d"`* ./raw/"
alias pull-screenshots="mv -v $SS/Pictures/Screenshots/*`date +"%Y%m%d"`* ./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/*`date +"%Y%m%d"`* ./raw/"
alias pull-youcut="pull-youcuts"
alias pull-yc="pull-youcut"
alias pull-memes="mv -v $SS/Pictures/memetastic/memes/*`date +"%Y%m%d"`*.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 ##
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"
## 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!
PROG="$(basename -- "${BASH_SOURCE[0]}")"
echo "'$PROG' completed!"
echo "`date` - '$PROG' completed!"
-9
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!"
+18
View File
@@ -0,0 +1,18 @@
# Variables for fast-access of production server.
export PROD_HOST=example.com
export PROD_PORT=2222
export PROD_USER=user
export PROD_GIT_HOST=git.example.com
export PROD_GIT_PORT=8080
export PROD_GIT_USER=git
export PROD_GIT_BRANCH=main
export PROD_DATA_HOST=sftp.example.com
export PROD_DATA_PORT=2200
export PROD_DATA_USER=data
export PROD_DATA_DIR=/srv/sftp
PROG="$(basename -- "${BASH_SOURCE[0]}")"
echo "`date` - '$PROG' completed!"
+68 -21
View File
@@ -9,11 +9,23 @@ 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
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,50 +39,85 @@ 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
cp -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
fi
if [[ -e bashrc.sh ]]; then
mv -v bashrc.sh ~/.bashrc
cp -v bashrc.sh ~/.bashrc
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
if [[ ! -e ~/storage/shared/TRASH ]]; then
mkdir -pv ~/storage/shared/TRASH
if [[ ! -e ~/sdcard/TRASH ]]; then
mkdir -pv /sdcard/TRASH
fi
ln -s ~/storage/shared/TRASH ~/TRASH
ln -s /sdcard/TRASH ~/TRASH
if [[ -n $DIR && $DIR != "/" && -d .git ]]; then
if [[ ! -d ~/Code && ! -d ~/sdcard/Code ]]; then
mkdir -pv ~/Code
ln -s ~/Code /sdcard/Code
fi
env_shared_dir="$HOME/.env-shared"
if [[ ! -d "$env_shared_dir" ]]; then
echo -e "\n`date` - env-shared"
if [[ -z "$BRANCH" ]]; then
export BRANCH="dev"
fi
git clone https://git.hyperling.com/me/env-shared \
--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
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'`" |
grep -v '/.git/'
mv -v $DIR \
~/TRASH/termux-"`date +'%Y%m%d%H%M%S'`" \
| grep -v '/.git/'
else
echo "File was used individually, remove it."
mv "$PROG" ~/TRASH/
fi
echo -e "\n*******"
echo "Don't forget to reload your environment!"
echo " source ~/.bashrc"