@@ -45,7 +45,7 @@ dir_script="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4545file_config=' /etc/ramroot.conf'
4646ram_machine=8000
4747ps_default=no
48- ps_timeout=8
48+ ps_timeout=5
4949ram_min=750
5050ram_pref=4000
5151zram_min=250
@@ -188,6 +188,7 @@ ramroot_config_gen() {
188188 ps_input zram
189189 # global file_config flag_yes opt_output ps_default ps_timeout \
190190 # ram_machine ram_min ram_pref zram_max zram_min
191+
191192 # RETURN: trying to save to directory:
192193 if [ -d " $opt_output " ]; then
193194 msg_error " $opt_output is a directory"
@@ -200,32 +201,30 @@ ramroot_config_gen() {
200201 # RETURN:
201202 if [ " $ps_input " != ' y' ] && [ " $ps_input " != ' yes' ]; then
202203 return 0
203- fi
204- fi
204+ fi ; fi
205205
206+ # only possible to generate custom config if root is mounted:
206207 if (mountpoint -q /); then
207208 zram=$(( $(df - m / | \
208209 awk 'FNR==2 {print int($3 )}')+ram_min+zram_min))
209- # get /boot, /efi, /esp, /home from /etc/fstab:
210+ # source /etc/fstab:
210211 if [ -f /etc/fstab ]; then
211212 mapfile -t mounts_fstab < <( sed -En \
212213 ' s@^\s*((UUID|PARTUUID)=[^\s]+)\s+(/[^ \s]+).*$@\3:\1@p;' \
213214 /etc/fstab | sort)
214215 for mount in ${mounts_fstab[@]} ; do
215216 mount_id=" ${mount#*: } "
216217 mount_path=" ${mount%:* } "
217- # attempt to check if mount is small enough:
218- if [[ " ${mount_path,,} " =~ /(boot| efi| esp| home)$ ]] || \
219- (mountpoint -q " $mount_path " ) && \
220- [ $(( ram_machine - zram - $(df - m "$mount_path " | \
221- awk 'FNR==2 {print int($3 )}')) ) -gt 0 ]; then
222- zram=$(( zram+ $(df - m "$mount_path " | \
223- awk 'FNR==2 {print int($3 )}')) )
224- mounts_zram+=(" $mount_id :$mount_path " )
225- fi
226- done
227- fi
228- fi
218+ # get /boot, /efi, /esp, /home from /etc/fstab:
219+ if [[ " ${mount_path,,} " =~ /(boot| efi| esp| home)$ ]] && \
220+ (mountpoint -q " $mount_path " ); then
221+ # attempt to determine if mount is small enough:
222+ part=$( df -m " $mount_path " | \
223+ awk ' FNR==2 {print int($3)}' )
224+ if [ $(( ram_machine- zram- part)) -gt 0 ]; then
225+ zram=$(( zram+ part))
226+ mounts_zram+=(" $mount_id :$mount_path " )
227+ fi ; fi ; done ; fi ; fi
229228
230229 # build config:
231230 config=$' #!usr/bin/ash\n\n # mounts loaded to zram:\n mounts_zram=\' '
@@ -252,7 +251,7 @@ ramroot_config_gen() {
252251 config+=$' \n\n # maximum Mb free ram:\n zram_max='
253252 config+=" $zram_max "
254253
255- # save config:
254+ # write config:
256255 printf ' %s\n' " $config " > " $opt_output "
257256}
258257
@@ -317,10 +316,8 @@ if [ $EUID -ne 0 ]; then
317316 cut -c9) " != ' w' ]; then
318317 msg_error ' you must be root to perform this operation'
319318 exit 1
320- fi
321- fi
322- fi
323- fi
319+ fi ; fi ; fi ; fi
320+
324321# FAIL: both disable and enable:
325322if [ " $flag_disable " = ' true' ] && [ " $flag_enable " = ' true' ]; then
326323 msg_error ' cannot both disable and enable'
0 commit comments