Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Please Test My Commandline Facebook Program (Installer Script)

  1. #1
    Join Date
    Jun 2006
    Location
    Georgia
    Beans
    1,072

    Please Test My Commandline Facebook Program (Installer Script)

    Code doesn't work atm. Check back later.
    I wrote the installer scripts.

    Please run fbcmdInstaller.
    Code:
    sudo bash fbcmdInstaller_0.2.sh
    When that's done test it with
    Code:
    fbcmd
    Then if you want to remove it run
    Code:
    sudo bash fbcmdRemove_0.2.sh
    Attached Files Attached Files
    Last edited by tdrusk; December 12th, 2008 at 12:56 AM.
    Acer Aspire 3680, Intel Celeron M, 1.41 GB RAM
    Feel free to message me if you have any questions.

  2. #2
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: Please Test My Commandline Facebook Program (Installer Script)

    Quote Originally Posted by tdrusk View Post
    I wrote the installer scripts.

    Please run fbcmdInstaller.
    Code:
    sudo sh fbcmdInstaller.sh
    When that's done test it with
    Code:
    fbcmd
    Then if you want to remove it run
    Code:
    sudo sh fbcmdRemove.sh
    I haven't run your scripts, since I don't use Facebook, but I have looked at them and have some comments:
    Code:
    #!/bin/bash
    #Installs fbcmd to /usr/lib/fbcmd
    
    #Get dependencies
    apt-get install php5-cli
    
    #make new directory for installation
    mkdir /usr/lib/fbcmd
    
    #Get fbcmd
    wget --directory-prefix=/usr/lib/fbcmd http://www.cs.ubc.ca/~davet/fbcmd/fbcmd-0-90.tgz
    
    #extract
    cd /usr/lib/fbcmd/
    tar -xvf /usr/lib/fbcmd/fbcmd-0-90.tgz 
    
    #Which browser?
    echo ""
    echo "Type the command to start your browser (ex: firefox, konqueror, etc)"
    read BROWSER
    Instead of asking which browser the user's running, just use xdg-open, which will start the default browser.
    Code:
    #Close Browser
    echo ""
    echo "Close your browser. Press Enter/Return when ready."
    read ENTER
    echo "Wait..."
    sleep 5
    Why should the user close their browser before it has even been opened? Also, the sleep 5 only wastes time. If the user closes their browser, then hits enter, the browser is dead. But again, closing the browser is pointless.
    Code:
    #Get AUTH code
    $BROWSER "http://www.facebook.com/code_gen.php?v=1.0&api_key=d96ea311638cf65f04b33c87eacf371e" &
    
    #Ask for AUTH code
    echo ""
    echo "What is your AUTH code?"
    read ANSWER
    
    #Enters AUTH code
    php /usr/lib/fbcmd/fbcmd/fbcmd.php AUTH $ANSWER
    
    #Asks for user name
    echo ""
    echo "What is your user/login name on this Linux computer?"
    read NAME
    You can detect this easily enough. Just look at $USER. If the script is running under sudo, then look at $SUDO_USER. The command env shows you all kinds of useful environment variables. And if you run sudo env, you'll see what's available from there.
    Code:
    #Create alias
    echo "alias fbcmd='php /usr/lib/fbcmd/fbcmd/fbcmd.php'" >> /home/$NAME/.bashrc
    
    #Add to .bash_aliases
    echo "if [ -f ~/.bash_aliases ]; then 
       . ~/.bash_aliases
    fi" >> /home/$NAME/.bashrc
    I think you meant /home/$USER/*. But even that's incorrect, because you can't determine a user's home directory from their username. For example, in a default installation, root's home dir is /root, not /home/root. Furthermore, there's nothing preventing user bob from having his homedir in /home/jane or /usr/local/foo/bob/home/directory. The env variable $HOME gives the correct home directory. You could also refer to ~$USER/some/file (or ~$SUDO_USER).

    Another problem is that you add code to ~/.bashrc to source ~/.bash_aliases, but you never do anything with .bash_aliases. You put your alias directly in .bashrc.

    Finally, if I ran an installer and found that it had modified my .bashrc behind my back, I'd be upset. Installers have no business doing that. Instead, it should add a symlink to the script somewhere on the PATH. The recommended way of doing this is
    Code:
    ln -s /usr/lib/fbcmd/fbcmd/fbcmd.php /usr/local/bin/fbcmd
    Code:
    #Allow all users to use
    chmod 666 /home/$NAME/.bashrc
    Why would you allow all users to use a user's .bashrc? That defeats the point of having per-user settings. If you really want global settings, set them in /etc/profile. Any time you're using a dotfile in the users homedir that won't work with 600 (or 700) permissions, you're using it wrong.
    Code:
    #Clean up
    rm /usr/lib/fbcmd/fbcmd-0-90.tgz
    
    #Finished
    exit #
    
    The exit statement really isn't necessary, since the script will automatically exit when it's finished.


    The uninstaller:
    Code:
    #!/bin/bash
    echo "What is your linux username?"
    read ANSWER
    Again, this is a unnecessary question.
    Code:
    rm -r /usr/lib/fbcmd
    echo "Remove the fbcmd and the if command above it from your .bashrc(Wait...)"
    Yet another reason not to modify the user's .bashrc.
    Code:
    sleep 4
    nano /home/$ANSWER/.bashrc
    exit #
    
    The rest of this script is unnecessary. The sleep statement does nothing, and there's no need for nano, because you shouldn't have modified .bashrc in the first place.

    EDIT: One more thing. In your instructions, you say to use sh to run your scripts, yet the shebang on both files calls bash. Which is it? Bash and sh are NOT the same thing.
    Last edited by mssever; December 11th, 2008 at 04:02 AM.

  3. #3
    Join Date
    Jun 2006
    Location
    Georgia
    Beans
    1,072

    Re: Please Test My Commandline Facebook Program (Installer Script)

    double post...
    Last edited by tdrusk; December 11th, 2008 at 05:37 AM.
    Acer Aspire 3680, Intel Celeron M, 1.41 GB RAM
    Feel free to message me if you have any questions.

  4. #4
    Join Date
    Jun 2006
    Location
    Georgia
    Beans
    1,072

    Re: Please Test My Commandline Facebook Program (Installer Script)

    Quote Originally Posted by mssever View Post
    I haven't run your scripts, since I don't use Facebook, but I have looked at them and have some comments:
    Code:
    #!/bin/bash
    #Installs fbcmd to /usr/lib/fbcmd
    
    #Get dependencies
    apt-get install php5-cli
    
    #make new directory for installation
    mkdir /usr/lib/fbcmd
    
    #Get fbcmd
    wget --directory-prefix=/usr/lib/fbcmd http://www.cs.ubc.ca/~davet/fbcmd/fbcmd-0-90.tgz
    
    #extract
    cd /usr/lib/fbcmd/
    tar -xvf /usr/lib/fbcmd/fbcmd-0-90.tgz 
    
    #Which browser?
    echo ""
    echo "Type the command to start your browser (ex: firefox, konqueror, etc)"
    read BROWSER
    Instead of asking which browser the user's running, just use xdg-open, which will start the default browser.
    Thanks, sounds good.
    Code:
    #Close Browser
    echo ""
    echo "Close your browser. Press Enter/Return when ready."
    read ENTER
    echo "Wait..."
    sleep 5
    Why should the user close their browser before it has even been opened? Also, the sleep 5 only wastes time. If the user closes their browser, then hits enter, the browser is dead. But again, closing the browser is pointless.
    The browser needs to be closed because I couldn't figure out how to make the script open a new tab or open the browser. If you have some insight in this please inform me.

    The sleep is necessary (at least it was for the current script). When I close firefox and just run
    Code:
    firefox www.google.com
    I get an error that Firefox is still running. I have to wait a few seconds. If the browser doesn't open it ruins the script because you need the AUTH.
    Code:
    #Get AUTH code
    $BROWSER "http://www.facebook.com/code_gen.php?v=1.0&api_key=d96ea311638cf65f04b33c87eacf371e" &
    
    #Ask for AUTH code
    echo ""
    echo "What is your AUTH code?"
    read ANSWER
    
    #Enters AUTH code
    php /usr/lib/fbcmd/fbcmd/fbcmd.php AUTH $ANSWER
    
    #Asks for user name
    echo ""
    echo "What is your user/login name on this Linux computer?"
    read NAME
    You can detect this easily enough. Just look at $USER. If the script is running under sudo, then look at $SUDO_USER. The command env shows you all kinds of useful environment variables. And if you run sudo env, you'll see what's available from there.
    Thanks for this.
    Code:
    #Create alias
    echo "alias fbcmd='php /usr/lib/fbcmd/fbcmd/fbcmd.php'" >> /home/$NAME/.bashrc
    
    #Add to .bash_aliases
    echo "if [ -f ~/.bash_aliases ]; then 
       . ~/.bash_aliases
    fi" >> /home/$NAME/.bashrc
    I think you meant /home/$USER/*. But even that's incorrect, because you can't determine a user's home directory from their username. For example, in a default installation, root's home dir is /root, not /home/root. Furthermore, there's nothing preventing user bob from having his homedir in /home/jane or /usr/local/foo/bob/home/directory. The env variable $HOME gives the correct home directory. You could also refer to ~$USER/some/file (or ~$SUDO_USER).

    Another problem is that you add code to ~/.bashrc to source ~/.bash_aliases, but you never do anything with .bash_aliases. You put your alias directly in .bashrc.

    Finally, if I ran an installer and found that it had modified my .bashrc behind my back, I'd be upset. Installers have no business doing that. Instead, it should add a symlink to the script somewhere on the PATH. The recommended way of doing this is
    Code:
    ln -s /usr/lib/fbcmd/fbcmd/fbcmd.php /usr/local/bin/fbcmd
    [code]
    Thanks. Will fix.
    #Allow all users to use
    Code:
    chmod 666 /home/$NAME/.bashrc
    Why would you allow all users to use a user's .bashrc? That defeats the point of having per-user settings. If you really want global settings, set them in /etc/profile. Any time you're using a dotfile in the users homedir that won't work with 600 (or 700) permissions, you're using it wrong.
    How can I make it so the user can access the file like before.
    Code:
    #Clean up
    rm /usr/lib/fbcmd/fbcmd-0-90.tgz
    
    #Finished
    exit #
    
    The exit statement really isn't necessary, since the script will automatically exit when it's finished.
    ah cool

    The uninstaller:
    Code:
    #!/bin/bash
    echo "What is your linux username?"
    read ANSWER
    Again, this is a unnecessary question.
    thanks
    Code:
    rm -r /usr/lib/fbcmd
    echo "Remove the fbcmd and the if command above it from your .bashrc(Wait...)"
    Yet another reason not to modify the user's .bashrc.
    Code:
    sleep 4
    nano /home/$ANSWER/.bashrc
    exit #
    
    The rest of this script is unnecessary. The sleep statement does nothing, and there's no need for nano, because you shouldn't have modified .bashrc in the first place.
    Aight cool. I left the sleep statement so the user would have time to read it, but I won't need that anymore.
    EDIT: One more thing. In your instructions, you say to use sh to run your scripts, yet the shebang on both files calls bash. Which is it? Bash and sh are NOT the same thing.
    I just realized that too. Would I omit that first line if I wanted to run them with sh?

    Thanks so much for your help. I have never written a script like this and I need all the crit I can get.
    Acer Aspire 3680, Intel Celeron M, 1.41 GB RAM
    Feel free to message me if you have any questions.

  5. #5
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: Please Test My Commandline Facebook Program (Installer Script)

    Quote Originally Posted by tdrusk View Post
    The browser needs to be closed because I couldn't figure out how to make the script open a new tab or open the browser. If you have some insight in this please inform me.
    When I type either "xdg-open http://www.google.com" or "firefox http://www.google.com" I get a new tab in the currently-running firefox instance. My gmail_link script includes the following function to launch a URL in a browser. I wrote this before I knew about xdg-open, so it includes a bit of logic to work out which browser to open. I include this because Opera is a different beast from the rest--unless they've fixed it by now. Anyway, here's a code snippet:
    Code:
    function callBrowser {
        local ua="$1"  # User-agent, aka browser
        local url="$2"
    
        if [[ $ua == 'opera' ]]; then
            exec opera --remote "openURL($url,new-page)"
        else exec $ua "$url"
        fi
    }
    Of course, in your case you'd need to drop the exec.

    How can I make it so the user can access the file like before.
    Don't change .bashrc in the first place. Then there will be no work to do.

    Oh, if your script happens to create any files, remember that those files will be owned by root, since the script is running as root. So you might need to chown stuff (anything you install in the user's home directory chould be chowned to the user).
    I just realized that too. Would I omit that first line if I wanted to run them with sh?
    It's always a good idea to include a shebang, because many people will set the x-bit on your file and run it with ./fbcmdInstaller.sh. If you want it to run with sh, set the shebang to #!/bin/sh. But IMO there are very few reasons to prefer sh over bash these days. And bash is a known quantity. sh will vary a bit. For example, on many Linux systems, sh actually runs bash in reduced-feature mode. In Ubuntu, sh runs dash. Other systems might use something else for sh. And every shell will have its own corner cases. With bash, you know what you're getting, and the odds of running into a system without bash are slim (and the odds of a Linux system without bash are virtually nil).

    So my recommendation is to leave the shebang as is, and amend your instructions to either tell the user to make the file executable and then directly execute it, or to call it with "bash filename".

    EDIT: One more thing: If you explicitly name an interpreter (sh somefile, bash somefile, php somefile), then it doesn't matter whether the file is executable.
    Last edited by mssever; December 11th, 2008 at 05:31 AM.

  6. #6
    Join Date
    Jun 2006
    Location
    Georgia
    Beans
    1,072

    Re: Please Test My Commandline Facebook Program (Installer Script)

    Quote Originally Posted by mssever View Post
    When I type either "xdg-open http://www.google.com" or "firefox http://www.google.com" I get a new tab in the currently-running firefox instance. My gmail_link script includes the following function to launch a URL in a browser. I wrote this before I knew about xdg-open, so it includes a bit of logic to work out which browser to open. I include this because Opera is a different beast from the rest--unless they've fixed it by now. Anyway, here's a code snippet:
    Code:
    function callBrowser {
        local ua="$1"  # User-agent, aka browser
        local url="$2"
    
        if [[ $ua == 'opera' ]]; then
            exec opera --remote "openURL($url,new-page)"
        else exec $ua "$url"
        fi
    }
    Of course, in your case you'd need to drop the exec.

    Don't change .bashrc in the first place. Then there will be no work to do.

    Oh, if your script happens to create any files, remember that those files will be owned by root, since the script is running as root. So you might need to chown stuff (anything you install in the user's home directory chould be chowned to the user).
    It's always a good idea to include a shebang, because many people will set the x-bit on your file and run it with ./fbcmdInstaller.sh. If you want it to run with sh, set the shebang to #!/bin/sh. But IMO there are very few reasons to prefer sh over bash these days. And bash is a known quantity. sh will vary a bit. For example, on many Linux systems, sh actually runs bash in reduced-feature mode. In Ubuntu, sh runs dash. Other systems might use something else for sh. And every shell will have its own corner cases. With bash, you know what you're getting, and the odds of running into a system without bash are slim (and the odds of a Linux system without bash are virtually nil).

    So my recommendation is to leave the shebang as is, and amend your instructions to either tell the user to make the file executable and then directly execute it, or to call it with "bash filename".

    EDIT: One more thing: If you explicitly name an interpreter (sh somefile, bash somefile, php somefile), then it doesn't matter whether the file is executable.
    Quote Originally Posted by mssever View Post
    I haven't run your scripts, since I don't use Facebook, but I have looked at them and have some comments:
    Code:
    #!/bin/bash
    #Installs fbcmd to /usr/lib/fbcmd
    
    #Get dependencies
    apt-get install php5-cli
    
    #make new directory for installation
    mkdir /usr/lib/fbcmd
    
    #Get fbcmd
    wget --directory-prefix=/usr/lib/fbcmd http://www.cs.ubc.ca/~davet/fbcmd/fbcmd-0-90.tgz
    
    #extract
    cd /usr/lib/fbcmd/
    tar -xvf /usr/lib/fbcmd/fbcmd-0-90.tgz 
    
    #Which browser?
    echo ""
    echo "Type the command to start your browser (ex: firefox, konqueror, etc)"
    read BROWSER
    Instead of asking which browser the user's running, just use xdg-open, which will start the default browser.
    Thanks, sounds good.
    Code:
    #Close Browser
    echo ""
    echo "Close your browser. Press Enter/Return when ready."
    read ENTER
    echo "Wait..."
    sleep 5
    Why should the user close their browser before it has even been opened? Also, the sleep 5 only wastes time. If the user closes their browser, then hits enter, the browser is dead. But again, closing the browser is pointless.
    The browser needs to be closed because I couldn't figure out how to make the script open a new tab or open the browser. If you have some insight in this please inform me.

    The sleep is necessary (at least it was for the current script). When I close firefox and just run
    Code:
    firefox www.google.com
    I get an error that Firefox is still running. I have to wait a few seconds. If the browser doesn't open it ruins the script because you need the AUTH.
    Code:
    #Get AUTH code
    $BROWSER "http://www.facebook.com/code_gen.php?v=1.0&api_key=d96ea311638cf65f04b33c87eacf371e" &
    
    #Ask for AUTH code
    echo ""
    echo "What is your AUTH code?"
    read ANSWER
    
    #Enters AUTH code
    php /usr/lib/fbcmd/fbcmd/fbcmd.php AUTH $ANSWER
    
    #Asks for user name
    echo ""
    echo "What is your user/login name on this Linux computer?"
    read NAME
    You can detect this easily enough. Just look at $USER. If the script is running under sudo, then look at $SUDO_USER. The command env shows you all kinds of useful environment variables. And if you run sudo env, you'll see what's available from there.
    Thanks for this.
    Code:
    #Create alias
    echo "alias fbcmd='php /usr/lib/fbcmd/fbcmd/fbcmd.php'" >> /home/$NAME/.bashrc
    
    #Add to .bash_aliases
    echo "if [ -f ~/.bash_aliases ]; then 
       . ~/.bash_aliases
    fi" >> /home/$NAME/.bashrc
    I think you meant /home/$USER/*. But even that's incorrect, because you can't determine a user's home directory from their username. For example, in a default installation, root's home dir is /root, not /home/root. Furthermore, there's nothing preventing user bob from having his homedir in /home/jane or /usr/local/foo/bob/home/directory. The env variable $HOME gives the correct home directory. You could also refer to ~$USER/some/file (or ~$SUDO_USER).

    Another problem is that you add code to ~/.bashrc to source ~/.bash_aliases, but you never do anything with .bash_aliases. You put your alias directly in .bashrc.

    Finally, if I ran an installer and found that it had modified my .bashrc behind my back, I'd be upset. Installers have no business doing that. Instead, it should add a symlink to the script somewhere on the PATH. The recommended way of doing this is
    Code:
    ln -s /usr/lib/fbcmd/fbcmd/fbcmd.php /usr/local/bin/fbcmd
    Thanks. Will fix.
    #Allow all users to use
    chmod 666 /home/$NAME/.bashrc
    [/code]
    Why would you allow all users to use a user's .bashrc? That defeats the point of having per-user settings. If you really want global settings, set them in /etc/profile. Any time you're using a dotfile in the users homedir that won't work with 600 (or 700) permissions, you're using it wrong.
    How can I make it so the user can access the file like before.
    Code:
    #Clean up
    rm /usr/lib/fbcmd/fbcmd-0-90.tgz
    
    #Finished
    exit #
    
    The exit statement really isn't necessary, since the script will automatically exit when it's finished.
    ah cool

    The uninstaller:
    Code:
    #!/bin/bash
    echo "What is your linux username?"
    read ANSWER
    Again, this is a unnecessary question.
    thanks
    Code:
    rm -r /usr/lib/fbcmd
    echo "Remove the fbcmd and the if command above it from your .bashrc(Wait...)"
    Yet another reason not to modify the user's .bashrc.
    Code:
    sleep 4
    nano /home/$ANSWER/.bashrc
    exit #
    
    The rest of this script is unnecessary. The sleep statement does nothing, and there's no need for nano, because you shouldn't have modified .bashrc in the first place.
    Aight cool. I left the sleep statement so the user would have time to read it, but I won't need that anymore.
    EDIT: One more thing. In your instructions, you say to use sh to run your scripts, yet the shebang on both files calls bash. Which is it? Bash and sh are NOT the same thing.
    I just realized that too. Would I omit that first line if I wanted to run them with sh?

    Thanks so much for your help. I have never written a script like this and I need all the crit I can get.
    Thanks. Very useful info. I'm going to work on this more tomorrow. Brain is tired.
    Last edited by tdrusk; December 11th, 2008 at 05:38 AM.
    Acer Aspire 3680, Intel Celeron M, 1.41 GB RAM
    Feel free to message me if you have any questions.

  7. #7
    Join Date
    Jun 2006
    Location
    Georgia
    Beans
    1,072

    Re: Please Test My Commandline Facebook Program (Installer Script)

    Aight. I have the program running good. I was just wondering what I should do with the /usr/local/bin/fbcmd? How can I make it so a normal user can use it?
    Acer Aspire 3680, Intel Celeron M, 1.41 GB RAM
    Feel free to message me if you have any questions.

  8. #8
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: Please Test My Commandline Facebook Program (Installer Script)

    Quote Originally Posted by tdrusk View Post
    Aight. I have the program running good. I was just wondering what I should do with the /usr/local/bin/fbcmd? How can I make it so a normal user can use it?
    If it's a symlink, everyone can use it, provided the target has the proper permissions (execute and all that). Also, since the target is apparently a command-line PHP script, make sure the script has an appropriate shebang line.

    Alternatively, fbcmd could easily be a shell script wrapper that merely calls the target with any necessary command-line arguments, environment, etc. Of course, the wrapper still must be executable and have an appropriate shebang. In either case, I recommend the permissions 755.

  9. #9
    Join Date
    Jun 2006
    Location
    Georgia
    Beans
    1,072

    Re: Please Test My Commandline Facebook Program (Installer Script)

    Okay. The new and improved scripts are up. What should I name them? (.py,.sh)
    I know it doesn't matter since I'm calling bash, but still...
    Acer Aspire 3680, Intel Celeron M, 1.41 GB RAM
    Feel free to message me if you have any questions.

  10. #10
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: Please Test My Commandline Facebook Program (Installer Script)

    Quote Originally Posted by tdrusk View Post
    Okay. The new and improved scripts are up. What should I name them? (.py,.sh)
    I know it doesn't matter since I'm calling bash, but still...
    Don't use .py unless they're written in Python. .sh is a good choice, as is the nonstandard-but-clear .bash. Of course, since executables traditionally have no extension, you could simply omit the extension altogether. Remember, the main purpose of extensions in the *nix world is to give human users some idea of the file's type. The system doesn't care. If the user sees .sh, they'll assume a shell script of some sort. If they see .py, they'll assume it's written in Python. Whatever you do is fine, as long as you don't mislead people.

    One other convention to be aware of is that uppercase letters are generally not used in filenames (with a few prominant exceptions, such as X). Generally, words are separated with either hyphens or underscores (or abbreviated, though I personally tend to avoid all but the best-established abbreviations because other people might not understand some abbreviation I just invented.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •