Changes

From Amahi Wiki
Jump to: navigation, search
The install script should do '''everything and uninstall scripts are executed in anything necessary''' to make an app work out of the webapp directory for the appbox. Simple as that.:)
The install script should do ''everything necessary'' to make an app work out of the box. Simple as that. :)
The install and uninstall scripts are executed in the webapp directory for the app. You should '''not code absolute paths''' in the (un)install scripts. You can use $PWD if you really have to. Apps may be install in different environments in the future, such as when two instance of an app are installed.
Say, for You should also not make assumptions about applicationnames.
foobarSay, for an application whose name has been assigned as
The script is run in this directory foobar
/var/hda/web-apps/foobarThe scripts are run in this directory
/var/hda/web-apps/foobar
 
However, if the user already has an app called foobar, this new app being installed may be called foobar-2 or foobar-3 ... etc. In the future we may support the installation of multiple instances of a single webapp (e.g. multiple wikis in a school).
= Useful Things =
mkdir -p /tmp/my-webapp-test
cd /tmp/my-webapp-test
wget <nowiki>http://url-for-muy-tar-ball-or-zip-file.tgz</nowiki>
untar/unzip mytarball
mv main-dir html
then run the script here ...
**NOTE: many apps include a .htaccess file that is hidden and may cause you problems. try to remove this if needed!
 
== Use of inline files with EOF ==
 
You can typically create or patch files with inline text files:
cat > foo.bar << EOF
some
$PWD
here
EOF
The above will create a file called foo.bar and have three lines. The second like will have a path. i.e. any $-variables will be substituted. When the EOF is quoted with 'EOF' there will be no substitution:  cat > foo.bar << 'EOF' some $PWD here EOF The second line will have $PWD. You can also feed inline files to patch (read man patch) with diffs that will then be used to patch files on the fly. Here is a quick guide to make install scripts easier with [[Patch and diff]] == The hda-install-file utility script ==
This utility script will install files with some details of the local installation replaced, namely:
(like a more general netmask, etc.)
== The amahi-download utility script ==
 
This script is useful to more securely download files in install scripts. It's used with a URL and the sha1sum of the file it's meant to download:
 
amahi-download -h
Usage: /usr/bin/amahi-download [options] <filename|url> <sha1sum>
-h, --help Show this help message.
This script will exit with a failure if the download fails or the checksum signature fails to check. == to To change the contents of a file while installing an webapp ==
i.e. you would need this to edit configuration files for one-click installs in HDA.
== hda-create-db-and-user utility script ==
Utility Script for creating a MySQL MariaDB database and user for accessing the newly created database.
<small>
-u, --user=name Specifies the user name to use.
Default: dbname@localhost
-p, Specifies the password for the user
Default: user name used above
-d, --drop Drops the user and the DB.
Default: dbname@localhost
To drop the same database '''<small>hda-create-db-and-user -d foo</small>'''
= Make an app start when server (re)boots =
 
The best way to have your app start when the computer boots/reboots is to add an entry to the crontab. Since the install scripts are run by the user 'apache', you can only add entries to apache's crontab. This means you cannot start any apps that require root privileges.
 
Here is an example:
 
First use the techniques from above to create the crontab entry that starts your app/daemon/server. the line starting with @reboot is the crontab entry. at the end of the crontab entry put a comment that is unique to your app. It will be used to remove the crontab item later during uninstall.
<small>
cat > run_web-app.cron << EOF
@reboot $PWD/html/web-app.py -d # web-app
EOF
</small>
 
This made a file called web-app.cron in your apps folder. web-app.py is the program that will run as the system starts.
 
Next; the first line lists all the items in the current crontab, and copys it to a temp file. the second line add's our crontab enty to the bottom of the file. the third line loads the contents of the temp file back into the users crontab.
 
<small>
crontab -l | grep -v "no crontab for" > /tmp/crontab.txt # copy the current crontab to a tempfile
cat run_web-app.cron >> /tmp/crontab.txt #add our apps line to the tempfile
crontab /tmp/crontab.txt #make the tempfile the crontab
</small>
'''NOTE'''
The script's that manipulate the crontab needs to be carefully crafted. If not coded correctly, the users crontab will be overwritten!
 
Make sure that if you add an entry to the crontab that you have the uninstall script remove it.
Here the first line list's all enties in the crontab and grep removes any line with the string "web-app" in it. this is why it is important to use a unique identifyer at the end of your crontab line. The remaining items from the crontab go into a tempfile then the contents of the tempfile are loaded into the users crontab again.
<small>
crontab -l | grep -v web-app > /tmp/web-app-uninstall-crontab.txt
crontab /tmp/web-app-uninstall-crontab.txt
</small>
Have fun creating your apps. If you need something ask at in the [http://webchat.freenode.net/?channels=amahi IRC ] :)
12,424

edits