Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions install_rtop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ if [ "$EUID" -ne 0 ]; then
exit 1
fi

# Check if libQt5Widgets.so.5 is installed
if ! ldconfig -p | grep -q libQt5Widgets.so.5; then
echo "libQt5Widgets.so.5 is not found on your system."
read -p "Do you want to install it now? (y/n): " choice
case "$choice" in
y|Y )
echo "Installing libqt5widgets5..."
apt-get update
apt-get install -y libqt5widgets5
;;
* )
echo "libQt5Widgets.so.5 is required"
echo "Please install it with $ sudo apt-get install libqt5widgets5"
;;
esac
else
echo "libQt5Widgets.so.5 is already installed."
fi

# Get the current non-root user
CURRENT_USER=$(logname)

Expand All @@ -23,8 +42,8 @@ fi

# Copy rtop to /usr/local/bin if not already there
if [ ! -f /usr/local/bin/rtop ]; then
sudo cp "$RTOP_PATH" /usr/local/bin/
sudo chmod +x /usr/local/bin/rtop
cp "$RTOP_PATH" /usr/local/bin/
chmod +x /usr/local/bin/rtop
echo "rtop has been copied to /usr/local/bin."
else
echo "rtop is already present in /usr/local/bin."
Expand All @@ -39,21 +58,21 @@ SUDOERS_FILE="/etc/sudoers.d/rtop_nopasswd"
# Check if the file already exists
if [ -f "$SUDOERS_FILE" ]; then
echo "The sudoers file for rtop already exists. Updating it..."
echo "$SUDOERS_ENTRY" | sudo tee "$SUDOERS_FILE" > /dev/null
echo "$SUDOERS_ENTRY" | tee "$SUDOERS_FILE" > /dev/null
else
echo "$SUDOERS_ENTRY" | sudo tee "$SUDOERS_FILE" > /dev/null
echo "$SUDOERS_ENTRY" | tee "$SUDOERS_FILE" > /dev/null
fi

# Set correct permissions for the file
sudo chmod 0440 "$SUDOERS_FILE"
chmod 0440 "$SUDOERS_FILE"

# Create the wrapper script
WRAPPER_SCRIPT="/usr/local/bin/rtop-wrapper"
echo "#!/bin/bash" | sudo tee "$WRAPPER_SCRIPT" > /dev/null
echo "sudo /usr/local/bin/rtop \"\$@\"" | sudo tee -a "$WRAPPER_SCRIPT" > /dev/null
echo "#!/bin/bash" | tee "$WRAPPER_SCRIPT" > /dev/null
echo "sudo /usr/local/bin/rtop \"\$@\"" | tee -a "$WRAPPER_SCRIPT" > /dev/null

# Make the wrapper script executable
sudo chmod +x "$WRAPPER_SCRIPT"
chmod +x "$WRAPPER_SCRIPT"

# Add the alias to the user's .bashrc
BASHRC_FILE="/home/$CURRENT_USER/.bashrc"
Expand All @@ -63,7 +82,7 @@ ALIAS_CMD="alias rtop='rtop-wrapper'"
if grep -Fxq "$ALIAS_CMD" "$BASHRC_FILE"; then
echo "The alias for rtop already exists in $BASHRC_FILE."
else
echo "$ALIAS_CMD" | sudo tee -a "$BASHRC_FILE" > /dev/null
echo "$ALIAS_CMD" | tee -a "$BASHRC_FILE" > /dev/null
echo "The alias for rtop has been added to $BASHRC_FILE."
fi

Expand All @@ -77,19 +96,19 @@ if [ -f "$ICON_SOURCE" ]; then
# Check if the destination directory exists
if [ ! -d "$ICON_DEST_DIR" ]; then
# Create the destination directory
sudo mkdir -p "$ICON_DEST_DIR"
mkdir -p "$ICON_DEST_DIR"
echo "Created directory $ICON_DEST_DIR."
fi
# Copy the icon to the destination directory
sudo cp "$ICON_SOURCE" "$ICON_DEST"
cp "$ICON_SOURCE" "$ICON_DEST"
echo "Icon has been copied to $ICON_DEST."
else
echo "Warning: Icon not found at $ICON_SOURCE. The .desktop file will be created without an icon."
fi

# Create .desktop file for rtop
DESKTOP_FILE="/usr/share/applications/rtop.desktop"
sudo tee "$DESKTOP_FILE" > /dev/null << EOF
tee "$DESKTOP_FILE" > /dev/null << EOF
[Desktop Entry]
Name=Rtop
Comment=Remote system monitoring tool
Expand All @@ -101,9 +120,8 @@ Categories=Utility;
EOF

# Ensure the .desktop file is executable
sudo chmod +x "$DESKTOP_FILE"
chmod +x "$DESKTOP_FILE"

echo "Setup complete. A .desktop file has been created for rtop."
echo "Please log out and log back in, or start a new shell session for changes to take effect."
echo "You can now find rtop in your applications menu and pin it to the dock if desired."

Loading