···8899The file will be added to the home folder of your user on the server. If it is different from root, modify the path in the third line of the script `source /root/.shellfishrc` to the correct one `source /your_user/.shellfishrc`.
10101111+## Dependencies
1212+1313+Your server must have the following tools installed:
1414+1515+- `curl`: To send the information to the widget. [More info](https://curl.se/)
1616+- `jq`: To process the JSON response. [More info](https://stedolan.github.io/jq/)
1717+1118## Usage
12191320All the widgets that will be added to this repository will be used in the same way. If there is any difference, it will be indicated in its section.
142115221. Download the .sh file to your server, for example (you can change the path `/opt/shellfish_widgets` to any other:
1616- ```bash
2323+2424+ ```shell
1725 mkdir /opt/shellfish_widgets
1826 cd /opt/shellfish_widgets
1927 wget https://github.com/jmrplens/ShellFish-Widgets/raw/main/small_widget_A.sh
2028 ```
2929+21302. Enable its execution:
2222- ```
3131+3232+ ```shell
2333 chmod +x /opt/shellfish_widgets/small_widget_A.sh
2434 ```
3535+25363. Run it:
2626- ```
3737+3838+ ```shell
2739 /opt/shellfish_widgets/small_widget_A.sh --server_name Example
2840 ```
4141+2942 With this, you will have already sent the information to the widget you set on your iOS. If you want, you can configure some details:
3043 - **Server name**: This is the name that will appear on the widget, if it is not configured, the hostame of the server will be used `--server_name Example`.
3144 - **Disk**: If you want to send the used space of a disk other than the main one `--disk /volumeX`.
···3346 - **Target**: To send/create the information to a specific widget, indicate the widget's reference `--target Small_A`.
344735484. (Optional) Add it to the crontab (in this example, it runs every 10 minutes) to have updated information periodically:
3636- ```
4949+5050+ ```shell
3751 { crontab -l; echo "*/10 * * * * /opt/shellfish_widgets/small_widget_A.sh"; } | crontab -
3852 ```
5353+3954 or `crontab -e` and add a new line with `*/10 * * * * /opt/shellfish_widgets/small_widget_A.sh`
40554156### Small Widgets
+35-23
small_widget_A.sh
···11#!/bin/bash
2233# Load to make widget command available
44+# shellcheck source=/dev/null
45source /root/.shellfishrc
5667# Default values
···2728CPU_TEMP_SENSOR=${CPU_TEMP_SENSOR:-$DEFAULT_CPU_TEMP_SENSOR}
2829TARGET=${TARGET:-$DEFAULT_TARGET}
29303131+# Function to calculate the interpolated color between green (min) and red (max)
3232+calculate_color() {
3333+ local value=$1
3434+ local min_value=$2
3535+ local max_value=$3
3636+3737+ # If value is lee than min_value, clip it to min_value
3838+ if (( value < min_value )); then
3939+ value=$min_value
4040+ fi
4141+4242+ # Normalize value between 0 and 1
4343+ local range=$((max_value - min_value))
4444+ local normalized_value=$((100 * (value - min_value) / range))
4545+4646+ if (( normalized_value <= 33 )); then
4747+ # Interpolating between green (#00FF00) and yellow (#FFFF00)
4848+ local red=$((255 * normalized_value / 33))
4949+ printf "#%02XFF00\n" $red
5050+ elif (( normalized_value <= 66 )); then
5151+ # Interpolating between yellow (#FFFF00) and orange (#FFA500)
5252+ local green=$((255 - (90 * (normalized_value - 33) / 33)))
5353+ printf "#FFA5%02X\n" $green
5454+ else
5555+ # Interpolating between orange (#FFA500) and red (#FF0000)
5656+ local green=$((165 - (165 * (normalized_value - 66) / 34)))
5757+ printf "#FF%02X00\n" $green
5858+ fi
5959+}
6060+3061# Try to automatically detect the main disk if it's not defined
3162if [ -z "$DISK" ]; then
3263 # Attempt 1: lsblk
3364 DISK=$(lsblk -J -o NAME,MOUNTPOINT | jq -r '.blockdevices[] | select(.children != null) | .children[] | select(.mountpoint == "/") | .name')
3434-6565+3566 # Attempt 2: df (fallback method)
3667 if [ -z "$DISK" ]; then
3768 DISK=$(df / | grep -Eo '^/dev/[a-zA-Z0-9]+' | cut -d'/' -f3)
···4475 fi
4576fi
46774747-# Function to interpolate colors in hexadecimal (green to red)
4848-calculate_color() {
4949- local value=$1
5050- local min_value=$2
5151- local max_value=$3
5252-5353- if (( value <= min_value )); then
5454- echo "#00FF00" # Green
5555- elif (( value >= max_value )); then
5656- echo "#FF0000" # Red
5757- else
5858- if (( value < (max_value + min_value) / 2 )); then
5959- echo "#FFFF00" # Yellow
6060- else
6161- echo "#FFA500" # Orange
6262- fi
6363- fi
6464-}
65786679# 1. Memory usage as a percentage
6780if [[ -f /proc/meminfo ]]; then
···81948295# 2. Disk usage as a percentage
8396disk_info_percent=$(df /dev/"${DISK}" -h --output=pcent | tail -1 | tr -d ' %')
8484-disk_total_size=$(df /dev/"${DISK}" -h --output=size | tail -1)B
8597disk_used_size=$(df /dev/"${DISK}" -h --output=used | tail -1)B
86988799# String for disk usage as a percentage
···154166cpu_string="${cpu_usage}%"
155167156168# 5. Color calculations based on percentages
157157-cpu_color=$(calculate_color "$cpu_usage" 20 90)
158158-memory_color=$(calculate_color "$mem_percent" 20 90)
159159-disk_color=$(calculate_color "$disk_info_percent" 20 90)
169169+cpu_color=$(calculate_color "$cpu_usage" 10 95)
170170+memory_color=$(calculate_color "$mem_percent" 10 95)
171171+disk_color=$(calculate_color "$disk_info_percent" 20 95)
160172temp_color=$(calculate_color "$cpu_temp" 45 90)
161173162174# Widget command using SF Symbols and strings in the correct format with colors