General Enhancements, NixOS Support (#47)
* Begin adding Nix. * Install LBRY from Nix since its Flatpak is no longer supported.. * Got the global install to work, now just figuring out why LBRY won't work. * Add alias to blow away dev branch and start back up from remote or main. * Nix install not really working, requires manual intervention, maybe add to setup.sh or just try NixOS and see if it can 'replace' this entire Ansible project and cease the use of multiple operating systems. * Start working on having a path for NixOS. * Add NixOS. * Skip the installer portion if using NixOS. * Start including more tasks. ALl work besides GNOME due to psutil, even though it is included in configuration.nix. * This should have never been added. Was an accident if it snuck though. * Test using env rather than hard-coded bash path. * Use variables, start thinking about future. * Add file to manage setting up NixOS for the first or any subsequent times. * Use the new nixos.sh script. * Ensure /usr/local/bin is in PATH. * Do not use * inside of "" for ls. * Add filename cleanup shortcut. * Add a clean option as well as a few bugfixes and checking that convert is installed. * Use underscores in filenames and remove plurality. * Bring the file into better column compliance. * Stop running the dconf psutil failures against NixOS for now. * Ensure the old names of scripts are removed from bin. * Clean filename fixes as well as a traversing version. * Remove extra spacing. * Begin adding swapfile creation. * Add dangerous code reset command. * Add some cleaning for NixOS package manager. * The ~ was being taken literally and created as a new folder. * More work on swap files, and a new ansible.nix file. * Fix the swap confuration line. * Finish the swap configuration by checking if it already exists. Always keep the fstab line in existence. * Reorder and enhance the update function for NixOS. * Add comment. * Start working on dconf for NixOS since don't have home-manager working yet in configration.nix. * Add notes. * If the file was created, make sure the user owns it and can edit by default. * Favorites are working and only need maintained in one place! :) * Add .zshrc for GNOME settings on NixOS. * Add most other settings that are done manually post-install. Report any failures with their placement. * FINALLY! Keyboard shortcuts and some final Gnome Tweak settings! * Add night light settings. * Move around some comments. * Pull first then deal with any merge issues, rather than trying to push when there are things to pull. * Test removing the dconf commands for non-NixOS. * Alter output; remove extra newlines and add cache verbosity. * dconf in rc files is working on Ubuntu! * Add delete. Fix filename quotes. Other enhancements. * Create new folder chain if clean changed directory names. * Add TBD about changing the directory structure. * Only say success if the file really exists. Skip if conversion fails. * Only say success if the file really exists. Skip if conversion fails. * Add quotes around dirname. * Add quotes around the entire directory tree. * Add quotes to comment in case it ever gets used. * Add a bittorrent client. * Disable Bluetooth on all devices, it's normally off anyways. * Fix comments, this enables not disables. * Create new services report. * Add services report to main area and move all reports to NixOS area. * Fix swap file variable name for non-NixOS distros. * Add godot editor. * Re-add extra programs Geary and OpenShot for variety. * Shorten the output for 80 char terminals. * Add Code-OSS for when Codium is having issues. * Allow code-oss to be installed. * Add the full desktop entry for Code-OSS. * Ansible handles the newlines, prevent the -e from getting into the file. * Enhance newlines in nmap report. * Add NixOS.
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
|
||||
DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
||||
echo "Running $DIR/$PROG"
|
||||
echo "Running '$DIR/$PROG'."
|
||||
|
||||
# Integers
|
||||
typeset -i size status
|
||||
@ -28,7 +28,7 @@ function usage() {
|
||||
# Parameters:
|
||||
# 1) The exit status to use.
|
||||
status=$1
|
||||
echo "Usage: $PROG [-s SIZE] [-l LOCATION] [-r] [-f] [-d] [-h] [-x]" >&2
|
||||
echo "Usage: $PROG [-s SIZE] [-l LOCATION] [-r] [-f] [-d] [-c] [-h] [-x]" >&2
|
||||
cat <<- EOF
|
||||
Compress JPG or PNG image(s). Can handle folders and work recursively.
|
||||
|
||||
@ -38,6 +38,7 @@ function usage() {
|
||||
-r : Recursively shrink images based on the location passed.
|
||||
-f : Force the image to be shrunk even if a file already exists for it.
|
||||
-d : Delete the original image if the compressed image is smaller.
|
||||
-c : Clean the filename of underscores, dashes, 'IMG', etc.
|
||||
-h : Display this usage text.
|
||||
-x : Enable BASH debugging.
|
||||
EOF
|
||||
@ -46,13 +47,14 @@ function usage() {
|
||||
|
||||
## Parameters ##
|
||||
|
||||
while getopts ":s:l:rfdhx" opt; do
|
||||
while getopts ":s:l:rfdchx" opt; do
|
||||
case $opt in
|
||||
s) in_size="$OPTARG" && size="$in_size" ;;
|
||||
l) location="$OPTARG" ;;
|
||||
r) recurse="Y" && search="find" ;;
|
||||
f) force="Y" ;;
|
||||
d) delete="Y" ;;
|
||||
c) clean="Y" ;;
|
||||
h) usage 0 ;;
|
||||
x) set -x ;;
|
||||
*) echo "ERROR: Option $OPTARG not recognized." >&2 && usage 1 ;;
|
||||
@ -66,6 +68,13 @@ if [[ -n "$in_size" && "$size" != "$in_size" ]]; then
|
||||
usage 1
|
||||
fi
|
||||
|
||||
convert_exe="`which convert`"
|
||||
if [[ "$convert_exe" == "" ]]; then
|
||||
echo "ERROR: 'convert' command could not be found, "
|
||||
echo "please install 'imagemagick'."
|
||||
usage 2
|
||||
fi
|
||||
|
||||
## Main ##
|
||||
|
||||
# If using ls, make sure full path is passed to the loop by adding '/*'.
|
||||
@ -73,7 +82,6 @@ if [[ -z "$recurse" && -d "$location" && "$location" != *'/*' ]]; then
|
||||
if [[ "$location" != *'/' ]]; then
|
||||
location="${location}/"
|
||||
fi
|
||||
location="${location}*"
|
||||
fi
|
||||
|
||||
$search "$location" | sort | while read image; do
|
||||
@ -98,20 +106,40 @@ $search "$location" | sort | while read image; do
|
||||
|
||||
new_image="${image//.$extension/}.$tag-$date_YYYYMMDD.$extension"
|
||||
|
||||
# Clean the filename of extra junk so that they can be chronological order.
|
||||
new_image_clean="${new_image//IMG/}"
|
||||
new_image_clean="${new_image_clean//_/}"
|
||||
new_image_clean="${new_image_clean//-/}"
|
||||
new_image_clean="${new_image_clean// /}"
|
||||
|
||||
# Delete the existing shrunk image if we are forcing a new compression.
|
||||
if [[ -n "$force" && -e "$new_image" ]]; then
|
||||
if [[ -n "$force" && (-e "$new_image" || -e $new_image_clean) ]]; then
|
||||
echo -n " FORCE: "
|
||||
rm -v "$new_image"
|
||||
rm -v "$new_image" "$new_image_clean" 2>/dev/null
|
||||
fi
|
||||
|
||||
# Skip if a compressed image was already created today.
|
||||
if [[ -e "$new_image" ]]; then
|
||||
if [[ -e "$new_image" || -e $new_image_clean ]]; then
|
||||
echo " SKIP: Image has already been shrunk previously, moving on."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Whether or not to use the cleaned version or the normal version.
|
||||
if [[ -n $clean ]]; then
|
||||
new_image="$new_image_clean"
|
||||
fi
|
||||
|
||||
### TBD Instead of this, only alter the file names, and set a dirname var?
|
||||
# Create a new directory if the directory names were altered.
|
||||
mkdir -pv "`dirname "$new_image"`"
|
||||
|
||||
# This modifies the image to be $size at its longest end, not be a square.
|
||||
convert "$image" -resize ${size}x${size} "$new_image"
|
||||
$convert_exe "$image" -resize ${size}x${size} "$new_image"
|
||||
status="$?"
|
||||
if [[ "$status" != 0 ]]; then
|
||||
echo " SKIP: '$convert_exe' returned a status of '$status'."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check file sizes and if the new one is larger then flag it as large.
|
||||
echo " Checking file sizes:"
|
||||
@ -130,7 +158,12 @@ $search "$location" | sort | while read image; do
|
||||
continue
|
||||
fi
|
||||
|
||||
echo " SUCCESS: Conversion succeeded, file has been compressed."
|
||||
if [[ -e "$new_image" ]]; then
|
||||
echo " SUCCESS: Conversion succeeded, file has been compressed."
|
||||
else
|
||||
echo " ERROR: New image '$new_image' could not be found. Aborting."
|
||||
break;
|
||||
fi
|
||||
|
||||
if [[ -n "$delete" ]]; then
|
||||
echo -n " DELETE: "
|
||||
@ -143,7 +176,6 @@ $search "$location" | sort | while read image; do
|
||||
done
|
||||
|
||||
# If large files do end up being created, allow the user to bulk delete them.
|
||||
echo "FORTEST"
|
||||
if [[ -e "$large_created" ]]; then
|
||||
echo -e "\n*********************************************************"
|
||||
echo -e "WARNING: The files below are larger than their originals!\n"
|
@ -4,20 +4,20 @@
|
||||
|
||||
## Setup ##
|
||||
|
||||
DIR=`dirname $0`
|
||||
PROG=`basename $0`
|
||||
if [[ "$DIR" == '.' ]]; then
|
||||
DIR=`pwd`
|
||||
fi
|
||||
echo "Running $DIR/$PROG"
|
||||
DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
||||
echo "Running '$DIR/$PROG'."
|
||||
|
||||
filename_flag='compressed'
|
||||
date_YYYYMMDD="`date "+%Y%m%d"`"
|
||||
large_extension='DoNotUse-LargerThanOriginal'
|
||||
large_created=".$PROG.large_created.true"
|
||||
|
||||
## Functions ##
|
||||
|
||||
function usage {
|
||||
echo "Usage: $PROG [-i file/folder] [-v bitrate] [-a bitrate] [-c vcodec] [-r] [-f] [-m] [-V] [-x] [-h]"
|
||||
echo -n "Usage: $PROG [-i file/folder] [-v bitrate] [-a bitrate] [-c vcodec]"
|
||||
echo " [-r] [-f] [-d] [-m] [-V] [-x] [-h]"
|
||||
cat <<- EOF
|
||||
Reduce the filesize of a video file to make it stream well. It also
|
||||
helps with the file size for placing the file into a backup system.
|
||||
@ -31,6 +31,7 @@ function usage {
|
||||
-c vcodec : The video codec you'd like to use, such as libopenh264.
|
||||
-r : Recurse the entire directory structure, compressing all video files.
|
||||
-f : Force recompressing any files by deleting it if it already exists.
|
||||
-d : Delete the original video if the compressed version is smaller.
|
||||
-m : Measure the time it takes to compress each video and do the loop.
|
||||
-V : Add verbosity, such as printing all the variable values.
|
||||
-x : Set the shell's x flag to display every action which is taken.
|
||||
@ -41,7 +42,7 @@ function usage {
|
||||
|
||||
## Parameters ##
|
||||
|
||||
while getopts ":i:v:a:c:rfmVxh" opt; do
|
||||
while getopts ":i:v:a:c:rfdmVxh" opt; do
|
||||
case $opt in
|
||||
i) input="$OPTARG"
|
||||
;;
|
||||
@ -55,6 +56,8 @@ while getopts ":i:v:a:c:rfmVxh" opt; do
|
||||
;;
|
||||
f) force="Y"
|
||||
;;
|
||||
d) delete="Y"
|
||||
;;
|
||||
m) time_command="time -p"
|
||||
;;
|
||||
V) verbose="Y"
|
||||
@ -109,6 +112,7 @@ if [[ "$verbose" == "Y" ]]; then
|
||||
codec='$codec'
|
||||
search_command='$search_command'
|
||||
force='$force'
|
||||
delete='$delete'
|
||||
time_command='$time_command'
|
||||
verbose='$verbose'
|
||||
set_x='$set_x'
|
||||
@ -119,7 +123,7 @@ if [[ "$verbose" == "Y" ]]; then
|
||||
fi
|
||||
|
||||
SECONDS=0
|
||||
$search_command $input | sort | while read file; do
|
||||
$search_command "$input" | sort | while read file; do
|
||||
echo -e "\n$file"
|
||||
|
||||
if [[ -n "$time_command" ]]; then
|
||||
@ -140,13 +144,16 @@ $search_command $input | sort | while read file; do
|
||||
extension="${file##*.}"
|
||||
newfile="${file//$extension/$filename_flag-$date_YYYYMMDD.$extension}"
|
||||
|
||||
# Convert spaces to underscores.
|
||||
newfile="${newfile// /_}"
|
||||
#### Convert spaces to underscores.
|
||||
###newfile="${newfile// /_}"
|
||||
###
|
||||
#### Ensure any directories that had spaces get recreated without them.
|
||||
###mkdir -pv "`dirname "$newfile"`"
|
||||
|
||||
# More exception checks based on the new file.
|
||||
if [[ -e "$newfile" ]]; then
|
||||
if [[ "$force" == "Y" ]]; then
|
||||
echo "FORCE: Removing $newfile."
|
||||
echo "FORCE: Removing '$newfile'."
|
||||
rm -vf "$newfile"
|
||||
else
|
||||
echo "SKIP: Already has a compressed version ($newfile)."
|
||||
@ -155,24 +162,66 @@ $search_command $input | sort | while read file; do
|
||||
fi
|
||||
|
||||
# Convert the file.
|
||||
echo "Converting to $newfile."
|
||||
echo "Converting to '$newfile'."
|
||||
$time_command bash -c "ffmpeg -nostdin -hide_banner -loglevel quiet \
|
||||
-i '$file' -b:v $video_bitrate -b:a $audio_bitrate \
|
||||
$vcodec -movflags +faststart $newfile"
|
||||
$vcodec -movflags +faststart '$newfile'"
|
||||
status="$?"
|
||||
if [[ "$status" != 0 ]]; then
|
||||
echo "SKIP: ffmpeg returned a status of '$status'."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check the filesize compared to the original and note if it is larger.
|
||||
echo "Checking file sizes:"
|
||||
ls -sh $file $newfile | sort -hr
|
||||
smaller_file=`ls -sh $file $newfile | sort -h | awk '{print $2}' | head -n 1`
|
||||
ls -sh "$file" "$newfile" | sort -hr
|
||||
smaller_file=`ls -sh "$file" "$newfile" | sort -h | awk '{print $2}' | head -n 1`
|
||||
if [[ "$smaller_file" == "$file" ]]; then
|
||||
echo -n "Conversion had the opposite effect, original was likely lesser "
|
||||
echo "quality. Adding a suffix to the file to signify that it grew."
|
||||
mv -v $newfile $newfile.DoNotUse-LargerThanOriginal
|
||||
else
|
||||
mv -v "$newfile" "$newfile.$large_extension"
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ -e "$newfile" ]]; then
|
||||
echo "Conversion succeeded, file has been compressed."
|
||||
else
|
||||
echo "ERROR: Converted file '$newfile' could not be found. Aborting."
|
||||
break
|
||||
fi
|
||||
|
||||
if [[ -n "$delete" ]]; then
|
||||
echo -n "Original has been deleted: "
|
||||
if [[ -d ~/TRASH ]]; then
|
||||
mv -v "$file" ~/TRASH/
|
||||
else
|
||||
rm -v "$file"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# If large files do end up being created, allow the user to bulk delete them.
|
||||
if [[ -e "$large_created" ]]; then
|
||||
echo -e "\n*********************************************************"
|
||||
echo -e "WARNING: The files below are larger than their originals!\n"
|
||||
find "$input" -name "*"$large_extension
|
||||
echo -e "*********************************************************"
|
||||
|
||||
echo -en "\nWould you like to delete them? (Y/n): "
|
||||
typeset -u confirm_delete
|
||||
read confirm_delete
|
||||
|
||||
if [[ -z "$confirm_delete" || "$confirm_delete" == "Y"* ]]; then
|
||||
echo ""
|
||||
find "$input" -name "*"$large_extension -exec rm -v {} \;
|
||||
else
|
||||
echo -e "\nKeeping files. Please use this if you change your mind:"
|
||||
echo " find \"$input\" -name \"*\"$large_extension -exec rm -v {} \;"
|
||||
fi
|
||||
|
||||
rm "$large_created"
|
||||
fi
|
||||
|
||||
echo -e "\nDone!"
|
||||
|
||||
# Display elapsed time
|
57
files/scripts/nixos.sh
Executable file
57
files/scripts/nixos.sh
Executable file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
# Script to consistently install configuration.nix.
|
||||
# To be called by Ansible via setup.sh and nixos.yml, as well as CLI by users.
|
||||
|
||||
## Variables ##
|
||||
|
||||
DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
||||
|
||||
nixos_working_dir=~/nixos-config-deleteme
|
||||
nixos_working_exe=activate.sh
|
||||
|
||||
## Functions ##
|
||||
|
||||
function usage {
|
||||
echo -e "\nUsage: $PROG -b BRANCH" >&2
|
||||
cat <<- EOF
|
||||
Run a setup script for NixOS based on the https://github.com/Hyperling/NixOS project.
|
||||
|
||||
Parameters:
|
||||
-b BRANCH: The branch which should be installed, likely 'main' or 'dev'.
|
||||
EOF
|
||||
echo ""
|
||||
exit $1
|
||||
}
|
||||
|
||||
function cleanup {
|
||||
sh -c "rm -rfv $nixos_working_dir" >/dev/null
|
||||
}
|
||||
|
||||
## Parameters ##
|
||||
|
||||
while getopts ":b:h" opt; do
|
||||
case $opt in
|
||||
b) branch="$OPTARG" ;;
|
||||
h) usage 0 ;;
|
||||
*) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z $branch ]]; then
|
||||
echo "ERROR: Branch is required. $branch" >&2
|
||||
usage 2
|
||||
fi
|
||||
|
||||
## Main ##
|
||||
|
||||
cleanup
|
||||
|
||||
# Install the Hyperling NixOS configurations.
|
||||
git clone https://github.com/Hyperling/NixOS --branch $branch $nixos_working_dir
|
||||
chmod 755 $nixos_working_dir/$nixos_working_exe
|
||||
$nixos_working_dir/$nixos_working_exe
|
||||
|
||||
cleanup
|
||||
|
||||
exit 0
|
Reference in New Issue
Block a user