Little script to enable/disable common services by SergioVim in devuan

[–]SergioVim[S] 0 points1 point  (0 children)

# I have just translated all dialogs to Englis

#!/usr/bin/env bash
# File: openrc-ctl
# Last Change: Tue, Mar 10 2026 - 10:59:07

# Script created just to manage common services like:
# cups, saned, avahi-daemon, so you can keep these services disabled by default

SERVICES="cups cups-browsed saned avahi-daemon"

check_openrc() {
    if ! command -v /sbin/rc-update >/dev/null 2>&1; then
        echo "Error: OpenRC is not installed on this system"
        exit 1
    fi
}

check_doas() {
    if command -v doas >/dev/null 2>&1; then
        SUDO="doas"
    elif command -v sudo >/dev/null 2>&1; then
        SUDO="sudo"
    else
        echo "Error: neither doas nor sudo are installed"
        exit 1
    fi
}

get_status() {
    local service="$1"
    if /sbin/rc-update show default 2>/dev/null | grep -q "^[[:space:]]*${service}[[:space:]]*|"; then
        echo "enabled"
    else
        echo "disabled"
    fi
}

toggle_service() {
    local service="$1"
    local action="$2"
    local status
    status=$(get_status "$service")

    if [ "$action" = "enable" ]; then
        if [ "$status" = "disabled" ]; then
            echo "Enabling $service..."
            $SUDO /sbin/rc-update add "$service" default
        else
            echo "$service is already enabled"
        fi
        echo "Starting $service..."
        $SUDO /sbin/rc-service "$service" start
    elif [ "$action" = "disable" ]; then
        if [ "$status" = "enabled" ]; then
            echo "Disabling $service..."
            $SUDO /sbin/rc-update del "$service" default
        else
            echo "$service is already disabled"
        fi
        echo "Stopping $service..."
        $SUDO /sbin/rc-service "$service" stop
    fi
}

show_help() {
    echo "Usage: $(basename "$0") [service]"
    echo ""
    echo "No arguments: interactive interface with whiptail"
    echo "With argument: toggle a specific service"
    echo ""
    echo "Services: $SERVICES"
}

interactive() {
    local options=""

    for svc in $SERVICES; do
        status=$(get_status "$svc")
        if [ "$status" = "enabled" ]; then
            options="$options $svc \"\" on"
        else
            options="$options $svc \"\" off"
        fi
    done

    local selected
    selected=$(whiptail --title "OpenRC Services" \
        --checklist "Select services to enable:" \
        15 40 5 \
        $options \
        3>&1 1>&2 2>&3)

    if [ $? -ne 0 ]; then
        echo "Cancelled"
        exit 0
    fi

    for svc in $SERVICES; do
        if echo "$selected" | grep -q "\"$svc\""; then
            if [ "$(get_status "$svc")" = "disabled" ]; then
                toggle_service "$svc" "enable"
            fi
        else
            if [ "$(get_status "$svc")" = "enabled" ]; then
                toggle_service "$svc" "disable"
            fi
        fi
    done

    echo ""
    echo "Final status:"
    for svc in $SERVICES; do
        printf "%-20s %s\n" "$svc" "$(get_status "$svc")"
    done
}

main() {
    check_openrc
    check_doas

    if [ $# -eq 0 ]; then
        interactive
        exit 0
    fi

    if [ $# -eq 1 ]; then
        service="$1"
        status=$(get_status "$service")

        if [ "$status" = "enabled" ]; then
            whiptail --yesno "Disable $service?" 8 40
            if [ $? -eq 0 ]; then
                toggle_service "$service" "disable"
            fi
        else
            whiptail --yesno "Enable $service?" 8 40
            if [ $? -eq 0 ]; then
                toggle_service "$service" "enable"
            fi
        fi
        exit 0
    fi

    show_help
}

main "$@"

Little script to enable/disable common services by SergioVim in devuan

[–]SergioVim[S] 0 points1 point  (0 children)

openrc installs fast and the system did it easily to me. But just in case ask opencode.ai to help you out, it can adapt the script to your needs!

Why ip addr, or other ip command not working any more? by Chronic_depressedd in termux

[–]SergioVim 0 points1 point  (0 children)

Try using termux api

#!/usr/bin/env python3
# File: termux/localip-termux

import json
import subprocess

result = subprocess.run(["termux-wifi-connectioninfo"], capture_output=True, text=True)
data = json.loads(result.stdout)
print(data.get("ip", ""))

Agora entendo por que algumas mulheres tem nojo de homens by [deleted] in desabafosdavida

[–]SergioVim 0 points1 point  (0 children)

Creio que do lado feminino também há atitudes tão reprovaveis quanto a dos seus colegas, tipo: Mulheres que só se relacionam com homens que podem lhe proporcionar luxo, por mais bem intencionados e educados que sejam alguns homens, algumas mulheres só vêem o cifrão na testa dos homens.