_common.sh 957 Bytes
Newer Older
Ilja's avatar
Ilja committed
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/bash

# ============= FUTURE YUNOHOST HELPER =============
# Delete a file checksum from the app settings
#
# $app should be defined when calling this helper
#
# usage: ynh_remove_file_checksum file
# | arg: file - The file for which the checksum will be deleted
ynh_delete_file_checksum () {
	local checksum_setting_name=checksum_${1//[\/ ]/_}	# Replace all '/' and ' ' by '_'
	ynh_app_setting_delete $app $checksum_setting_name
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
}

# ============= CUSTOM HELPERS =============
# Improvement on default helper who in some cases returned empty string
# 
# Generate a random string
#
# example: pwd=$(ynh_string_random 8)
#
# usage: ynh_string_random [length]
# | arg: length - the string length to generate (default: 24)
ynh_string_random() {
    str=''
    while [ ${#str} -lt ${1:-24} ]; do
        str=$str$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9');
    done
    echo $str | sed -n 's/\(.\{'"${1:-24}"'\}\).*/\1/p'
}