From 534379a3239598fe926c729b50ee8c461472b891 Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Thu, 3 Oct 2019 22:56:50 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9p=C3=B4t=20initial?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/backlight_off | 1 + bin/backlight_on | 1 + bin/battery | 129 +++++++++++++++++++++++++++++++++++++++++++ bin/current_date | 3 + bin/ostatus | 34 ++++++++++++ bin/proxy_chromium | 3 + bin/random_wallpaper | 49 ++++++++++++++++ bin/stardew_valley | 8 +++ 8 files changed, 228 insertions(+) create mode 100755 bin/backlight_off create mode 100755 bin/backlight_on create mode 100755 bin/battery create mode 100755 bin/current_date create mode 100755 bin/ostatus create mode 100755 bin/proxy_chromium create mode 100755 bin/random_wallpaper create mode 100755 bin/stardew_valley diff --git a/bin/backlight_off b/bin/backlight_off new file mode 100755 index 0000000..9840a53 --- /dev/null +++ b/bin/backlight_off @@ -0,0 +1 @@ +sudo tee /sys/class/leds/asus::kbd_backlight/brightness <<< 0 diff --git a/bin/backlight_on b/bin/backlight_on new file mode 100755 index 0000000..10f3e7a --- /dev/null +++ b/bin/backlight_on @@ -0,0 +1 @@ +sudo tee /sys/class/leds/asus::kbd_backlight/brightness <<< 1 diff --git a/bin/battery b/bin/battery new file mode 100755 index 0000000..4174531 --- /dev/null +++ b/bin/battery @@ -0,0 +1,129 @@ +#!/bin/sh + +HEART_FULL=♥ +HEART_EMPTY=♡ +[ -z "$NUM_HEARTS" ] && + NUM_HEARTS=5 + +cutinate() +{ + perc=$1 + inc=$(( 100 / $NUM_HEARTS)) + + + for i in `seq $NUM_HEARTS`; do + if [ $perc -lt 100 ]; then + echo $HEART_EMPTY + else + echo $HEART_FULL + fi + perc=$(( $perc + $inc )) + done +} + +linux_get_bat () +{ + bf=$(cat $BAT_FULL) + bn=$(cat $BAT_NOW) + echo $(( 100 * $bn / $bf )) +} + + +openbsd_get_bat () +{ + bf=$(sysctl -n hw.sensors.acpibat0.amphour0 | cut -d ' ' -f 1) + bn=$(sysctl -n hw.sensors.acpibat0.amphour3 | cut -d ' ' -f 1) + echo "(($bn * 100) / $bf)" | bc -l | awk -F '.' '{ print $1 }'; +} + +freebsd_get_bat () +{ + sysctl -n hw.acpi.battery.life +} + +battery_status() +{ +case $(uname -s) in + "Linux") + BATPATH=${BATPATH:-/sys/class/power_supply/BAT1} + STATUS=$BATPATH/status + [ "$1" = `cat $STATUS` ] || [ "$1" = "" ] || return 0 + if [ -f "$BATPATH/energy_full" ]; then + naming="energy" + elif [ -f "$BATPATH/charge_full" ]; then + naming="charge" + elif [ -f "$BATPATH/capacity" ]; then + cat "$BATPATH/capacity" + return 0 + fi + BAT_FULL=$BATPATH/${naming}_full + BAT_NOW=$BATPATH/${naming}_now + linux_get_bat + ;; + "FreeBSD") + STATUS=`sysctl -n hw.acpi.battery.state` + case $1 in + "Discharging") + if [ $STATUS -eq 1 ]; then + freebsd_get_bat + fi + ;; + "Charging") + if [ $STATUS -eq 2 ]; then + freebsd_get_bat + fi + ;; + "") + freebsd_get_bat + ;; + esac + ;; + "OpenBSD") + openbsd_get_bat + ;; + "Darwin") + case $1 in + "Discharging") + ext="No";; + "Charging") + ext="Yes";; + esac + + ioreg -c AppleSmartBattery -w0 | \ + grep -o '"[^"]*" = [^ ]*' | \ + sed -e 's/= //g' -e 's/"//g' | \ + sort | \ + while read key value; do + case $key in + "MaxCapacity") + export maxcap=$value;; + "CurrentCapacity") + export curcap=$value;; + "ExternalConnected") + if [ -n "$ext" ] && [ "$ext" != "$value" ]; then + exit + fi + ;; + "FullyCharged") + if [ "$value" = "Yes" ]; then + exit + fi + ;; + esac + if [[ -n "$maxcap" && -n $curcap ]]; then + echo $(( 100 * $curcap / $maxcap )) + break + fi + done +esac +} + +BATTERY_STATUS=`battery_status $1` +[ -z "$BATTERY_STATUS" ] && exit + +if [ -n "$CUTE_BATTERY_INDICATOR" ]; then + cutinate $BATTERY_STATUS +else + echo ${BATTERY_STATUS}% +fi + diff --git a/bin/current_date b/bin/current_date new file mode 100755 index 0000000..bdf45f4 --- /dev/null +++ b/bin/current_date @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +LANG=fr_FR.UTF-8 date +'%R %a, le %d/%m/%Y' diff --git a/bin/ostatus b/bin/ostatus new file mode 100755 index 0000000..6a761eb --- /dev/null +++ b/bin/ostatus @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# Script to send a status on GNUSocial instance using HTTPie +# +# Requirements: httpie package + +SERVER='https://herds.eu' +API="${SERVER}/api" +URL="${API}/statuses/update.xml" +GS_USER='bl4n' + +command -v http >/dev/null 2>&1 || { echo >&2 "httpie is missing!"; exit 1;} + +message="$*" + +if http --check-status --timeout=5 -a $GS_USER -f POST $URL source='HTTPie' status="$message" &> /dev/null; then + echo 'OK!' +else + case $? in + 2) echo 'Request timed out!' && exit 1;; + 3) echo 'Unexpected HTTP 3xx Redirection!' && exit 1 ;; + 4) echo 'HTTP 4xx Client Error!' && exit 1;; + 5) echo 'HTTP 5xx Server Error!' && exit 1;; + 6) echo 'Exceeded --max-redirects= redirects!' && exit 1 ;; + *) echo 'Other Error!' && exit 1;; + esac +fi + +exit 0 +# Some information about method +# EITHER HTTPIE +#http -f POST $URL -a $GS_USER source='HTTPie' status="$message" +# OR CURL +#curl -u $GS_USER $URL -d status='curlTest' diff --git a/bin/proxy_chromium b/bin/proxy_chromium new file mode 100755 index 0000000..66487a4 --- /dev/null +++ b/bin/proxy_chromium @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +chromium --proxy-server="socks4://localhost:9005" diff --git a/bin/random_wallpaper b/bin/random_wallpaper new file mode 100755 index 0000000..8772d5b --- /dev/null +++ b/bin/random_wallpaper @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# random_wallpaper +# +# Requirement: feh (apt install feh) + +directory="$HOME/wallpapers" +minutes=15 + +# Some tests +if [ -z "`which feh`" ]; then + echo "This script needs the feh program. Install it." +i exit 1 +fi + +if [ -d '$directory' ]; then + echo "No $directory found." + exit 1 +fi + +IFS=" +" + +array_files=($(ls -1 $directory)) + +nb_files=`ls $directory|wc -l` + +if [ $nb_files == 0 ]; then + echo "$nb_files files in $directory" + exit 1 +fi + +# initialisation +seconds=$[ $minutes * 60 ] + +while true; do + + # Random number generator (not more than files number) + NUMBER=$[ ( $RANDOM % $nb_files ) ] + + # Change background + file="${array_files["$NUMBER"]}" + feh --bg-fill "$directory/$file" + + # Wait some times + sleep $seconds +done + +exit 0 diff --git a/bin/stardew_valley b/bin/stardew_valley new file mode 100755 index 0000000..55e7610 --- /dev/null +++ b/bin/stardew_valley @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +IFS=" +" + +dir="/home/od/GOG Games/Stardew Valley/" + +cd $dir && TERM=xterm ./start.sh