-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·88 lines (74 loc) · 3.39 KB
/
install.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
85
86
87
88
#/bin/bash
# TODO: parameterise the RAMDisk folder name via template systemd service @
# TODO: use reverse dns naming com.github.petrstepanov.tiny-ramdisk to avoid name clashes
BIN_FOLDER=$HOME/.local/bin
SYSTEMD_FOLDER=$HOME/.local/share/systemd/user
ICON_FOLDER=$HOME/.local/share/icons/hicolor/scalable/apps
SYMBOLIC_ICON_FOLDER=$HOME/.local/share/icons/hicolor/symbolic/apps
RAMDISK_FOLDER=$HOME/RAMDisk
RAMDISK_PERSISTENT_FOLDER=$HOME/.RAMDisk
# Create entry in /etc/fstab
echo "INFO: Creating ramfs entry in /etc/fstab."
sudo sed -i "/#ramdisk-$USER/d" /etc/fstab
echo "none $RAMDISK_FOLDER ramfs rw,exec,noauto,user,mode=1777 0 0 #ramdisk-$USER" | sudo tee -a /etc/fstab
# Make `mount` recognize changes in `fstab`: https://unix.stackexchange.com/q/477794/340672
sudo systemctl daemon-reload
# Copy startup and shutdown scripts
# Tip: copying, not moving because copying inherits file properties, of its parent directory (ownership, etc).
# https://osric.com/chris/accidental-developer/2019/01/cp-mv-ownership-attributes/
mkdir -p $BIN_FOLDER
# Check which RAMDisk scripts to install - with or without executable permissions on the drive?
while true; do
read -p "QUESTION: Do you need executable permissions on the RAMDisk? (yes/no) " YN
case $YN in
yes )
echo -e "INFO: Ok. Copying startup and shutdown scripts."
cp ./src/tiny-ramdisk-startup-exec.sh $BIN_FOLDER/tiny-ramdisk-startup.sh
cp ./src/tiny-ramdisk-shutdown-exec.sh $BIN_FOLDER/tiny-ramdisk-shutdown.sh
echo -e "INFO: Installing the policy file."
sudo cp ./src/tiny-ramdisk.policy /usr/share/polkit-1/actions
sudo mv /usr/share/polkit-1/actions/tiny-ramdisk.policy /usr/share/polkit-1/actions/tiny-ramdisk.$USER.policy
sudo sed -i "s;%USER%;$USER;g" /usr/share/polkit-1/actions/tiny-ramdisk.$USER.policy
break;;
no )
echo -e "INFO: Ok. Copying startup and shutdown scripts."
cp ./src/tiny-ramdisk-startup-noexec.sh $BIN_FOLDER/tiny-ramdisk-startup.sh
cp ./src/tiny-ramdisk-shutdown-noexec.sh $BIN_FOLDER/tiny-ramdisk-shutdown.sh
break;;
* )
echo invalid response
exit 1
break;;
esac
done
# Add executable permissions to RAMDisk scripts
chmod +x $BIN_FOLDER/tiny-ramdisk-*
# Install application icon for pkexec dialog (may be needed)
# All icons are installed to "hicolor" fallback icon theme folder: https://askubuntu.com/a/300155/925071
echo "INFO: Installing application icons."
mkdir -p $ICON_FOLDER
cp ./resources/tiny-ramdisk.svg $ICON_FOLDER
xdg-desktop-menu forceupdate
# Install symbolic icons for notifications
mkdir -p $SYMBOLIC_ICON_FOLDER
cp ./resources/tiny-ramdisk*symbolic.svg $SYMBOLIC_ICON_FOLDER
gtk-update-icon-cache --ignore-theme-index $HOME/.local/share/icons/hicolor/
# Create folder for user systemd scripts
echo "INFO: Installing systemd service."
mkdir -p $SYSTEMD_FOLDER
# Copy systemd services
# https://wiki.archlinux.org/title/systemd/User#Writing_user_units
cp ./src/tiny-ramdisk.service $SYSTEMD_FOLDER
# Stop the service (if running)
systemctl --user stop tiny-ramdisk
systemctl --user disable tiny-ramdisk
systemctl --user daemon-reload
# Start the service
echo "INFO: Starting the RAMDisk service..."
systemctl --user enable tiny-ramdisk
systemctl --user start tiny-ramdisk
# Show RAMDisk folder in Files application
echo "INFO: Done! Path to your RAMDisk is ${RAMDISK_FOLDER}"
xdg-open $RAMDISK_FOLDER
# Success exit
exit 0