As the title says. In particular, If the LC_ALL=C and the switch back to "" worked, there
would be no need the if...elif...else...fi section, right?
I'm asking because I'm confused. This script works without fuss in my DPupStretch-7
without the language query section. It worked fine in xenial32-706 too without it until
today.
Today I had to introduce the language query section to get it to work properly in the
xenialPup version.
.
Otherwise /mnt/ram1 is just a folder. rsync fills it up anyway but it's just a folder.
But
Code: Select all
cat /sys/block/zram0/stat
The LANG variable is fr_CA.UTF-8 in both. This is very mysterious.
Some comments in the script are in French, sorry. If a translation is needed, just ask.
Also, go easy on me, this is still a draft!
Thanks in advance for any insight.
BFN.
Code: Select all
#!/bin/bash
# /opt/local/bin/DV-zram.sh
# Créer un disque virtuel de type zram, par "Mute Ant".
# Source : https://forums.linuxmint.com/viewtopic.php?t=203420
# Relevé le 2017/10/24 à 04:30 par musher0
# (c) musher0 for original lines.
####
ChecK="`df | awk '$NF ~ /ram1/'`" # musher0, 17-10-14
if [ "$ChecK" = "" ];then # musher0, 17-10-14
MOUNTPOINT="/mnt/ram1"
LC_ALL=C # Marche pas ?
SIZE="`free -m | awk '/Mem/ {print $4/3*2}'`";LC_ALL=""
##############
# If the LC_ALL=C and the switch back worked, there would
# be no need the following if...elif...else...fi section, right?
# if [ "${LANG:10}" = "8" ];then # non significatif
if [ "${LANG:0:2}" = "fr" ];then # Laisser tomber les décimales possibles.
SIZE="${SIZE%,*}"
elif [ "${LANG:0:2}" = "en" ];then
SIZE="${SIZE%.*}"
# elif # autres langues # room for other languages
else
SIZE="${SIZE%.*}" # En-cas # Catch all ?
fi
##############
mkdir -p "$MOUNTPOINT" # s'assurer que le point de montage existe
sleep 0.1s
modprobe zram # Tell the kernel to create device zram0
sleep 0.1s
echo 1 > /sys/block/zram0/reset # Réinitialiser # Playing it safe.
sleep 0.1s
echo "${SIZE}"m > /sys/block/zram0/disksize # Set the size of zram0 ...
sleep 0.1s
mkfs.ext2 /dev/zram0 # Format the new device as ext2
# mkudffs --media-type=hd --blocksize=512 /dev/zram # non
sleep 0.1s
mount /dev/zram0 /mnt/ram1 # Ramdisk # Mount the new device on Ramdisk
sleep 0.1s
chmod 1777 /mnt/ram1 # Ramdisk # Change Ramdisk flags to be like a /tmp/ folder
sleep 0.1s
mkdir -p /mnt/ram1/Downloads # Make a Downloads folder in Ramdisk
sleep 0.1s
cd /mnt/home/ramdisk
rsync -qavz . "/mnt/ram1" # --delete # optionnel
# Source : https://unix.stackexchange.com/questions/203846/how-to-sync-two-folders-with-command-line-tools
#
# Meilleur que :
# exec /opt/local/bin/ramdisk_cp.sh & # Copier le contenu de /mnt/home/ramdisk.
#
# Inversement :
# cd /mnt/ram1
# rsync -avz . "/mnt/home/ramdisk"
#
######################
# Suite de l'explication de "Mute Ant" :
#
# The amount of memory used will fluctuate according to
# what you store in the Ramdisk folder. The disk will persist
# if you log out, but not if you reboot. 1G, 2G, 500M,
# whatever you can afford, sets the maximum data size,
# RAM use will often be less; if the data can be compressed,
# it will be.
#
# Should you ever need to switch it off without rebooting...
# sudo su -c "
# umount /dev/zram0 # &&
# echo 1 > /sys/block/zram0/reset
#
# ...will do that.
######################
sleep 0.5s
MsG="Un disque virtuel de $SIZE Mb a été créé."
Xdialog --title "Créé" --ok-label "OK" --timeout 5 --msgbox "$MsG" 0 0
rox /mnt/ram1 &
else # Cette section par musher0, 17-10-14
Xdialog --title "Existe" --ok-label "OK" --timeout 5 --msgbox "Un DV existe déja." 0 0
fi # Fin de la section par musher0, 17-10-14
########## Référence ####
# Ajouts par musher0
#
# Divers scripts d'une ligne pour faire des vérifications sur ce DV.
#
# 1) # echo -e "Location\tUsed\tAvail.\t%\tName";df -h | awk '$NF ~ /ramdisk/ { print $1"\t\t"$3"\t"$4"\t"$5"\t"$6}'
# OU
# 2a) df | head -1;df | grep ram;echo
# 2b) df -h | head -1;df -h | grep ram;echo
#
###
# 3) df | awk '$2=="1024000" && $NF ~ /ramdisk/'
# Celle-ci vous dit seulement s'il existe un DV.
####