Skip to content

Instantly share code, notes, and snippets.

@pkulev
Created November 25, 2015 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkulev/dee4bf8d3fa768c487eb to your computer and use it in GitHub Desktop.
Save pkulev/dee4bf8d3fa768c487eb to your computer and use it in GitHub Desktop.
#!/bin/sh -e
PROG="${0##*/}"
usage() {
echo -e "Usage: ${PROG} ACTION FILE\n"
echo " ${PROG} moves or copies FILE to /usr/portage/distfiles and sets proper umask."
echo " ACTION: action {cp, mv}."
echo -e " FILE: path to file.\n"
echo " You mustn't run this script with root privileges."
exit 0
}
[ $# -eq 2 ] || usage
[ ${EUID} -ne 0 ] || usage
action="$1" && shift
filename="$1" && shift
[ "$action" = "cp" ] || [ "$action" = "mv" ] || usage
destination="/usr/portage/distfiles"
filemask="664"
perform_action() {
sudo $1 $2 $3
sudo chmod $4 "$3/$2"
sudo chown ${USER}:${USER} "$3/$2"
}
echo "action: ${action}"
echo "destination: ${destination}/${filename}"
echo "umask: ${filemask}"
echo "owner: ${USER}:${USER}"
perform_action ${action} ${filename} ${destination} ${filemask}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment