@@ -45,7 +45,7 @@ dir_script="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
45
45
file_config=' /etc/ramroot.conf'
46
46
ram_machine=8000
47
47
ps_default=no
48
- ps_timeout=8
48
+ ps_timeout=5
49
49
ram_min=750
50
50
ram_pref=4000
51
51
zram_min=250
@@ -188,6 +188,7 @@ ramroot_config_gen() {
188
188
ps_input zram
189
189
# global file_config flag_yes opt_output ps_default ps_timeout \
190
190
# ram_machine ram_min ram_pref zram_max zram_min
191
+
191
192
# RETURN: trying to save to directory:
192
193
if [ -d " $opt_output " ]; then
193
194
msg_error " $opt_output is a directory"
@@ -200,32 +201,30 @@ ramroot_config_gen() {
200
201
# RETURN:
201
202
if [ " $ps_input " != ' y' ] && [ " $ps_input " != ' yes' ]; then
202
203
return 0
203
- fi
204
- fi
204
+ fi ; fi
205
205
206
+ # only possible to generate custom config if root is mounted:
206
207
if (mountpoint -q /); then
207
208
zram=$(( $(df - m / | \
208
209
awk 'FNR==2 {print int($3 )}')+ram_min+zram_min))
209
- # get /boot, /efi, /esp, /home from /etc/fstab:
210
+ # source /etc/fstab:
210
211
if [ -f /etc/fstab ]; then
211
212
mapfile -t mounts_fstab < <( sed -En \
212
213
' s@^\s*((UUID|PARTUUID)=[^\s]+)\s+(/[^ \s]+).*$@\3:\1@p;' \
213
214
/etc/fstab | sort)
214
215
for mount in ${mounts_fstab[@]} ; do
215
216
mount_id=" ${mount#*: } "
216
217
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
229
228
230
229
# build config:
231
230
config=$' #!usr/bin/ash\n\n # mounts loaded to zram:\n mounts_zram=\' '
@@ -252,7 +251,7 @@ ramroot_config_gen() {
252
251
config+=$' \n\n # maximum Mb free ram:\n zram_max='
253
252
config+=" $zram_max "
254
253
255
- # save config:
254
+ # write config:
256
255
printf ' %s\n' " $config " > " $opt_output "
257
256
}
258
257
@@ -317,10 +316,8 @@ if [ $EUID -ne 0 ]; then
317
316
cut -c9) " != ' w' ]; then
318
317
msg_error ' you must be root to perform this operation'
319
318
exit 1
320
- fi
321
- fi
322
- fi
323
- fi
319
+ fi ; fi ; fi ; fi
320
+
324
321
# FAIL: both disable and enable:
325
322
if [ " $flag_disable " = ' true' ] && [ " $flag_enable " = ' true' ]; then
326
323
msg_error ' cannot both disable and enable'
0 commit comments