Skip to content

Instantly share code, notes, and snippets.

@ammmze
Created April 12, 2015 21:35
Show Gist options
  • Save ammmze/3ca24ab13e415580aac7 to your computer and use it in GitHub Desktop.
Save ammmze/3ca24ab13e415580aac7 to your computer and use it in GitHub Desktop.
Changing odrive file server (ofs) run user.
#!/bin/bash
# Usage: sudo ./ofs-user.sh some-new-user
# New username to use for ofs
NEW_USER=${1:-media}
OFS_HOME=/etc/ofs
# Set up home directory for ofs
USER_HOME=`sudo su $NEW_USER -c 'echo ~'`
USER_OFS_LINK=`readlink $USER_HOME/.ofs`
if [ "$USER_HOME" != "$OFS_HOME" ] && [ "$USER_OFS_LINK" != "$OFS_HOME" ]; then
if [ -d "$USER_HOME/.ofs" ]; then
echo "$USER_HOME/.ofs already exists. If this is no longer needed, then you should remove it. We are needing to link $OFS_HOME here."
exit 1
fi
ln -s "$OFS_HOME" "$USER_HOME/.ofs"
fi
# Stop the service
service ofs stop
# Change init file to use new user
sed -i "s|^USER=.*$|USER=$NEW_USER|" /etc/init.d/ofs
# Set owner of the ofs home files
chown -R $NEW_USER:$NEW_USER $OFS_HOME
# Remove tmp ofs ports file
rm /tmp/.ofs-ports
# Start the service
service ofs start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment