Compare commits
83 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9f2802359 | |||
| 3486e238d4 | |||
| 3ed66ea059 | |||
| 46e6b205a9 | |||
| ea40967e2b | |||
| 86ad8c5b5c | |||
| fd227c810c | |||
| 4744d996a1 | |||
| bd0c01fda6 | |||
| c323748cec | |||
| 6226d00a1c | |||
| f199605915 | |||
| 6356497cb6 | |||
| b7d189af66 | |||
| dbc0a711c4 | |||
| ae636f4fbe | |||
| 42f4ef919f | |||
| 2662966098 | |||
| 16ded2672e | |||
| bd7ac08dfe | |||
| b1a0586df7 | |||
| 09aec0e5d0 | |||
| 891822aad3 | |||
| 6d728dd9ad | |||
| f0a2c39bf8 | |||
| 132ae721e7 | |||
| d25e94d267 | |||
| 226aa5dd6d | |||
| b8e4b9bfc3 | |||
| 83f3288031 | |||
| a8952795bd | |||
| 9bde085ab4 | |||
| 7e7214eaf7 | |||
| ab396a9739 | |||
| abc56b57cd | |||
| 68fea2f314 | |||
| 7237184456 | |||
| ee651659aa | |||
| aa5a6e7b77 | |||
| 0485f27205 | |||
| f811070949 | |||
| 1e3f6a7402 | |||
| 37db32a78b | |||
| 40af484ddd | |||
| fa98b50827 | |||
| 7f9494411b | |||
| 1957f4fdab | |||
| 14d8a61f49 | |||
| 07ca207fd1 | |||
| 0494b05bb7 | |||
| 55102cc9fd | |||
| 4d740d7d2f | |||
| 080669359a | |||
| 4cfeb6073c | |||
| 74bdd45ef7 | |||
| 98fc25a132 | |||
| a0962cb04d | |||
| e85947cb0c | |||
| 3c285298eb | |||
| a9c9f3b784 | |||
| 53fbb829a3 | |||
| 28219c97ed | |||
| 876a106ea0 | |||
| 3554a40622 | |||
| b0fcdb9429 | |||
| 0a26a3b3e8 | |||
| 663079c0cd | |||
| 33c60504bd | |||
| a5791e2bc6 | |||
| 3763fc6000 | |||
| 49d9c95c85 | |||
| 6220e70480 | |||
| 2324acb6d6 | |||
| e27924f062 | |||
| d3dc527b26 | |||
| 7ceb1f436b | |||
| 8ef92669cd | |||
| d793218215 | |||
| bb0bcc27c8 | |||
| bdd7e7855b | |||
| 060a3b25d8 | |||
| 6b3975176a | |||
| 67ef7d128f |
@@ -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.
|
||||
|
||||
461
bashrc.sh
461
bashrc.sh
@@ -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\]\[$GRAY\][\[$ORANGE\]\t \[$GREEN\]\w\[$GRAY\]]\[$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,146 +56,74 @@ 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 rm="echo 'Move to ~/storage/shared/TRASH/ instead!'"
|
||||
|
||||
# Quickies
|
||||
alias update="pkg update && pkg upgrade"
|
||||
alias bye="exit"
|
||||
alias goodbye="update -y && bye"
|
||||
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
|
||||
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"
|
||||
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 "ERROR: New file not created or has a 0 size." >&2
|
||||
echo "* Not a valid git project, skipping."
|
||||
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
|
||||
}
|
||||
|
||||
@@ -184,116 +131,206 @@ 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
|
||||
~/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"
|
||||
# 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
|
||||
|
||||
# Validations
|
||||
if [[ -z $input || ! -e $input ]]; then
|
||||
echo "ERROR: Input file '$input' does not exist." >&2
|
||||
basic-process-usage
|
||||
if [[ "$rcvr" == "main" ]]; then
|
||||
echo "*** ERROR: Are you nuts, fool!? Not main! Do it manually! ***"
|
||||
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 [[ -z "$base" ]]; then
|
||||
if [[ "$rcvr" == "prod" ]]; then
|
||||
base="stage"
|
||||
elif [[ "$rcvr" == "stage" ]]; then
|
||||
base="dev"
|
||||
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
|
||||
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"
|
||||
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"
|
||||
|
||||
|
||||
## Video Related ##
|
||||
|
||||
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 ##
|
||||
|
||||
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
|
||||
}
|
||||
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}"
|
||||
else
|
||||
echo "File still needed, downloading to local tmp/."
|
||||
fi
|
||||
volume=""
|
||||
if [[ ( "$2" == "Y" && -z "$3" ) || "$3" == "Y" ]]; then
|
||||
$volume="Y"
|
||||
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
|
||||
basic-process "$video" "$audio" $volume
|
||||
}
|
||||
alias v2a="convert-to-audio"
|
||||
alias vta="v2a"
|
||||
alias va="v2a"
|
||||
alias pa="v2a"
|
||||
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"
|
||||
|
||||
# Go to normal storage. DISABLED, use shortcut aliases instead.
|
||||
#cd ~/storage/shared/
|
||||
|
||||
# Export all functions! #
|
||||
eval "$(declare -F | grep -v _ | sed 's/-f /-fx /')"
|
||||
|
||||
# Complete!
|
||||
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
||||
echo "'$PROG' completed!"
|
||||
echo "`date` - '$PROG' completed!"
|
||||
|
||||
@@ -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
example.env
Normal file
18
example.env
Normal 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
setup.sh
68
setup.sh
@@ -9,11 +9,23 @@ cd $DIR
|
||||
DIR="`pwd`"
|
||||
echo "Working in '$DIR'."
|
||||
|
||||
|
||||
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,23 +39,30 @@ else
|
||||
echo "Everything looks good already, pal."
|
||||
fi
|
||||
|
||||
|
||||
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 \
|
||||
nmap traceroute wget \
|
||||
openssh tsu vim htop git cronie man zip ncurses-utils \
|
||||
nmap traceroute wget rsync \
|
||||
ffmpeg imagemagick \
|
||||
kotlin php nodejs python libllvm
|
||||
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 +71,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,16 +82,41 @@ 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
|
||||
cp -v ~/$env_shared_dir/vimrc.vim ~/.vimrc
|
||||
if [[ ! -d ~/bin ]]; then
|
||||
mkdir -pv ~/bin
|
||||
fi
|
||||
cp -v ~/$env_shared_dir/bin-shared/* ~/bin/
|
||||
mv -v ~/$env_shared_dir \
|
||||
~/TRASH/$env_shared_dir-"`date "+%Y%m%d-%H%M%S"`" \
|
||||
| grep -v '/.git/'
|
||||
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user