Getting started with ACF development: Difference between revisions

From Alpine Linux
No edit summary
No edit summary
Line 1: Line 1:
For the impatient, download http://dev.alpinelinux.org/~ncopa/setup-acf-dev and execute as root.
This document describes how to get started with ACF development using the [http://dev.alpinelinux.org/~ncopa/setup-acf-dev setup-acf-dev] script.
 
It is possible to set up a minimal alpine chroot on your desktop (Ubuntu/Debian/Fedore/Gentoo/whatever) where ACF development can be done. This way its not needed to run a fullblown virtual (or real) machine to do ACF development. While this enviroment will be somewhat limited (no grsecurity or other kernel specific stuff) it still does provide all the necessary stuff to do meaningful ACF development.
 
There is a small script to set up this environment here: http://dev.alpinelinux.org/~ncopa/setup-acf-dev


The script will:
The script will:
Line 10: Line 14:
* Create a simple script to enter the chroot
* Create a simple script to enter the chroot


== Invoking the script ==
$ sudo ./setup-acf-dev
usage: setup-acf-dev TARGETDIR


The following environment variables are used:"


<pre>
  WGET        path to wget program (/usr/bin/wget)
#!/bin/sh
  TAR        path to tar program (/usr/bin/tar)
 
  MIRROR      alpine mirror (http://dev.alpinelinux.org/alpine/v1.7)
# bootstrap an alpine installation and set up ACF development
  BASE        name of alpine base package (base.tar.bz2)
# version 1.2
  ACFUSER    non-root username to use in chroot ($SUDO_USER)
 
  ACFSVN      svn repository base (svn://svn.alpinelinux.org/acf)
usage() {
  MODULES    svn modules to checkout (core alpine-baselayout)
        cat << EOF
  CHROOT      chroot program. I.E 'linux32 chroot' (chroot)
usage: $(basename $0) TARGETDIR
  PORT        port for mini_httpd (80)
 
  http_proxy  proxy server ()
The following environment variables are used:"
 
  WGET        path to wget program ($WGET)
  TAR        path to tar program ($TAR)
  MIRROR      alpine mirror ($MIRROR)
  BASE        name of alpine base package ($BASE)
  ACFUSER    non-root username to use in chroot (\$SUDO_USER)
  ACFSVN      svn repository base ($ACFSVN)
  MODULES    svn modules to checkout ($MODULES)
  CHROOT      chroot program. I.E 'linux32 chroot' ($CHROOT)
  PORT        port for mini_httpd ($PORT)
  http_proxy  proxy server ($http_proxy)
 
EOF
        exit 3
}
 
die () {
        echo "$@" >&2
        exit 3
}
 
# read args
 
# set up vars
: ${WGET:="/usr/bin/wget"}
: ${TAR:="/usr/bin/tar"}
: ${MIRROR:="http://dev.alpinelinux.org/alpine/v1.7"}
: ${ACFSVN:="svn://svn.alpinelinux.org/acf"}
: ${MODULES:="core alpine-baselayout"}
: ${BASE:="base.tar.bz2"}
: ${ACFUSER:="$SUDO_USER"}
: ${CHROOT:="chroot"}
: ${PORT:="80"}
 
target=$1
CHD="$CHROOT $target"
[ -n "$http_proxy" ] && PROXY="http_proxy=$http_proxy"
APPS="haserl make mini_httpd subversion sudo vim luafilesystem"
 
# main
[ -z "$target" ] && usage
[ "$target" = "/" ] && die "Bootstrapping Alpine to '/' is probably not a good idea. Aborting..."
[ `whoami` != root ] && die "This script needs to be run as root."
 
while ! getent passwd "$ACFUSER" >/dev/null 2>&1 && [ "$ACFUSER" != root ] ; do
        echo -n "Enter non-root username: "
        read ACFUSER
done
 
mkdir -p "$target"
 
echo ">>> Fetching $MIRROR/$BASE..."
sh -c "$PROXY $WGET -q -O - $MIRROR/$BASE | tar -C \"$target\" -jxv" \
        || die "Failed to fetch or unpack $BASE"


echo ">>> Creating missing dirs..."
So if you for example use a 64 bit Gentoo desktop you can run the script as:
for dir in proc sys dev home; do
        mkdir -p "$target/$dir"
done


echo ">>> Installing busybox links..."
CHROOT='linux32 chroot' ./setup-acf-dev acfroot
# create fake /proc/self/exe
mkdir -p "$target/proc/self"
ln -s /bin/busybox "$target/proc/self/exe"
$CHD /bin/busybox --install -s
rm -r "$target/proc/self"


if [ -f /etc/resolv.conf ]; then
Then will all chroot invocations be in probper 32 bit mode.
        echo ">>> Copying /etc/resolv.conf..."
        cp /etc/resolv.conf "$target/etc/"
fi


echo ">>> Setting up APK_PATH..."
To just set up a chroot in the driectory ''acfroot'' you run the script as:
mkdir -p "$target/etc/apk"
echo "APK_PATH=$MIRROR/apks" >> "$target/etc/apk/apk.conf"


if [ -n "$http_proxy" ]; then
$ sudo ./setup-acf-dev acfroot
        echo ">>> Setting up http_proxy..."
>>> Fetching http://dev.alpinelinux.org/alpine/v1.7/base.tar.bz2...
        sed -i -e '/^http_proxy=/d' "$target/etc/profile"
./
        echo "http_proxy=$http_proxy" >> "$target/etc/profile"
./var/
fi
./var/db/
./var/db/apk/
./var/db/apk/uclibc-0.9.28.3.tar.gz
 
...
>>> Creating .vimrc...
>>> Creating enter-chroot script...
>>>
>>> Setup Completed. Enter the chroot environement with (as root):
>>>
>>>    acfroot/enter-chroot
>>>
>>> Once inside the chroot the privileges will drop to 'ncopa'.
>>> You can start and stop mini_httpd within chroot by executing:
>>>
>>>    sudo /etc/init.d/mini_httpd start
>>>    sudo /etc/init.d/mini_httpd stop
>>>
>>> You can specify the port in /etc/mini_httpd.conf
>>>
>>> Remember to install the acf module to activate changes:
>>>
>>>    sudo make install
>>>


echo ">>> Settig up user $ACFUSER..."
== Entering and leaving the ACF chroot ==
$CHD adduser -D $ACFUSER
The help text will tell you how to enter the chroot. Please note that you need to execute teh enter-chroot script as root. The enter-chrrot script will mount a /proc inside the chroot and it will then change the permissions to the user created by the ''setup-acf-dev'' script


echo ">>> Installing applications..."
If you installed the ACF environment in teh acfroot directory you enter the chroot byt typing '''sudo acfroot/enter-chroot'''
$CHD /bin/sh -c "$PROXY apk_add $APPS"


echo ">>> Setting up $ACFUSER as passwordless sudo user..."
On my gentoo system it looks like this:
sed -i -e "/^$ACFUSER /d" "$target/etc/sudoers"
ncopa@nc ~ $ sudo acfroot/enter-chroot
echo "$ACFUSER ALL=(ALL) NOPASSWD: ALL" >> "$target/etc/sudoers"
Password:
Entering ACF develmopment chroot. Type 'exit' or press ctrl-d to leave.
~ $  


echo ">>> Setting up mini_httpd..."
== Starting the web server ==
sed -i -e "/^MINI_HTTPD.*/d" "$target/etc/conf.d/mini_httpd"
After entering the chroot you can start the webserver with:
echo 'MINI_HTTPD_OPTS="-C /etc/mini_httpd.conf"
sudo /etc/init.d/mini_httpd start
MINI_HTTPD_DOCROOT=/var/www/localhost/htdocs' \
        >> "$target/etc/conf.d/mini_httpd"
cat << EOF > "$target/etc/mini_httpd.conf"
nochroot
dir=/var/www/localhost/htdocs
user=nobody
logfile=/var/log/mini_httpd.log
cgipat=cgi-bin**
port=$PORT
EOF
$CHD mkdir -p /var/www/localhost
$CHD ln -sf /usr/share/acf/www /var/www/localhost/htdocs


for svnmod in $MODULES ; do
By default it will bind to port 80. If you need to change the port you can do that by editing ''/etc/mini_httpd.conf''.
        echo ">>> Checking out ACF module $svnmod"
        $CHD su $ACFUSER -c "svn co $ACFSVN/$svnmod/trunk ~/$svnmod"
        echo ">>> Installing ACF module $svnmod"
        $CHD su $ACFUSER -c "cd ~/$svnmod && sudo make install"
done


echo ">>> Creating .vimrc..."
Point your web brower to http://localhost and you should see the Alpine webconf.
cat <<EOF > "$target/home/$ACFUSER/.vimrc"
noremap <F9> <C-C>:w<CR> :! sudo make install<CR>
inoremap <F9> <C-C>:w<CR> :! sudo make install<CR>
EOF


echo ">>> Creating enter-chroot script..."
== Working with the source files ==
cat <<EOF > "$target/enter-chroot"
After entering the chroot you have the acf modules checked out. Currently there are only 2 modules, alpine-buildroot and core. Enter the module you are interested in, make a change, and run '''sudo make install''' to install the changes. The .vimrc created has a keymap for ''F9'' that will save file and execute ''sudo make install''. So during normal development its jsut to press '''F9''' and refresh the webbrowser to see the changes.
dir=\$(dirname \$0)
mount --bind /proc \$dir/proc
echo "Entering ACF develmopment chroot. Type 'exit' or press ctrl-d to leave."
$CHROOT \$(dirname \$0) /bin/sh -c 'su -l $ACFUSER'  
echo "Left ACF development chroot."
umount \$dir/proc
EOF
chmod +x "$target/enter-chroot"


cat <<EOF
== Adding files ==
>>>
If you want to add a file, you need to make the '''Makefile''' aware of your file. If you forget this step the file will not be included in the distribution source package and not in the final apk package. To detect those errors early, '''always install edited files with make install''.
>>> Setup Completed. Enter the chroot environement with (as root):
>>>
>>>    $target/enter-chroot
>>>
>>> Once inside the chroot the privileges will drop to '$ACFUSER'.
>>> You can start and stop mini_httpd within chroot by executing:
>>>
>>>    sudo /etc/init.d/mini_httpd start
>>>    sudo /etc/init.d/mini_httpd stop
>>>
>>> You can specify the port in /etc/mini_httpd.conf
>>>
>>> Remember to install the acf module to activate changes:
>>>
>>>    sudo make install
>>>
EOF


Before committing anything to svn, also make sure that ''make install'' works.


</pre>
''To be Continued''

Revision as of 15:29, 25 October 2007

This document describes how to get started with ACF development using the setup-acf-dev script.

It is possible to set up a minimal alpine chroot on your desktop (Ubuntu/Debian/Fedore/Gentoo/whatever) where ACF development can be done. This way its not needed to run a fullblown virtual (or real) machine to do ACF development. While this enviroment will be somewhat limited (no grsecurity or other kernel specific stuff) it still does provide all the necessary stuff to do meaningful ACF development.

There is a small script to set up this environment here: http://dev.alpinelinux.org/~ncopa/setup-acf-dev

The script will:

  • Set up a small alpine chroot environment
  • Set up a user in the environment with sudo access
  • Install needed applications like subversion, http server and vim
  • Configure the http server
  • Check out ACF modules from svn repository and install them in the environemt
  • Create a simple .vimrc with useful key binding
  • Create a simple script to enter the chroot

Invoking the script

$ sudo ./setup-acf-dev 
usage: setup-acf-dev TARGETDIR
The following environment variables are used:"
  WGET        path to wget program (/usr/bin/wget)
  TAR         path to tar program (/usr/bin/tar)
  MIRROR      alpine mirror (http://dev.alpinelinux.org/alpine/v1.7)
  BASE        name of alpine base package (base.tar.bz2)
  ACFUSER     non-root username to use in chroot ($SUDO_USER)
  ACFSVN      svn repository base (svn://svn.alpinelinux.org/acf)
  MODULES     svn modules to checkout (core alpine-baselayout)
  CHROOT      chroot program. I.E 'linux32 chroot' (chroot)
  PORT        port for mini_httpd (80)
  http_proxy  proxy server ()

So if you for example use a 64 bit Gentoo desktop you can run the script as:

CHROOT='linux32 chroot' ./setup-acf-dev acfroot

Then will all chroot invocations be in probper 32 bit mode.

To just set up a chroot in the driectory acfroot you run the script as:

$ sudo ./setup-acf-dev acfroot
>>> Fetching http://dev.alpinelinux.org/alpine/v1.7/base.tar.bz2...
./
./var/
./var/db/
./var/db/apk/
./var/db/apk/uclibc-0.9.28.3.tar.gz
 
...

>>> Creating .vimrc...
>>> Creating enter-chroot script...
>>>
>>> Setup Completed. Enter the chroot environement with (as root):
>>>
>>>     acfroot/enter-chroot
>>>
>>> Once inside the chroot the privileges will drop to 'ncopa'.
>>> You can start and stop mini_httpd within chroot by executing:
>>>
>>>     sudo /etc/init.d/mini_httpd start
>>>     sudo /etc/init.d/mini_httpd stop
>>>
>>> You can specify the port in /etc/mini_httpd.conf
>>>
>>> Remember to install the acf module to activate changes:
>>>
>>>     sudo make install
>>>

Entering and leaving the ACF chroot

The help text will tell you how to enter the chroot. Please note that you need to execute teh enter-chroot script as root. The enter-chrrot script will mount a /proc inside the chroot and it will then change the permissions to the user created by the setup-acf-dev script

If you installed the ACF environment in teh acfroot directory you enter the chroot byt typing sudo acfroot/enter-chroot

On my gentoo system it looks like this:

ncopa@nc ~ $ sudo acfroot/enter-chroot 
Password:
Entering ACF develmopment chroot. Type 'exit' or press ctrl-d to leave.
~ $ 

Starting the web server

After entering the chroot you can start the webserver with:

sudo /etc/init.d/mini_httpd start

By default it will bind to port 80. If you need to change the port you can do that by editing /etc/mini_httpd.conf.

Point your web brower to http://localhost and you should see the Alpine webconf.

Working with the source files

After entering the chroot you have the acf modules checked out. Currently there are only 2 modules, alpine-buildroot and core. Enter the module you are interested in, make a change, and run sudo make install to install the changes. The .vimrc created has a keymap for F9 that will save file and execute sudo make install. So during normal development its jsut to press F9 and refresh the webbrowser to see the changes.

Adding files

If you want to add a file, you need to make the Makefile' aware of your file. If you forget this step the file will not be included in the distribution source package and not in the final apk package. To detect those errors early, always install edited files with make install.

Before committing anything to svn, also make sure that make install works.

To be Continued