This repository has been archived by the owner on Mar 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathssk_mkswap.sh
84 lines (50 loc) · 1.6 KB
/
ssk_mkswap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
clear
type "got_ssk" &> /dev/null
if [ $? -ne 0 ]; then
wget -O- -q https://raw.githubusercontent.com/phoenixweiss/sskit/master/ssk_init.sh >> ~/.profile
. ~/.profile
export -f got_ssk # Export function for check SSKit availibility
fi
rootonly
# Get swap details
SWAPUSED=`free -m | grep 'Swap:' | awk '{ print $3 }'`
SWAPTOTAL=`free -m | grep 'Swap:' | awk '{ print $2 }'`
say "You system partitions are:"
blkid
hr
say "Info about current swap(if any):"
cat /proc/swaps
hr
say "Info about free memory(with swap):"
free
hr
vmstat
hr
say "Currently, you have $(ramsizemb) Mb of real RAM, $SWAPTOTAL Mb of swap ($SWAPUSED Mb used right now)"
say "Do you want to make a proper swapfile based on your RAM size?"
read -r -p "Continue (y/N)? " choice
case $choice in
[yY][eE][sS] | [yY] )
dd if=/dev/zero of=/swapfile bs=1M count=$(ramsizemb)
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap defaults 0 0" >> /etc/fstab # TODO check if the line presents!
# cat /etc/sysctl.conf | grep vm
echo "vm.swappiness=15" >> /etc/sysctl.conf # TODO check if the line presents!
say "$(ramsizemb) Mb swap file ready and mounted in /swapfile"
say "To check all info about using memory try $(important 'cat /proc/meminfo')"
say "Please, do not forget to $(important 'reboot') server! Please do it manually!"
printf "\n"
;;
* )
say "$(currtime)"
exit 0 # Exit without further setup
;;
esac
hr
say "Bye, $USER!"
say "$(currtime)"
# TODO reboot if not interactive!
exit 0 # Success exit