From b47183af767d07e9a7644d153849273f28be6f5f Mon Sep 17 00:00:00 2001 From: Chad Date: Mon, 26 Jun 2023 06:58:09 -0700 Subject: [PATCH] Enhancements + Fixes (#41) * Signal does seem good after all. * Add alias `here` which shows details of everything in the current location. * Move instant messengers to consistently be at the end of the favorites bar. * Change to single quotes so that the pwd is per-call instead of per-source. * Specify the video codec so that the command works on openSUSE. * Refactor so that there is a shared/common fact list. * Add ffmpeg as a package variable. * Reformat long comment. * New file for installing package manager apps for workstations. * Call the workstation package manager tasks. * Change to parenthesis to look better. * Explicitly add a video flag, add recursive searching, fix a bug with -f ignoring input. * Add ability to "force" the compression, deletes old files and regenerates them. Input is now passed with i rather than f for file/folder. f is now used for force. * Fix skipping the file if it's already compressed. Enhance readability of log text. --- facts/general/package.yml | 12 ++- facts/workstation/package.yml | 1 + files/scripts/compress-video.sh | 77 +++++++++++++------ local.yml | 3 + tasks/general/acct_mgmt/users.yml | 2 + tasks/general/software/packages.yml | 4 +- tasks/workstation/linux/software/flatpaks.yml | 2 +- tasks/workstation/linux/software/packages.yml | 9 +++ tasks/workstation/shared/settings/gnome.yml | 5 +- 9 files changed, 77 insertions(+), 38 deletions(-) create mode 100644 tasks/workstation/linux/software/packages.yml diff --git a/facts/general/package.yml b/facts/general/package.yml index c7a67c5..1546deb 100644 --- a/facts/general/package.yml +++ b/facts/general/package.yml @@ -2,6 +2,11 @@ # Define program names for package builtin. # This file is for ALL systems and should not include UI components. +- name: General | Facts | Packages | Shared Defaults + set_fact: + sshfs: sshfs + tar: tar + - name: General | Facts | Packages | Parrot OS Fixes set_fact: ansible_pkg_mgr: "apt" @@ -10,10 +15,8 @@ - name: General | Facts | Package | apt set_fact: - sshfs: sshfs locate: locate opensshd: openssh-server - tar: tar microcode_amd: amd64-microcode microcode_intel: intel-microcode cron: cron @@ -21,10 +24,8 @@ - name: General | Facts | Package | pacman set_fact: - sshfs: sshfs locate: mlocate opensshd: openssh - tar: tar microcode_amd: linux-firmware microcode_intel: intel-ucode cron: cronie @@ -46,7 +47,6 @@ sshfs: fuse-sshfs locate: mlocate opensshd: openssh - tar: tar microcode_amd: microcode_ctl microcode_intel: microcode_ctl cron: cronie @@ -54,10 +54,8 @@ - name: General | Facts | Package | zypper set_fact: - sshfs: sshfs locate: mlocate opensshd: openssh - tar: tar microcode_amd: ucode-amd microcode_intel: ucode-intel cron: cronie diff --git a/facts/workstation/package.yml b/facts/workstation/package.yml index 37ef39f..2731f58 100644 --- a/facts/workstation/package.yml +++ b/facts/workstation/package.yml @@ -25,6 +25,7 @@ font_awesome: fonts-font-awesome dmenu: dmenu sassc: sassc + ffmpeg: ffmpeg - name: Workstation | Facts | Package | Pop_OS! diff --git a/files/scripts/compress-video.sh b/files/scripts/compress-video.sh index 04c6ded..31f7ae3 100755 --- a/files/scripts/compress-video.sh +++ b/files/scripts/compress-video.sh @@ -14,41 +14,52 @@ function usage { 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. + Currently only set up for libopenh264 and mp4 files. Parameters: - -f input : The input file or folder with which to search for video files. + -i input : The input file or folder with which to search for video files. If nothing is provided, current directory (.) is assumed. -v bitrate : The video bitrate to convert to, defaults to 2000k. -a bitrate : The audio bitrate to convert to, defaults to 128k. + -r : Recurse the entire directory structure, compressing all video files. + -f : Force recompressing any files by deleting it if it already exists. -h : Display this help messaging. EOF exit $1 } ## Parse Input -while getopts ":f:v:a:h" opt; do +while getopts ":i:v:a:rfh" opt; do case $opt in - f) - input="$OPTARG" + i) input="$OPTARG" + echo "input='$input'" ;; - v) - video_bitrate="$OPTARG" + v) video_bitrate="$OPTARG" + echo "video_bitrate='$video_bitrate'" ;; - a) - audio_bitrate="$OPTARG" + a) audio_bitrate="$OPTARG" + echo "audio_bitrate='$audio_bitrate'" ;; - h) - usage 0 + r) recurse="Y" + search_command=find + echo "recurse='$recurse', search_command='$search_command'" + ;; + f) force="Y" + echo "force='$force'" + ;; + h) usage 0 ;; esac done -if [[ -z $input && ! -z $1 ]]; then - echo "WARNING: Program was not passed a file. Using input 1." - input=$1 -else - echo "WARNING: Program was not passed a file. Using current directory." - input='.' +if [[ -z "$input" ]]; then + if [[ ! -z "$1" ]]; then + echo "WARNING: Program was not passed a file. Using input $1." + input=$1 + else + echo "WARNING: Program was not passed a file. Using current directory." + input='.' + fi fi if [[ -z $video_bitrate ]]; then @@ -59,14 +70,24 @@ if [[ -z $audio_bitrate ]]; then audio_bitrate='128k' fi +if [[ -z $recurse ]]; then + search_command=ls +fi + ## Other Variables filename_flag='compressed.' ## Main Loop -ls $input | while read file; do - ## Exception Checks - if [[ $file != *'.mp4' && $file != *'.mpeg' ]]; then - echo "Skipping $file, not an MP4 or MPEG." +$search_command $input | while read file; do + echo -e "\n$file" + + # Exception checks for the existing file. + if [[ $file != *'.mp4' ]]; then + echo "SKIP: Not an MP4." + continue + fi + if [[ $file == *"$filename_flag"* ]]; then + echo "SKIP: Input is already compressed." continue fi @@ -74,16 +95,22 @@ ls $input | while read file; do extension=${file##*.} newfile=${file//$extension/$filename_flag$extension} - if [[ $file == *"$filename_flag"* || -e $newfile ]]; then - echo "Skipping $file, already compressed." - continue + # More exception checks based on the new file. + if [[ -e $newfile ]]; then + if [[ $force == "Y" ]]; then + echo "FORCE: Removing $newfile." + rm -vf $newfile + else + echo "SKIP: Already has a compressed version ($newfile)." + continue + fi fi # Convert the file. - echo "Converting $file to $newfile." + echo "Converting to $newfile." ffmpeg -nostdin -hide_banner -loglevel quiet \ -i $file -b:v $video_bitrate -b:a $audio_bitrate \ - $newfile + -vcodec libopenh264 -movflags +faststart $newfile done exit 0 diff --git a/local.yml b/local.yml index decc67a..fab2929 100644 --- a/local.yml +++ b/local.yml @@ -66,6 +66,9 @@ - include_tasks: tasks/workstation/linux/software/flatpaks.yml when: ansible_system == "Linux" and flatpak_distro + - include_tasks: tasks/workstation/linux/software/packages.yml + when: ansible_system == "Linux" + - include_tasks: tasks/workstation/linux/software/brave.yml when: ansible_pkg_mgr in ("apt", "dnf", "zypper") and not mobile diff --git a/tasks/general/acct_mgmt/users.yml b/tasks/general/acct_mgmt/users.yml index 1a44aab..23b0736 100644 --- a/tasks/general/acct_mgmt/users.yml +++ b/tasks/general/acct_mgmt/users.yml @@ -279,6 +279,7 @@ echo "ERROR: Something went wrong while removing Flatpak apps!" } alias_vim: alias vi=vim + alias_here: alias here='ls -lh `pwd`/*' - name: General | Account Management | Users | Files | Common Variable set_fact: @@ -305,6 +306,7 @@ {{ function_flatpak_usage }} {{ function_flatpak_purge }} {{ alias_vim }} + {{ alias_here }} - name: General | Account Management | Users | Files | .bashrc blockinfile: diff --git a/tasks/general/software/packages.yml b/tasks/general/software/packages.yml index 0edc176..84f5d48 100644 --- a/tasks/general/software/packages.yml +++ b/tasks/general/software/packages.yml @@ -19,8 +19,8 @@ shell: exit 1 when: ansible_distribution == "Parrot OS" and parrotos_zypper_removed is defined and not parrotos_zypper_removed.failed -# More Parrot OS junk. They have a command called update in /usr/bin. Doesn't have sudo or anything in it either. -# Hide it in preference for .bashrc update function. +# More Parrot OS junk. They have a command called update in /usr/bin. Doesn't +# have sudo or anything in it. Hide it in preference for .bashrc update function. - name: General | Software | Packages | Fix Parrot OS 2 (update) shell: "mv `which update` `which update`.zz.`date +%Y%m%d`" ignore_errors: yes diff --git a/tasks/workstation/linux/software/flatpaks.yml b/tasks/workstation/linux/software/flatpaks.yml index 39f076e..da858ff 100644 --- a/tasks/workstation/linux/software/flatpaks.yml +++ b/tasks/workstation/linux/software/flatpaks.yml @@ -39,6 +39,7 @@ - { app: "io.lbry.lbry-app", name: "lbry", extra: "dbus-launch" } - { app: "io.gitlab.librewolf-community", name: "librewolf", extra: "" } - { app: "chat.delta.desktop", name: "deltachat", extra: "" } + - { app: "org.signal.Signal", name: "signal", extra: "" } flatpaks_coding: - { app: "com.vscodium.codium", name: "codium", extra: "" } - { app: "com.google.AndroidStudio", name: "android-studio", extra: "" } @@ -63,7 +64,6 @@ - { app: "com.discordapp.Discord", name: "discord", extra: "" } # Stopped working, just spins and says Starting. # 2022-11-20 No longer using any of these and they're taking up a lot of space. # - { app: "im.riot.Riot", name: "element", extra: "" } - - { app: "org.signal.Signal", name: "signal", extra: "" } - { app: "org.telegram.desktop", name: "telegram", extra: "" } - { app: "com.jetbrains.PyCharm-Community", name: "pycharm", extra: "" } # End 2022-11-20 # diff --git a/tasks/workstation/linux/software/packages.yml b/tasks/workstation/linux/software/packages.yml new file mode 100644 index 0000000..727a917 --- /dev/null +++ b/tasks/workstation/linux/software/packages.yml @@ -0,0 +1,9 @@ +--- +# Packages specific to workstations. + +- name: Workstation | Software | Packages | Install Software (Editing) + package: + name: + - "{{ ffmpeg }}" + state: present + when: editing == true diff --git a/tasks/workstation/shared/settings/gnome.yml b/tasks/workstation/shared/settings/gnome.yml index d5b3f88..07a82df 100644 --- a/tasks/workstation/shared/settings/gnome.yml +++ b/tasks/workstation/shared/settings/gnome.yml @@ -171,11 +171,10 @@ , 'org.gnome.Nautilus.desktop' , 'io.gitlab.librewolf-community.desktop', '{{ browser }}' , 'org.gnome.Evolution.desktop', 'chat.delta.desktop.desktop' - , 'org.signal.Signal.desktop' , 'com.vscodium.codium.desktop', 'org.shotcut.Shotcut.desktop' - , 'org.telegram.desktop.desktop', 'com.discordapp.Discord.desktop' - , 'im.riot.Riot.desktop' , 'io.lbry.lbry-app.desktop' + , 'org.signal.Signal.desktop', 'im.riot.Riot.desktop' + , 'org.telegram.desktop.desktop', 'com.discordapp.Discord.desktop' , 'com.valvesoftware.Steam.desktop' ]" state: present