Getting started with ACF development: Difference between revisions

From Alpine Linux
No edit summary
(replace /etc/init.d with rc-service)
 
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
For the impatient, download http://dev.alpinelinux.org/~ncopa/setup-acf-dev and execute as root.
{{ Obsolete }}
This document describes how to get started with ACF development using the [https://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: https://dev.alpinelinux.org/~ncopa/setup-acf-dev


The script will:
The script will:
Line 10: Line 15:
* 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 (https://dev.alpinelinux.org/alpine/v1.7 {{Dead link}})
# 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 (<nowiki>svn://svn.alpinelinux.org/acf</nowiki>)
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
So if you for example use a 64 bit Gentoo desktop you can run the script as:
        echo -n "Enter non-root username: "
        read ACFUSER
done


mkdir -p "$target"
CHROOT='linux32 chroot' ./setup-acf-dev acfroot


echo ">>> Fetching $MIRROR/$BASE..."
Then will all chroot invocations be in probper 32 bit mode.
sh -c "$PROXY $WGET -q -O - $MIRROR/$BASE | tar -C \"$target\" -jxv" \
        || die "Failed to fetch or unpack $BASE"


echo ">>> Creating missing dirs..."
To just set up a chroot in the driectory ''acfroot'' you run the script as:
for dir in proc sys dev home; do
        mkdir -p "$target/$dir"
done


echo ">>> Installing busybox links..."
$ sudo ./setup-acf-dev acfroot
# create fake /proc/self/exe
>>> Fetching https://dev.alpinelinux.org/alpine/v1.7/base.tar.bz2...
mkdir -p "$target/proc/self"
./
ln -s /bin/busybox "$target/proc/self/exe"
./var/
$CHD /bin/busybox --install -s
./var/db/
rm -r "$target/proc/self"
./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
>>>


if [ -f /etc/resolv.conf ]; then
== Entering and leaving the ACF chroot ==
        echo ">>> Copying /etc/resolv.conf..."
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
        cp /etc/resolv.conf "$target/etc/"
fi


echo ">>> Setting up APK_PATH..."
If you installed the ACF environment in teh acfroot directory you enter the chroot byt typing '''sudo acfroot/enter-chroot'''
mkdir -p "$target/etc/apk"
echo "APK_PATH=$MIRROR/apks" >> "$target/etc/apk/apk.conf"


if [ -n "$http_proxy" ]; then
On my gentoo system it looks like this:
        echo ">>> Setting up http_proxy..."
ncopa@nc ~ $ sudo acfroot/enter-chroot
        sed -i -e '/^http_proxy=/d' "$target/etc/profile"
Password:
        echo "http_proxy=$http_proxy" >> "$target/etc/profile"
Entering ACF develmopment chroot. Type 'exit' or press ctrl-d to leave.
fi
~ $  


echo ">>> Settig up user $ACFUSER..."
== Starting the web server ==
$CHD adduser -D $ACFUSER
After entering the chroot you can start the webserver with:
sudo rc-service mini_httpd start


echo ">>> Installing applications..."
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''.
$CHD /bin/sh -c "$PROXY apk_add $APPS"


echo ">>> Setting up $ACFUSER as passwordless sudo user..."
Point your web brower to <nowiki>http://localhost</nowiki> and you should see the Alpine webconf.
sed -i -e "/^$ACFUSER /d" "$target/etc/sudoers"
echo "$ACFUSER ALL=(ALL) NOPASSWD: ALL" >> "$target/etc/sudoers"


echo ">>> Setting up mini_httpd..."
== Working with the source files ==
sed -i -e "/^MINI_HTTPD.*/d" "$target/etc/conf.d/mini_httpd"
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.
echo 'MINI_HTTPD_OPTS="-C /etc/mini_httpd.conf"
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
== Adding files ==
        echo ">>> Checking out ACF module $svnmod"
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.
        $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..."
Before committing anything to svn, also make sure that ''make install'' works.
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..."
''To be Continued''
cat <<EOF > "$target/enter-chroot"
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
= Setting up a acf-dev without chroot =
>>>
The following assumes that you already have a functioning Alpine Linux and that you plan to run this on a Alpine Linux
>>> Setup Completed. Enter the chroot environement with (as root):
* Install needed packages
>>>
apk_add haserl mini_httpd subversion luaposix json4lua
>>>    $target/enter-chroot
* Check out the acf-core (and acf-devtools)
>>>
git clone https://gitlab.alpinelinux.org/acf/acf-core.git /usr/share/acf
>>> Once inside the chroot the privileges will drop to '$ACFUSER'.
svn co <nowiki>svn://svn.alpinelinux.org/acf/devtools/trunk</nowiki> /usr/share/acf/app/devtools
>>> You can start and stop mini_httpd within chroot by executing:
* Create needed folders and symlinks
>>>
mkdir -p /var/www/localhost/
>>>    sudo /etc/init.d/mini_httpd start
ln -s /usr/share/acf/www/ /var/www/localhost/htdocs
>>>    sudo /etc/init.d/mini_httpd stop
* Edit the /etc/mini_httpd.conf
>>>
nochroot
>>> You can specify the port in /etc/mini_httpd.conf
dir=/var/www/localhost/htdocs
>>>
user=nobody
>>> Remember to install the acf module to activate changes:
logfile=/var/log/mini_httpd.log
>>>
cgipat=cgi-bin**
>>>    sudo make install
port=80
>>>
* Edit the /etc/conf.d/mini_httpd
EOF
MINI_HTTPD_OPTS="-C /etc/mini_httpd.conf"
MINI_HTTPD_DOCROOT=/var/www/localhost/htdocs
* Create/modify /etc/acf/acf.conf
mkdir /etc/acf/
echo "appdir=/usr/share/acf/app/
libdir=/usr/share/acf/lib/
skin=static" > /etc/acf/acf.conf
* Startup your mini_httpd
rc-service mini_httpd start


* Now update your projects
Browse to your ip-address to your acf-dev machine (using firefox or some other web-browser).
Click on "DevTools" > "SVN status (for ACF)" and it helps you download all possible projects.
It should work now!


</pre>
[[Category:ACF]]

Latest revision as of 09:50, 17 November 2023

This material is obsolete ...

Please feel free to help us make an up-to-date version. (Discuss)

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: https://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 (https://dev.alpinelinux.org/alpine/v1.7 [Dead Link])
  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 https://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 rc-service 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

Setting up a acf-dev without chroot

The following assumes that you already have a functioning Alpine Linux and that you plan to run this on a Alpine Linux

  • Install needed packages
apk_add haserl mini_httpd subversion luaposix json4lua
  • Check out the acf-core (and acf-devtools)
git clone https://gitlab.alpinelinux.org/acf/acf-core.git /usr/share/acf
svn co svn://svn.alpinelinux.org/acf/devtools/trunk /usr/share/acf/app/devtools
  • Create needed folders and symlinks
mkdir -p /var/www/localhost/
ln -s /usr/share/acf/www/ /var/www/localhost/htdocs
  • Edit the /etc/mini_httpd.conf
nochroot
dir=/var/www/localhost/htdocs
user=nobody
logfile=/var/log/mini_httpd.log
cgipat=cgi-bin**
port=80
  • Edit the /etc/conf.d/mini_httpd
MINI_HTTPD_OPTS="-C /etc/mini_httpd.conf"
MINI_HTTPD_DOCROOT=/var/www/localhost/htdocs
  • Create/modify /etc/acf/acf.conf
mkdir /etc/acf/
echo "appdir=/usr/share/acf/app/
libdir=/usr/share/acf/lib/
skin=static" > /etc/acf/acf.conf
  • Startup your mini_httpd
rc-service mini_httpd start
  • Now update your projects

Browse to your ip-address to your acf-dev machine (using firefox or some other web-browser). Click on "DevTools" > "SVN status (for ACF)" and it helps you download all possible projects. It should work now!