terça-feira, 30 de abril de 2024

Script para copiar arquivos para o pendrive (USB Flash Drive)

No Linux, os arquivos são gravados definitivamente apenas após a desmontagem da partição. Isso pode explicar por que muitas ferramentas gráficas apresentam desempenho insatisfatório ao gravar arquivos em pendrives. Para contornar esse problema, desenvolvi um pequeno script que, até o momento, tem funcionado bem.

#!/bin/bash

declare -r MOUNT_POINT="/media/flashdrive"

# Define sudo command or alternative for elevated privileges
SUDO="sudo"

# Check for sudo access at the start if a sudo command is used
if [[ -n "$SUDO" ]] && ! "$SUDO" -v &> /dev/null; then
    echo "Error: This script requires sudo access to run." >&2
    exit 1
fi

# Function to check for required commands
check_dependencies() {
    local dependencies=(lsblk mkdir mount umount cp du grep diff rsync sync blkid mkfs.exfat)
    local missing=()
    for cmd in "${dependencies[@]}"; do
        if ! command -v "$cmd" &> /dev/null; then
            missing+=("$cmd")
        fi
    done
    if [[ ${#missing[@]} -ne 0 ]]; then
        echo "Error: Required commands not installed: ${missing[*]}" >&2
        exit 1
    fi
}

# Function to safely sync and unmount the device
safe_unmount() {
    local device="$1"
    if mount | grep -qw "$device"; then
        echo "Syncing device..."
        sync
        echo "$device is currently mounted, attempting to unmount..."
        "$SUDO" umount "$device" && echo "$device unmounted successfully." || { echo "Failed to unmount $device."; return 1; }
    fi
}

# Function to mount drive
ensure_mounted() {
    local device="$1"
    if ! mount | grep -q "$MOUNT_POINT"; then
        echo "Mounting $device..."
        "$SUDO" mkdir -p "$MOUNT_POINT"
        "$SUDO" mount "$device" "$MOUNT_POINT" || { echo "Failed to mount $device."; exit 1; }
    else
        echo "Device is already mounted on $MOUNT_POINT."
    fi
}

# Function to copy files or directories safely
copy_files() {
    local source="$1"
    local destination="$2"
    local dest_path="$destination/$(basename "$source")"

    if [[ -d "$source" ]]; then
        echo "Copying directory $source to $destination using 'cp -r'..."
        "$SUDO" cp -r "$source" "$dest_path" && echo "$source has been copied."
    else
        echo "Copying file $source to $destination using 'cp'..."
        "$SUDO" cp "$source" "$dest_path" && echo "$source has been copied."
    fi
    
    sync
    echo "Syncing file system..."
    "$SUDO" mount -o remount,sync "$MOUNT_POINT"

    # Verify copy integrity
    if "$SUDO" du -b "$source" && "$SUDO" du -b "$dest_path" && "$SUDO" diff -qr "$source" "$dest_path"; then
        echo "Verification successful: No differences found."
    else
        echo "Verification failed: Differences found!"
        return 1
    fi
}

# Function to copy files or directories using rsync
rsync_files() {
    local source="$1"
    local destination="$2"
    echo "Copying $source to $destination using rsync..."
    "$SUDO" rsync -avh --progress "$source" "$destination" && echo "Files copied successfully using rsync."
}


# Function to check filesystem existence
check_filesystem() {
    local device="$1"
    local blkid_output
    blkid_output=$("$SUDO" blkid -o export "$device")
    if [[ -n "$blkid_output" ]]; then
        echo -e "Warning: $device has existing data:"
        echo "$blkid_output" | grep -E '^(TYPE|PTTYPE)='
        echo -e "Please confirm to proceed with formatting:"
        return 0
    else
        return 1
    fi
}

# Function to format the drive
format_drive() {
    local device="$1"
    echo "Checking if device $device is mounted..."
    safe_unmount "$device" || return 1

    # Check existing filesystems or partition tables
    if check_filesystem "$device"; then
        read -p "Are you sure you want to format $device? [y/N]: " confirm
        if [[ $confirm != [yY] ]]; then
            echo "Formatting aborted."
            return 1
        fi
    fi
    
    echo "Formatting $device..."
    "$SUDO" mkfs.exfat "$device" && echo "Drive formatted successfully." || echo "Formatting failed."
}

# Function to display usage information
help() {
    echo "Usage: $0 OPTION [ARGUMENTS]"
    echo
    echo "Options:"
    echo "  -c, -C DEVICE SOURCE_PATH    Mount DEVICE and copy SOURCE_PATH to it using 'cp'."
    echo "  -r, -R DEVICE SOURCE_PATH    Mount DEVICE and copy SOURCE_PATH to it using 'rsync'."
    echo "  -l, -L                       List information about block devices."
    echo "  -f, -F DEVICE                Format DEVICE."
    echo
    echo "Examples:"
    echo "  $0 -C /path/to/data /dev/sdx # Copy /path/to/data to /dev/sdx after mounting it using 'cp'."
    echo "  $0 -R /path/to/data /dev/sdx # Copy /path/to/data to /dev/sdx after mounting it using 'rsync'."
    echo "  $0 -L                        # List all block devices."
    echo "  $0 -F /dev/sdx               # Format /dev/sdx."
}

# Process command-line arguments
case "$1" in
    -C | -c)
        check_dependencies
        ensure_mounted "$3"
        copy_files "$2" "$MOUNT_POINT"
        safe_unmount "$MOUNT_POINT"
        ;;
    -R | -r)
        check_dependencies
        ensure_mounted "$3"
        rsync_files "$2" "$MOUNT_POINT"
        safe_unmount "$MOUNT_POINT"
        ;;
    -L | -l)
        lsblk -o NAME,MODEL,SERIAL,VENDOR,TRAN
        ;;
    -F | -f)
        check_dependencies
        format_drive "$2"
        ;;  
    *)
        help
        ;;
esac

segunda-feira, 29 de abril de 2024

terminal transparente no i3wm com picom

1 - instale o picom

$ sudo apt-get install picom

2 - crie o diretorio e arquivo de configuração do picom.conf

$ mkdir .config/picom
$ touch .config/picom/picom.conf

no arquivo de configuração do picom adicione as seguintes linhas 

backend = "xrender";

opacity-rule = [ "85:class_g = 'kitty'" ]

OBS: kitty é o nome do terminal troque-o pelo terminal ao qual usa 85 é o grau de transparencia

adicione no arquivo config do i3wm

exec --no-startup-id picom --config /home/usuario/.config/picom/picom.conf 

salve

após isso reinicie

$ shutdown -r now

sábado, 27 de abril de 2024

formatar corretamente pendrive para aceitar arquivos grandes

 tive um pequeno problema em enviar arquivos maiores que 4gb para o pendrive sandisk a solução foi formata-lo  em exfat

$ lsblk

$ sudo mkfs.exfat -n VolumeLabel /dev/sdX1

após isso usei o comando cp para enviar para o pendrive

dar permissão ao brightness / brilho do monitor

Can't modify brightness: Permission denied

You should run this program with root privileges.
Alternatively, get write permissions for device files.

 $ sudo chmod +s $(which brightnessctl)

quarta-feira, 24 de abril de 2024

monitor preto e branco/ monitor grayscale i3wm / remove saturation /

xrandr --output eDP-1 --set CTM '1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0,1431655765,0'

voltar ao normal

xrandr --output eDP-1 --set CTM '0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1'

segunda-feira, 22 de abril de 2024

Melhores servidores IRC 2024

 1. DALnet

    Webchat: Use the webchat available at DALnet Webchat.
    IRC Client: Connect using an IRC client to servers like irc.dal.net.
    More Information: Visit DALnet Servers for a full list of server addresses.

2. EFNet

    Webchat: Connect via the webchat at EFNet Webchat.
    IRC Client: Use addresses like irc.choopa.net or efnet.deic.eu.
    More Information: Find more servers and information at EFNet Servers.

3. GeekShed

    Webchat: Access the network through GeekShed Webchat.
    IRC Client: Use irc.geekshed.net to connect.
    More Information: A list of servers is available on GeekShed Servers.

4. IRCnet

    Webchat: Use IRCnet Webchat.
    IRC Client: Connect using server addresses like open.ircnet.net or ssl.ircnet.ovh.
    More Information: Detailed server information is available at IRCnet Servers.

5. Libera.Chat

    Webchat: Connect via Libera.Chat Webchat.
    IRC Client: Servers include irc.libera.chat (port 6697 for SSL).
    More Information: Check out Libera.Chat for more details on connections.

6. OFTC

    Webchat: Engage through OFTC Webchat.
    IRC Client: Connect to irc.oftc.net.
    More Information: Additional server details at OFTC.

7. QuakeNet

    Webchat: Access the network via QuakeNet Webchat.
    IRC Client: Use servers such as irc.quakenet.org.
    More Information: More servers can be found at QuakeNet Servers.

8. Rizon

    Webchat: Join through Rizon Webchat.
    IRC Client: Server addresses include irc.rizon.net.
    More Information: See Rizon Servers for a full list.

9. Undernet

    Webchat: Connect using Undernet Webchat.
    IRC Client: Use irc.undernet.org for connections.
    More Information: Explore further at Undernet.

Instalação do i3wm no Linux Mint - i3 4.23 / Install i3wm Linux Mint - i3 4.23

 1 - Baixe o i3wm i3-4.23.tar.xz
link: https://i3wm.org/downloads/

2 - descompacte o arquivo tar.xz
$ tar -xvf i3-4.23.tar.xz

3 - entre no diretorio descompactado
$ cd i3-4.23

4 - crie um diretorio build
$ mkdir build

5 - entre no diretorio build
$ cd build

6 - instale o meson
$ sudo apt-get install meson

7 - instale o build-essential
$ sudo apt-get install build-essential

8 - instale as dependencias
$ sudo apt install libstartup-notification0-dev libxcb-xkb-dev libxcb-xinerama0-dev \
libxcb-randr0-dev libxcb-shape0-dev libxcb-util-dev libxcb-cursor-dev libxcb-keysyms1-dev \
libxcb-icccm4-dev libxcb-xrm-dev libxkbcommon-dev libxkbcommon-x11-dev libyajl-dev \
libpcre2-dev libcairo2-dev libpango1.0-dev libev-dev libc6-dev

9 - rode o comando meson
$ meson ..

10 - execute o comando ninja
$ ninja
$ sudo ninja install

11 - sudo vim /usr/share/xsessions/i3.desktop

12 - adicione no arquivo
[Desktop Entry]
Name=i3
Comment=Improved dynamic tiling window manager
Exec=i3
TryExec=i3
Type=Application
X-LightDM-DesktopName=i3
DesktopNames=i3
Keywords=tiling;wm;windowmanager;window;manager;

12 - restart lightdm
sudo systemctl restart lightdm

 

OBS: o i3lock e i3blocks podem ser instalados facilmente com o comando
$ sudo apt-get install i3lock i3blocks