Document use of the template command
This commit is contained in:
parent
2d078653bb
commit
511a8c1683
|
@ -19,253 +19,47 @@ Freedombone consists of a set of bash scripts. There are a lot of them, but they
|
|||
* Adding extra apps
|
||||
Suppose you have some internet application which you want to add to the system. To do this you need to create an app script which tells the system how to install/remove and also backup/restore. The script should be designed to work with the current stable version of Debian.
|
||||
|
||||
On an installed system the app scripts go into the directory:
|
||||
There's a command which you can use to generate scripts for new apps. Some examples are as follows:
|
||||
|
||||
To create a script for a generic PHP plus MySql/MariaDB web app:
|
||||
|
||||
#+begin_src bash
|
||||
/usr/share/freedombone/apps
|
||||
freedombone-template --app [name] -e [email] -r [repo url] -c [commit] --php yes -d mariadb > src/freedombone-app-myappname
|
||||
#+end_src
|
||||
|
||||
and within the project repo they appear within the /src/ directory. Your new app script should have the name:
|
||||
For a Nodejs app with MySql/MariaDB database:
|
||||
|
||||
#+begin_src bash
|
||||
freedombone-app-[myappname]
|
||||
freedombone-template --app [name] -e [email] -r [repo url] -c [commit] --node yes -d mariadb --dir /etc/myappname --daemon yes > src/freedombone-app-myappname
|
||||
#+end_src
|
||||
|
||||
The /myappname/ value should not contain any spaces and will appear in the list of available apps.
|
||||
|
||||
An example template for an app script is shown below. Copy this and add whatever variables and configuration you need. Search and replace /myappname/ with your own.
|
||||
For a Python app with Postgresql database:
|
||||
|
||||
#+begin_src bash
|
||||
#!/bin/bash
|
||||
# Copyright (C) Year YourName <YourEmail>
|
||||
#
|
||||
# This program is free software: you can redistribute it
|
||||
# and/or modify it under the terms of the GNU Affero General
|
||||
# Public License as published by the Free Software Foundation,
|
||||
# either version 3 of the License, or (at your option) any
|
||||
# later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
|
||||
# 'full' includes your app in the full installation and you
|
||||
# can also add other variants, separated by spaces. The
|
||||
# available variants will be detected automatically from the
|
||||
# app scripts. In most cases don't change this.
|
||||
VARIANTS='full'
|
||||
|
||||
# If you want this to appear on the control panel About screen
|
||||
SHOW_ON_ABOUT=1
|
||||
|
||||
# If you want this app to be in the default installation,
|
||||
# otherwise it will be available but not selected by default
|
||||
IN_DEFAULT_INSTALL=1
|
||||
|
||||
SOME_IMPORTANT_CONFIG_VARIABLE='some important value'
|
||||
ANOTHER_IMPORTANT_CONFIG_VARIABLE='foo'
|
||||
MY_FUNKY_AVATAR=https://some-domain-or-other/fro.png
|
||||
MYAPPNAME_ONION_PORT=[port number]
|
||||
MYAPPNAME_DB_PASSWORD=
|
||||
|
||||
# A directory where the data for this app exists
|
||||
MYAPP_DATA_DIR=/var/lib/somedirectory
|
||||
|
||||
# List of configuration variables used by the app
|
||||
myappname_variables=(ONION_ONLY
|
||||
MY_USERNAME
|
||||
SOME_IMPORTANT_CONFIG_VARIABLE
|
||||
ANOTHER_IMPORTANT_CONFIG_VARIABLE
|
||||
MY_FUNKY_AVATAR
|
||||
MYAPPNAME_ONION_PORT
|
||||
MYAPPNAME_DB_PASSWORD)
|
||||
|
||||
function logging_on_myappname {
|
||||
echo -n ''
|
||||
# Commands to turn on logging go here
|
||||
}
|
||||
|
||||
function logging_off_myappname {
|
||||
echo -n ''
|
||||
# Commands to turn off logging go here
|
||||
}
|
||||
|
||||
function change_password_myappname {
|
||||
PASSWORD_USERNAME="$1"
|
||||
PASSWORD_NEW="$2"
|
||||
# Do something to change the password
|
||||
}
|
||||
|
||||
function reconfigure_myappname {
|
||||
echo -n ''
|
||||
# Do something to delete existing keys/identity and
|
||||
# generate new ones
|
||||
}
|
||||
|
||||
function upgrade_myappname {
|
||||
echo -n ''
|
||||
# Do something to upgrade this app.
|
||||
# If it's a debian package then it will be maintained by the
|
||||
# operating system and you don't need anything here
|
||||
}
|
||||
|
||||
function backup_local_myappname {
|
||||
# If your app has a MariaDB/MySQL database
|
||||
backup_database_to_usb myappname
|
||||
|
||||
# To backup a directory
|
||||
backup_directory_to_usb $MYAPP_DATA_DIR myappname
|
||||
|
||||
# if you need to backup data within individual user
|
||||
# home directories
|
||||
for d in /home/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
||||
if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
||||
echo $"Backing up myappname config for $USERNAME"
|
||||
if [ -d /home/$USERNAME/.config/myappname ]; then
|
||||
backup_directory_to_usb \
|
||||
/home/$USERNAME/.config/myappname \
|
||||
myappname_users/$USERNAME
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function restore_local_myappname {
|
||||
temp_restore_dir=/root/tempmyappname
|
||||
|
||||
# If your app has a MariaDB/MySQL database
|
||||
restore_database myappname
|
||||
|
||||
# Restore some data from a directory
|
||||
# Note that we don't restore directly but to a temporary
|
||||
# directory and then copy the files. This ensures that if
|
||||
# there is a restore failure you don't end up with
|
||||
# half-copied or corrupted files
|
||||
restore_directory_from_usb $MYAPP_DATA_DIR myappname
|
||||
cp -r $temp_restore_dir/$MYAPP_DATA_DIR $MYAPP_DATA_DIR
|
||||
rm -rf $temp_restore_dir
|
||||
|
||||
# If you need to restore a configuration directory for each user
|
||||
if [ -d $USB_MOUNT/backup/myappname_users ]; then
|
||||
for d in $USB_MOUNT/backup/myappname_users/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
||||
if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
||||
if [ ! -d /home/$USERNAME ]; then
|
||||
${PROJECT_NAME}-adduser $USERNAME
|
||||
fi
|
||||
echo $"Restoring Vim config for $USERNAME"
|
||||
function_check restore_directory_from_usb
|
||||
restore_directory_from_usb $temp_restore_dir \
|
||||
myappname_users/$USERNAME
|
||||
cp -r $temp_restore_dir/home/$USERNAME/.config \
|
||||
/home/$USERNAME/
|
||||
if [ ! "$?" = "0" ]; then
|
||||
rm -rf $temp_restore_dir
|
||||
set_user_permissions
|
||||
backup_unmount_drive
|
||||
exit 664
|
||||
fi
|
||||
rm -rf $temp_restore_dir
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_remote_myappname {
|
||||
# this should be the same as backup_local_myappname,
|
||||
# but call the backup functions backup_directory_to_friend
|
||||
# and backup_database_to_friend
|
||||
}
|
||||
|
||||
function restore_remote_vim {
|
||||
# this should be the same as restore_local_myappname,
|
||||
# but call the restore function restore_directory_from_friend
|
||||
# and restore_database_from_friend
|
||||
}
|
||||
|
||||
function remove_myappname {
|
||||
# if it's a debian package then:
|
||||
apt-get -y remove --purge [my-app-package-name]
|
||||
|
||||
# If your app has a MariaDB/MySQL database
|
||||
drop_database myappname
|
||||
|
||||
# If your app uses an onion address
|
||||
remove_onion_service myappname ${MYAPPNAME_ONION_PORT}
|
||||
}
|
||||
|
||||
function install_myappname {
|
||||
# if it's a debian package then:
|
||||
apt-get -y install [my-app-package-name]
|
||||
|
||||
# If you need to create a MariaDB/MySQL database for the app
|
||||
MYAPPNAME_DB_PASSWORD="$(create_password 20)"
|
||||
create_database myappname "$MYAPPNAME_DB_PASSWORD" $MY_USERNAME
|
||||
|
||||
# If you need to create an onion address for the app
|
||||
MYAPPNAME_ONION_HOSTNAME=$(add_onion_service myappname \
|
||||
80 ${MYAPPNAME_ONION_PORT})
|
||||
|
||||
# Do any other configuration
|
||||
# Here you might use $ONION_ONLY or
|
||||
# $SOME_IMPORTANT_CONFIG_VARIABLE
|
||||
|
||||
# Mark the app as having installed successfully
|
||||
# If this variable isn't set then it will be assumed that
|
||||
# the install has failed
|
||||
APP_INSTALLED=1
|
||||
}
|
||||
|
||||
function install_interactive_myappname {
|
||||
# Interactively obtain some values using dialog, such as
|
||||
# domain names. An avatar changing example is:
|
||||
data=$(tempfile 2>/dev/null)
|
||||
trap "rm -f $data" 0 1 2 5 15
|
||||
dialog --title $"Change your avatar" \
|
||||
--backtitle $"Freedombone Control Panel" \
|
||||
--inputbox $"Enter a URL for an image. It should be " \
|
||||
$"approximately a square image." 8 75 2>$data
|
||||
sel=$?
|
||||
case $sel in
|
||||
0)
|
||||
MY_FUNKY_AVATAR=$(<$data)
|
||||
if [ ${#MY_FUNKY_AVATAR} -gt 3 ]; then
|
||||
clear
|
||||
|
||||
# do whatever is needed to change the avatar
|
||||
# in your app
|
||||
|
||||
dialog --title $"Change your avatar" \
|
||||
--msgbox $"Your avatar has been changed" 6 40
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# install_myappname will be called automatically after this function
|
||||
}
|
||||
|
||||
# NOTE: deliberately no exit 0
|
||||
freedombone-template --app [name] -e [email] -r [repo url] -c [commit] -d postgresql --dir /etc/myappname --daemon yes > src/freedombone-app-myappname
|
||||
#+end_src
|
||||
|
||||
To test your app log into your system, select *Exit to command line* then gain root powers with:
|
||||
For a Python app without any database:
|
||||
|
||||
#+begin_src bash
|
||||
sudo su
|
||||
freedombone-template --app [name] -e [email] -r [repo url] -c [commit] --dir /etc/myappname --daemon yes > src/freedombone-app-myappname
|
||||
#+end_src
|
||||
|
||||
Copy your app script to */usr/share/freedombone/apps/freedombone-app-myappname*.
|
||||
|
||||
And run the admin control panel:
|
||||
For more details see the manpage:
|
||||
|
||||
#+begin_src bash
|
||||
control
|
||||
man freedombone-template
|
||||
#+end_src
|
||||
|
||||
Select *Add/Remove Apps* and if all is well then you should see your app listed as installable. Test that installing and removing it works as expected.
|
||||
When your new script is ready for testing you can install it with:
|
||||
|
||||
Submit your working app to *https://github.com/bashrc/freedombone/issues*
|
||||
#+begin_src bash
|
||||
make install
|
||||
#+end_src
|
||||
|
||||
Then run the administrator control panel and you should see the new app within *Add/Remove apps*.
|
||||
|
||||
Submit your working app to *https://github.com/bashrc/freedombone/issues* or create a pull request.
|
||||
|
||||
* Customising mesh images
|
||||
If you want to make your own specially branded version of the mesh images, such as for a particular event, then to change the default desktop backgrounds edit the images within *img/backgrounds* and to change the available avatars and desktop icons edit the images within *img/avatars*. Re-create disk images using the instructions shown previously.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2017-12-20 Wed 12:42 -->
|
||||
<!-- 2018-02-06 Tue 21:55 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>‎</title>
|
||||
|
@ -246,297 +246,92 @@ for the JavaScript code in this tag.
|
|||
|
||||
<center><h1>Developers Guide</h1></center>
|
||||
|
||||
<div id="outline-container-org6818d03" class="outline-2">
|
||||
<h2 id="org6818d03">Introduction</h2>
|
||||
<div class="outline-text-2" id="text-org6818d03">
|
||||
<div id="outline-container-org178b393" class="outline-2">
|
||||
<h2 id="org178b393">Introduction</h2>
|
||||
<div class="outline-text-2" id="text-org178b393">
|
||||
<p>
|
||||
Freedombone consists of a set of bash scripts. There are a lot of them, but they're not very complicated. If you're familiar with the GNU/Linux commandline and can hack a bash script then you can probably add a new app or fix a bug in the system. There are no trendy development frameworks to learn or to get in your way. You might also want to consult the <a href="./codeofconduct.html">Code of Conduct</a>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-org080672c" class="outline-2">
|
||||
<h2 id="org080672c">Adding extra apps</h2>
|
||||
<div class="outline-text-2" id="text-org080672c">
|
||||
<div id="outline-container-org694dd79" class="outline-2">
|
||||
<h2 id="org694dd79">Adding extra apps</h2>
|
||||
<div class="outline-text-2" id="text-org694dd79">
|
||||
<p>
|
||||
Suppose you have some internet application which you want to add to the system. To do this you need to create an app script which tells the system how to install/remove and also backup/restore. The script should be designed to work with the current stable version of Debian.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
On an installed system the app scripts go into the directory:
|
||||
There's a command which you can use to generate scripts for new apps. Some examples are as follows:
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To create a script for a generic PHP plus MySql/MariaDB web app:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-bash">/usr/share/freedombone/apps
|
||||
<pre class="src src-bash">freedombone-template --app [name] -e [email] -r [repo url] -c [commit] --php yes -d mariadb > src/freedombone-app-myappname
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
and within the project repo they appear within the <i>src</i> directory. Your new app script should have the name:
|
||||
For a Nodejs app with MySql/MariaDB database:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-bash">freedombone-app-[myappname]
|
||||
<pre class="src src-bash">freedombone-template --app [name] -e [email] -r [repo url] -c [commit] --node yes -d mariadb --dir /etc/myappname --daemon yes > src/freedombone-app-myappname
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
The <i>myappname</i> value should not contain any spaces and will appear in the list of available apps.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
An example template for an app script is shown below. Copy this and add whatever variables and configuration you need. Search and replace <i>myappname</i> with your own.
|
||||
For a Python app with Postgresql database:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-bash"><span class="org-comment-delimiter">#</span><span class="org-comment">!/bin/</span><span class="org-keyword">bash</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Copyright (C) Year YourName <YourEmail></span>
|
||||
<span class="org-comment-delimiter">#</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">This program is free software: you can redistribute it</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">and/or modify it under the terms of the GNU Affero General</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Public License as published by the Free Software Foundation,</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">either version 3 of the License, or (at your option) any</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">later version.</span>
|
||||
<span class="org-comment-delimiter">#</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">This program is distributed in the hope that it will be useful,</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">GNU Affero General Public License for more details.</span>
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">'full' includes your app in the full installation and you</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">can also add other variants, separated by spaces. The</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">available variants will be detected automatically from the</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">app scripts. In most cases don't change this.</span>
|
||||
<span class="org-variable-name">VARIANTS</span>=<span class="org-string">'full'</span>
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If you want this to appear on the control panel About screen</span>
|
||||
<span class="org-variable-name">SHOW_ON_ABOUT</span>=1
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If you want this app to be in the default installation,</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">otherwise it will be available but not selected by default</span>
|
||||
<span class="org-variable-name">IN_DEFAULT_INSTALL</span>=1
|
||||
|
||||
<span class="org-variable-name">SOME_IMPORTANT_CONFIG_VARIABLE</span>=<span class="org-string">'some important value'</span>
|
||||
<span class="org-variable-name">ANOTHER_IMPORTANT_CONFIG_VARIABLE</span>=<span class="org-string">'foo'</span>
|
||||
<span class="org-variable-name">MY_FUNKY_AVATAR</span>=https://some-domain-or-other/fro.png
|
||||
<span class="org-variable-name">MYAPPNAME_ONION_PORT</span>=[port number]
|
||||
<span class="org-variable-name">MYAPPNAME_DB_PASSWORD</span>=
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">A directory where the data for this app exists</span>
|
||||
<span class="org-variable-name">MYAPP_DATA_DIR</span>=/var/lib/somedirectory
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">List of configuration variables used by the app</span>
|
||||
<span class="org-variable-name">myappname_variables</span>=(ONION_ONLY
|
||||
MY_USERNAME
|
||||
SOME_IMPORTANT_CONFIG_VARIABLE
|
||||
ANOTHER_IMPORTANT_CONFIG_VARIABLE
|
||||
MY_FUNKY_AVATAR
|
||||
MYAPPNAME_ONION_PORT
|
||||
MYAPPNAME_DB_PASSWORD)
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">logging_on_myappname</span> {
|
||||
<span class="org-builtin">echo</span> -n <span class="org-string">''</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Commands to turn on logging go here</span>
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">logging_off_myappname</span> {
|
||||
<span class="org-builtin">echo</span> -n <span class="org-string">''</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Commands to turn off logging go here</span>
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">change_password_myappname</span> {
|
||||
<span class="org-variable-name">PASSWORD_USERNAME</span>=<span class="org-string">"$1"</span>
|
||||
<span class="org-variable-name">PASSWORD_NEW</span>=<span class="org-string">"$2"</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Do something to change the password</span>
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">reconfigure_myappname</span> {
|
||||
<span class="org-builtin">echo</span> -n <span class="org-string">''</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Do something to delete existing keys/identity and</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">generate new ones</span>
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">upgrade_myappname</span> {
|
||||
<span class="org-builtin">echo</span> -n <span class="org-string">''</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Do something to upgrade this app.</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If it's a debian package then it will be maintained by the</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">operating system and you don't need anything here</span>
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">backup_local_myappname</span> {
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If your app has a MariaDB/MySQL database</span>
|
||||
backup_database_to_usb myappname
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">To backup a directory</span>
|
||||
backup_directory_to_usb $<span class="org-variable-name">MYAPP_DATA_DIR</span> myappname
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">if you need to backup data within individual user</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">home directories</span>
|
||||
<span class="org-keyword">for</span> d<span class="org-keyword"> in</span> /home/*/ ; <span class="org-keyword">do</span>
|
||||
<span class="org-variable-name">USERNAME</span>=$(<span class="org-sh-quoted-exec">echo</span> <span class="org-string">"$d"</span> | awk -F <span class="org-string">'/'</span> <span class="org-string">'{print $3}'</span>)
|
||||
<span class="org-keyword">if</span> [[ $(<span class="org-sh-quoted-exec">is_valid_user</span> <span class="org-string">"$USERNAME"</span>) == <span class="org-string">"1"</span> ]]; <span class="org-keyword">then</span>
|
||||
<span class="org-builtin">echo</span> $<span class="org-string">"Backing up myappname config for $USERNAME"</span>
|
||||
<span class="org-keyword">if</span> [ -d /home/$<span class="org-variable-name">USERNAME</span>/.config/myappname ]; <span class="org-keyword">then</span>
|
||||
backup_directory_to_usb <span class="org-sh-escaped-newline">\</span>
|
||||
/home/$<span class="org-variable-name">USERNAME</span>/.config/myappname <span class="org-sh-escaped-newline">\</span>
|
||||
myappname_users/$<span class="org-variable-name">USERNAME</span>
|
||||
<span class="org-keyword">fi</span>
|
||||
<span class="org-keyword">fi</span>
|
||||
<span class="org-keyword">done</span>
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">restore_local_myappname</span> {
|
||||
<span class="org-variable-name">temp_restore_dir</span>=/root/tempmyappname
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If your app has a MariaDB/MySQL database</span>
|
||||
restore_database myappname
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Restore some data from a directory</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Note that we don't restore directly but to a temporary</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">directory and then copy the files. This ensures that if</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">there is a restore failure you don't end up with</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">half-copied or corrupted files</span>
|
||||
restore_directory_from_usb $<span class="org-variable-name">MYAPP_DATA_DIR</span> myappname
|
||||
cp -r $<span class="org-variable-name">temp_restore_dir</span>/$<span class="org-variable-name">MYAPP_DATA_DIR</span> $<span class="org-variable-name">MYAPP_DATA_DIR</span>
|
||||
rm -rf $<span class="org-variable-name">temp_restore_dir</span>
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If you need to restore a configuration directory for each user</span>
|
||||
<span class="org-keyword">if</span> [ -d $<span class="org-variable-name">USB_MOUNT</span>/backup/myappname_users ]; <span class="org-keyword">then</span>
|
||||
<span class="org-keyword">for</span> d<span class="org-keyword"> in</span> $<span class="org-variable-name">USB_MOUNT</span>/backup/myappname_users/*/ ; <span class="org-keyword">do</span>
|
||||
<span class="org-variable-name">USERNAME</span>=$(<span class="org-sh-quoted-exec">echo</span> <span class="org-string">"$d"</span> | awk -F <span class="org-string">'/'</span> <span class="org-string">'{print $6}'</span>)
|
||||
<span class="org-keyword">if</span> [[ $(<span class="org-sh-quoted-exec">is_valid_user</span> <span class="org-string">"$USERNAME"</span>) == <span class="org-string">"1"</span> ]]; <span class="org-keyword">then</span>
|
||||
<span class="org-keyword">if</span> [ <span class="org-negation-char">!</span> -d /home/$<span class="org-variable-name">USERNAME</span> ]; <span class="org-keyword">then</span>
|
||||
${<span class="org-variable-name">PROJECT_NAME</span>}-adduser $<span class="org-variable-name">USERNAME</span>
|
||||
<span class="org-keyword">fi</span>
|
||||
<span class="org-builtin">echo</span> $<span class="org-string">"Restoring Vim config for $USERNAME"</span>
|
||||
function_check restore_directory_from_usb
|
||||
restore_directory_from_usb $<span class="org-variable-name">temp_restore_dir</span> <span class="org-sh-escaped-newline">\</span>
|
||||
myappname_users/$<span class="org-variable-name">USERNAME</span>
|
||||
cp -r $<span class="org-variable-name">temp_restore_dir</span>/home/$<span class="org-variable-name">USERNAME</span>/.config <span class="org-sh-escaped-newline">\</span>
|
||||
/home/$<span class="org-variable-name">USERNAME</span>/
|
||||
<span class="org-keyword">if</span> [ <span class="org-negation-char">!</span> <span class="org-string">"$?"</span> = <span class="org-string">"0"</span> ]; <span class="org-keyword">then</span>
|
||||
rm -rf $<span class="org-variable-name">temp_restore_dir</span>
|
||||
set_user_permissions
|
||||
backup_unmount_drive
|
||||
<span class="org-keyword">exit</span> 664
|
||||
<span class="org-keyword">fi</span>
|
||||
rm -rf $<span class="org-variable-name">temp_restore_dir</span>
|
||||
<span class="org-keyword">fi</span>
|
||||
<span class="org-keyword">done</span>
|
||||
<span class="org-keyword">fi</span>
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">backup_remote_myappname</span> {
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">this should be the same as backup_local_myappname,</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">but call the backup functions backup_directory_to_friend</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">and backup_database_to_friend</span>
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">restore_remote_vim</span> {
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">this should be the same as restore_local_myappname,</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">but call the restore function restore_directory_from_friend</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">and restore_database_from_friend</span>
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">remove_myappname</span> {
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">if it's a debian package then:</span>
|
||||
apt-get -y remove --purge [my-app-package-name]
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If your app has a MariaDB/MySQL database</span>
|
||||
drop_database myappname
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If your app uses an onion address</span>
|
||||
remove_onion_service myappname ${<span class="org-variable-name">MYAPPNAME_ONION_PORT</span>}
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">install_myappname</span> {
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">if it's a debian package then:</span>
|
||||
apt-get -y install [my-app-package-name]
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If you need to create a MariaDB/MySQL database for the app</span>
|
||||
<span class="org-variable-name">MYAPPNAME_DB_PASSWORD</span>=<span class="org-string">"$(</span><span class="org-sh-quoted-exec">create_password</span><span class="org-string"> 20)"</span>
|
||||
create_database myappname <span class="org-string">"$MYAPPNAME_DB_PASSWORD"</span> $<span class="org-variable-name">MY_USERNAME</span>
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If you need to create an onion address for the app</span>
|
||||
<span class="org-variable-name">MYAPPNAME_ONION_HOSTNAME</span>=$(<span class="org-sh-quoted-exec">add_onion_service</span> myappname <span class="org-sh-escaped-newline">\</span>
|
||||
80 ${<span class="org-variable-name">MYAPPNAME_ONION_PORT</span>})
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Do any other configuration</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Here you might use $ONION_ONLY or</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">$SOME_IMPORTANT_CONFIG_VARIABLE</span>
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Mark the app as having installed successfully</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">If this variable isn't set then it will be assumed that</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">the install has failed</span>
|
||||
<span class="org-variable-name">APP_INSTALLED</span>=1
|
||||
}
|
||||
|
||||
<span class="org-keyword">function</span> <span class="org-function-name">install_interactive_myappname</span> {
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">Interactively obtain some values using dialog, such as</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">domain names. An avatar changing example is:</span>
|
||||
<span class="org-variable-name">data</span>=$(<span class="org-sh-quoted-exec">tempfile</span> 2>/dev/null)
|
||||
<span class="org-keyword">trap</span> <span class="org-string">"rm -f $data"</span> 0 1 2 5 15
|
||||
dialog --title $<span class="org-string">"Change your avatar"</span> <span class="org-sh-escaped-newline">\</span>
|
||||
--backtitle $<span class="org-string">"Freedombone Control Panel"</span> <span class="org-sh-escaped-newline">\</span>
|
||||
--inputbox $<span class="org-string">"Enter a URL for an image. It should be "</span> <span class="org-sh-escaped-newline">\</span>
|
||||
$<span class="org-string">"approximately a square image."</span> 8 75 2>$<span class="org-variable-name">data</span>
|
||||
<span class="org-variable-name">sel</span>=$<span class="org-variable-name">?</span>
|
||||
<span class="org-keyword">case</span> $<span class="org-variable-name">sel</span><span class="org-keyword"> in</span>
|
||||
0)
|
||||
<span class="org-variable-name">MY_FUNKY_AVATAR</span>=$(<$<span class="org-variable-name">data</span>)
|
||||
<span class="org-keyword">if</span> [ ${#<span class="org-variable-name">MY_FUNKY_AVATAR</span>} -gt 3 ]; <span class="org-keyword">then</span>
|
||||
clear
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">do whatever is needed to change the avatar</span>
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">in your app</span>
|
||||
|
||||
dialog --title $<span class="org-string">"Change your avatar"</span> <span class="org-sh-escaped-newline">\</span>
|
||||
--msgbox $<span class="org-string">"Your avatar has been changed"</span> 6 40
|
||||
<span class="org-keyword">fi</span>
|
||||
;;
|
||||
<span class="org-keyword">esac</span>
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">install_myappname will be called automatically after this function</span>
|
||||
}
|
||||
|
||||
<span class="org-comment-delimiter"># </span><span class="org-comment">NOTE: deliberately no exit 0</span>
|
||||
<pre class="src src-bash">freedombone-template --app [name] -e [email] -r [repo url] -c [commit] -d postgresql --dir /etc/myappname --daemon yes > src/freedombone-app-myappname
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
To test your app log into your system, select <b>Exit to command line</b> then gain root powers with:
|
||||
For a Python app without any database:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-bash">sudo su
|
||||
<pre class="src src-bash">freedombone-template --app [name] -e [email] -r [repo url] -c [commit] --dir /etc/myappname --daemon yes > src/freedombone-app-myappname
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Copy your app script to <b>/usr/share/freedombone/apps/freedombone-app-myappname</b>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
And run the admin control panel:
|
||||
For more details see the manpage:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-bash">control
|
||||
<pre class="src src-bash">man freedombone-template
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Select <b>Add/Remove Apps</b> and if all is well then you should see your app listed as installable. Test that installing and removing it works as expected.
|
||||
When your new script is ready for testing you can install it with:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-bash">make install
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Then run the administrator control panel and you should see the new app within <b>Add/Remove apps</b>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Submit your working app to <b><a href="https://github.com/bashrc/freedombone/issues">https://github.com/bashrc/freedombone/issues</a></b>
|
||||
Submit your working app to <b><a href="https://github.com/bashrc/freedombone/issues">https://github.com/bashrc/freedombone/issues</a></b> or create a pull request.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orge29cd52" class="outline-2">
|
||||
<h2 id="orge29cd52">Customising mesh images</h2>
|
||||
<div class="outline-text-2" id="text-orge29cd52">
|
||||
<div id="outline-container-orge25d226" class="outline-2">
|
||||
<h2 id="orge25d226">Customising mesh images</h2>
|
||||
<div class="outline-text-2" id="text-orge25d226">
|
||||
<p>
|
||||
If you want to make your own specially branded version of the mesh images, such as for a particular event, then to change the default desktop backgrounds edit the images within <b>img/backgrounds</b> and to change the available avatars and desktop icons edit the images within <b>img/avatars</b>. Re-create disk images using the instructions shown previously.
|
||||
</p>
|
||||
|
|
Loading…
Reference in New Issue