Created
November 25, 2015 22:57
-
-
Save pkulev/dee4bf8d3fa768c487eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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