Skip to content

Commit

Permalink
Initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Infernio committed Sep 7, 2018
1 parent 1d11129 commit 6c89b4a
Showing 1 changed file with 244 additions and 0 deletions.
244 changes: 244 additions & 0 deletions sssm
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
#!/bin/bash

# Author: Infernio <infernio at icloud dot com>
# SSSM - Simple steam skin manager.
# This script can install, upgrade and remove steam skins for specific users.

# Constants
C_GREEN='\033[1;32m'
C_RED='\033[1;31m'
C_BLUE='\033[1;34m'
C_YELLOW='\033[1;33m'
C_NC='\033[0m'
SSSM_VERSION="1.0.0"

# Parameters
action=$1

# Functions
function usage()
{
name=$(basename "${BASH_SOURCE}")
echo -e "Usage: ${name} ${C_BLUE}<action>${C_NC} ${C_YELLOW}[action-specific options]${C_NC}"
echo "SSSM (Simple Steam Skin Manager) is a simple script for managing steam skins."
echo "Skins must be installed to /usr/lib/steam/skins in order to be used."
echo ""
echo "Actions:"
echo -e " - ${C_BLUE}list ${C_YELLOW}[user]${C_NC}"
echo " Lists all currently installed skins."
echo " Parameters:"
echo -e " - ${C_YELLOW}user${C_NC} (optional): If specified, list only the skins that user has installed."
echo " Otherwise, list all globally installed skins."
echo -e " - ${C_BLUE}sync ${C_YELLOW}<skin> [user]${C_NC}"
echo " Installs or upgrades a skin for a user."
echo " Parameters:"
echo -e " - ${C_YELLOW}skin${C_NC}: The skin to install / upgrade."
echo -e " - ${C_YELLOW}user${C_NC} (optional): The user to install / upgrade the skin for."
echo " If left empty, install / upgrade for all users."
echo -e " - ${C_BLUE}remove ${C_YELLOW}<skin> [user]${C_NC}"
echo " Uninstalls a skin for a user."
echo " Parameters:"
echo -e " - ${C_YELLOW}skin${C_NC}: The skin to uninstall."
echo -e " - ${C_YELLOW}user${C_NC} (optional): The user to uninstall the skin for."
echo " If left empty, uninstall for all users."
echo -e " - ${C_BLUE}version${C_NC}"
echo " Prints the manager's version and exits."
}

function version()
{
echo "Simple Steam Skin Manager v${SSSM_VERSION}"
}

function list()
{
# Parameters
user="$1"

# if 'user' is empty, list globally installed ones
if [ -z "$user" ]
then
for skin in /usr/lib/steam/skins/*
do
if [ -d "${skin}" ]
then
skin=${skin#"/usr/lib/steam/skins/"}
echo "${skin}"
fi
done
else
# otherwise, list the ones installed by the specified user
for skin in "/home/${user}/.local/share/Steam/skins"/*
do
if [ -d "${skin}" ]
then
skin=${skin#"/home/${user}/.local/share/Steam/skins/"}
echo "${skin}"
fi
done
fi
}

function sync()
{
# Parameters
skin="$1"
user="$2"

# 'skin' may not be empty
if [ -z "$skin" ]
then
usage
exit 1
fi

# if 'user' is empty, install for all users
if [ -z "$user" ]
then
sync_forall "$skin"
exit $?
fi

echo -e "${C_BLUE} => ${C_NC}Installing skin ${C_GREEN}${skin}${C_NC} for user ${C_GREEN}${user}${C_NC}."

# Check to make sure the user actually has Steam installed
if [ ! -d "/home/${user}/.local/share/Steam" ]
then
echo -e "${C_BLUE} => ${C_RED}Installation failed:${C_NC} ${C_GREEN}${user}${C_NC} does not seem to have Steam installed."
exit 1
fi

# Create the directory, nuke the skin if it already exists and copy the new skin over
SKINDIR="/home/${user}/.local/share/Steam/skins"
mkdir -p "${SKINDIR}"
rm -rf "${SKINDIR}/${skin}"
cp -r "/usr/lib/steam/skins/${skin}" "${SKINDIR}"
res1=$?
chown -R "${user}:${user}" "${SKINDIR}/${skin}"
res2=$?

# Check if the installation succeeded
if [ $res1 -eq 0 ] && [ $res2 -eq 0 ]
then
echo -e "${C_BLUE} => ${C_NC}Installation completed successfully."
else
echo -e "${C_BLUE} => ${C_RED}Installation failed:${C_NC} Error while copying or setting ownership."
exit 1
fi
}

function sync_forall()
{
# Parameters
skin="$1"

echo -e "${C_BLUE}=> ${C_NC}Installing skin ${C_GREEN}${skin}${C_NC} for all users."
for user in /home/*
do
user=${user#"/home/"}

# Skip lost+found and root (which you shouldn't use for steam)
if [ "$user" != "lost+found" ] && [ "$user" != "root" ]
then
sync "$skin" "$user"
if [ $? -ne 0 ]
then
exit 1
fi
fi
done
echo -e "${C_BLUE}=> ${C_NC}Installation completed successfully for all users."
}

function remove()
{
# Parameters
skin="$1"
user="$2"

# 'skin' may not be empty
if [ -z "$skin" ]
then
usage
exit 1
fi

# if 'user' is empty, uninstall for all users
if [ -z "$user" ]
then
remove_forall "$skin"
exit $?
fi

echo -e "${C_BLUE} => ${C_NC}Uninstalling skin ${C_GREEN}${skin}${C_NC} for user ${C_GREEN}${user}${C_NC}."

# Check to make sure the user actually has Steam installed
if [ ! -d "/home/${user}/.local/share/Steam" ]
then
echo -e "${C_BLUE} => ${C_RED}Uninstallation failed:${C_NC} ${C_GREEN}${user}${C_NC} does not seem to have Steam installed."
exit 1
fi

# Check if the skin is installed and, if so, remove it
SKINDIR="/home/${user}/.local/share/Steam/skins"
if [ -d "${SKINDIR}/${skin}" ]
then
rm -rf "${SKINDIR}/${skin}"

# Check if the uninstallation succeeded
if [ $? -eq 0 ]
then
echo -e "${C_BLUE} => ${C_NC}Uninstallation completed successfully."
else
echo -e "${C_BLUE} => ${C_RED}Uninstallation failed:${C_NC} Error while removing files."
exit 1
fi

else
echo -e "${C_BLUE} => ${C_RED}Uninstallation failed:${C_NC} User ${C_GREEN}${user}${C_NC} does not seem to have the skin ${C_GREEN}${skin}${C_NC} installed."
exit 1
fi
}

function remove_forall()
{
# Parameters
skin="$1"

echo -e "${C_BLUE}=> ${C_NC}Uninstalling skin ${C_GREEN}${skin}${C_NC} for all users."
for user in /home/*
do
user=${user#"/home/"}

# Skip lost+found and root (which you shouldn't use for steam)
if [ "$user" != "lost+found" ] && [ "$user" != "root" ]
then
remove "$skin" "$user"
if [ $? -ne 0 ]
then
exit 1
fi
fi
done
echo -e "${C_BLUE}=> ${C_NC}Uninstallation completed successfully for all users."
}

# Main Script
case "$action" in
# just in case ;)
"sync" | "install" | "isntall")
sync "$2" "$3"
;;
"list")
list "$2"
;;
"remove" | "uninstall")
remove "$2" "$3"
;;
"version")
version
;;
*)
usage
exit 1
esac

0 comments on commit 6c89b4a

Please sign in to comment.