Compare commits
9 Commits
58cc76c317
...
60dfe19049
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60dfe19049 | ||
|
|
c32771a4ff | ||
|
|
080511d0bd | ||
|
|
d8bdfefdf1 | ||
|
|
5f5f9c0e71 | ||
|
|
30387a4f08 | ||
|
|
0c51363d86 | ||
|
|
043fbaef0b | ||
|
|
ed5587712e |
11
profile.conf
11
profile.conf
@@ -1,6 +1,6 @@
|
||||
[system]
|
||||
# System section is used to set Bash behavior and other system related variables,
|
||||
# such as the default pager, the terminal type, etc.
|
||||
# System section is used to set Bash behavior and other system related
|
||||
# variables, such as the default pager, the terminal type, etc.
|
||||
# Set bash history
|
||||
HISTSIZE=50000
|
||||
HISTIGNORE="&:[bf]g:exit"
|
||||
@@ -17,6 +17,10 @@ TERM=xterm-256color
|
||||
[debug]
|
||||
# Section used by debug.sh
|
||||
|
||||
[disp]
|
||||
# Section used by disp.sh
|
||||
# NO_COLOR=1 # Set to any value to disable colors in disp output
|
||||
|
||||
[filefct]
|
||||
# Section used by filefct.sh
|
||||
|
||||
@@ -25,8 +29,7 @@ TERM=xterm-256color
|
||||
|
||||
[info]
|
||||
# Section used by info.sh
|
||||
# Default city for weather forcast
|
||||
DEFAULT_CITY="Toulouse"
|
||||
DEFAULT_CITY="Toulouse" # Default city for weather forcast
|
||||
|
||||
[lang]
|
||||
# Section used by lang.sh
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
@@ -208,7 +208,22 @@ utaz()
|
||||
disp E "The --create-dir and --no-dir options are mutually exclusive."
|
||||
|
||||
for zitem in "${FILES[@]}"; do
|
||||
for f in "${zitem}"/*; do
|
||||
# Build list of input files to process, with whitespace-safe handling.
|
||||
local targets=()
|
||||
if [[ -f "$zitem" ]]; then
|
||||
targets=("$zitem")
|
||||
elif [[ -d "$zitem" ]]; then
|
||||
mapfile -d '' -t targets < <(find "$zitem" -mindepth 1 -maxdepth 1 -print0 2>/dev/null)
|
||||
if [[ ${#targets[@]} -eq 0 ]]; then
|
||||
disp I "Directory ${zitem} is empty, skipping."
|
||||
continue
|
||||
fi
|
||||
else
|
||||
disp W "Path ${zitem} is not a file or directory, skipping."
|
||||
continue
|
||||
fi
|
||||
|
||||
for f in "${targets[@]}"; do
|
||||
local dir="${f%.*}"
|
||||
local extractor=""
|
||||
case "$f" in
|
||||
@@ -269,21 +284,21 @@ utaz()
|
||||
# Verify binary existence
|
||||
local cmd=${extractor//_un/}
|
||||
if [[ $cmd == "deb" ]]; then
|
||||
command -v dpkg-deb >/dev/null 2>&1 || {
|
||||
command -v -- dpkg-deb >/dev/null 2>&1 || {
|
||||
disp E "The program 'dpkg-deb' is not installed, aborting."
|
||||
continue
|
||||
}
|
||||
elif [[ $cmd == "rpm" ]]; then
|
||||
command -v rpm2cpio >/dev/null 2>&1 || {
|
||||
command -v -- rpm2cpio >/dev/null 2>&1 || {
|
||||
disp E "The program 'rpm2cpio' is not installed, aborting."
|
||||
continue
|
||||
}
|
||||
command -v cpio >/dev/null 2>&1 || {
|
||||
command -v -- cpio >/dev/null 2>&1 || {
|
||||
disp E "The program 'cpio' is not installed, aborting."
|
||||
continue
|
||||
}
|
||||
else
|
||||
command -v ${cmd} >/dev/null 2>&1 || {
|
||||
command -v -- "${cmd}" >/dev/null 2>&1 || {
|
||||
disp E "Binary ${cmd} necessary to extract ${f} is missing."
|
||||
continue
|
||||
}
|
||||
@@ -318,7 +333,12 @@ utaz()
|
||||
if [[ -n ${createdir} ]]; then
|
||||
disp I "Archive extracted successfully in subdirectory."
|
||||
elif [[ -n ${nodir} ]]; then
|
||||
mv "./${dir}/"* ./ && rmdir "${dir}"
|
||||
shopt -s nullglob
|
||||
for child in "${dir}"/*; do
|
||||
mv -- "$child" .
|
||||
done
|
||||
shopt -u nullglob
|
||||
rmdir -- "${dir}"
|
||||
disp I "Archive extracted successfully, no subdirectory needed."
|
||||
else
|
||||
# Set nullglob to ensure the array is empty if no files match
|
||||
@@ -328,7 +348,12 @@ utaz()
|
||||
# Check if exactly one item exists and if that item is a directory
|
||||
if [[ ${#contents[@]} -eq 1 ]] && [[ -d "${contents[0]}" ]]; then
|
||||
# Single directory detected
|
||||
mv "${contents[0]}"/* ./ && rmdir "${dir}"
|
||||
shopt -s nullglob
|
||||
for child in "${contents[0]}"/*; do
|
||||
mv -- "$child" .
|
||||
done
|
||||
shopt -u nullglob
|
||||
rmdir -- "${dir}"
|
||||
disp I "Archive extracted successfully, no subdirectory needed."
|
||||
else
|
||||
disp I "Archive extracted successfully in subdirectory."
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
@@ -46,7 +46,7 @@ function backtrace()
|
||||
"${FUNCNAME[$i]}" "${BASH_SOURCE[$i]}" "${BASH_LINENO[$(( i-1 ))]}"
|
||||
((i++))
|
||||
done
|
||||
unset func i
|
||||
unset i
|
||||
printf "==============================\n"
|
||||
}
|
||||
|
||||
@@ -69,30 +69,37 @@ settrace()
|
||||
#trap -p ERR
|
||||
|
||||
local PARSED
|
||||
PARSED=$(getopt -oh --long help,on,off,status -- "$@")
|
||||
PARSED=$(getopt -oh --long help,on,off,status,force -- "$@")
|
||||
if [[ $? -ne 0 ]]; then
|
||||
disp E "Invalid options, use \"settrace --help\" to display usage."
|
||||
return 1
|
||||
fi
|
||||
eval set -- "$PARSED"
|
||||
local force=0
|
||||
while true; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
printf "Try to activate backtrace display for script debugging.\n\n"
|
||||
printf "Options:\n"
|
||||
printf "\t--on\t\tActivate backtrace generation\n"
|
||||
printf "\t--force\t\tForce replacement of existing trap (use with --on)\n"
|
||||
printf "\t--off\t\tDeactivate backtrace generation\n\n"
|
||||
printf "That function active a trap event on error. If the script you want to\n"
|
||||
printf "debug overload the ERR bash trap, it will not work.\n"
|
||||
return 0
|
||||
;;
|
||||
--on)
|
||||
if [[ ${status} == "on" ]]; then
|
||||
disp W "ERR signal trap is already set, replacing previous trap!"
|
||||
if [[ ${status} == "on" ]] && [[ $force -eq 0 ]]; then
|
||||
disp E "ERR signal trap is already set. Use --force to replace it."
|
||||
return 1
|
||||
fi
|
||||
trap "error" ERR
|
||||
shift
|
||||
;;
|
||||
--force)
|
||||
force=1
|
||||
shift
|
||||
;;
|
||||
--off)
|
||||
if [[ ${status} != "on" ]]; then
|
||||
disp W "ERR signal trap is already unset!"
|
||||
@@ -101,7 +108,7 @@ settrace()
|
||||
shift
|
||||
;;
|
||||
--status)
|
||||
disp "ERR trap signal is ${status}."
|
||||
disp I "Trap signal is ${status}."
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
@@ -114,7 +121,7 @@ settrace()
|
||||
;;
|
||||
esac
|
||||
done
|
||||
unset status
|
||||
unset status force
|
||||
}
|
||||
export -f settrace
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
@@ -124,25 +124,45 @@ export On_IWhite='\e[0;107m'
|
||||
# D : debug (cyan)
|
||||
disp()
|
||||
{
|
||||
case $1 in
|
||||
# Handle NO_COLOR: disable colors if set
|
||||
local color_enabled=1
|
||||
[[ -n $NO_COLOR ]] && color_enabled=0
|
||||
|
||||
case ${1^^} in
|
||||
"I")
|
||||
local heads="[ ${IGreen}info${DEFAULTFG} ]"
|
||||
if [[ $color_enabled -eq 1 ]]; then
|
||||
local heads="[ ${IGreen}info${DEFAULTFG} ]"
|
||||
else
|
||||
local heads="[ info ]"
|
||||
fi
|
||||
shift
|
||||
[[ -z $QUIET || $QUIET -ne 1 ]] && \
|
||||
printf "%b\n" "${heads} $*${RESETCOL}"
|
||||
;;
|
||||
"W")
|
||||
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
|
||||
if [[ $color_enabled -eq 1 ]]; then
|
||||
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
|
||||
else
|
||||
local heads="[ Warning ]"
|
||||
fi
|
||||
shift
|
||||
printf "%b\n" "${heads} $*${RESETCOL}" >&2
|
||||
;;
|
||||
"E")
|
||||
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
|
||||
if [[ $color_enabled -eq 1 ]]; then
|
||||
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
|
||||
else
|
||||
local heads="[ ERROR ]"
|
||||
fi
|
||||
shift
|
||||
printf "%b\n" "${heads} $*${RESETCOL}" >&2
|
||||
;;
|
||||
"D")
|
||||
local heads="[ ${ICyan}debug${DEFAULTFG} ]"
|
||||
if [[ $color_enabled -eq 1 ]]; then
|
||||
local heads="[ ${ICyan}debug${DEFAULTFG} ]"
|
||||
else
|
||||
local heads="[ debug ]"
|
||||
fi
|
||||
shift
|
||||
[[ -n $DEBUG && $DEBUG -gt 1 ]] && \
|
||||
printf "%b\n" "${heads} $*${RESETCOL}"
|
||||
@@ -157,4 +177,7 @@ export -f disp
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Load disp section variables
|
||||
load_conf disp
|
||||
|
||||
# EOF
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
#
|
||||
# * Redistribution and use in source and binary forms,
|
||||
|
||||
12
profile.sh
12
profile.sh
@@ -113,6 +113,15 @@ parse_conf()
|
||||
value="${value#"${value%%[![:space:]]*}"}"
|
||||
value="${value%$'\r'}"
|
||||
|
||||
# Protect against command injection by disallowing certain characters in keys
|
||||
value="${value//\`/}"
|
||||
value="${value//\$\(/}"
|
||||
|
||||
# Correctly interpretet internal variables (e.g. $HOME)
|
||||
if [[ "$value" == *\$* ]]; then
|
||||
value=$(envsubst <<< "$value")
|
||||
fi
|
||||
|
||||
# Strip quotes (handling both " and ')
|
||||
value="${value%\"}"; value="${value#\"}"
|
||||
value="${value%\'}"; value="${value#\'}"
|
||||
@@ -122,7 +131,8 @@ parse_conf()
|
||||
current_array["$key"]="$value"
|
||||
fi
|
||||
done < "$config_file"
|
||||
}# ------------------------------------------------------------------------------
|
||||
}
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user