summaryrefslogtreecommitdiff
path: root/src/fifa.sh
blob: 28bc8c8510ad73230f534a184b96adfed4a50fb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash


###### Set some default variables or get them from the setup script ######
TITLE="Flexible Installer Framework for Arch linux"
eval `grep ^LOG= /arch/setup`
# flags like --noconfirm should not be specified here.  it's up to the profile to decide the interactivity
PACMAN=pacman
PACMAN_TARGET="pacman --root $TARGET_DIR --config /tmp/pacman.conf"



###### Miscalleaneous functions ######

usage ()
{
	if [ "$var_UI_TYPE" = dia ]
	then
		#TODO: do this
		true
	else
		echo "$0 <profilename>"
		echo "If the profilename starts with 'http://' it will be wget'ed.  Otherwise it's assumed to be a profile file like /home/arch/fifa/profile-<profilename>"
		echo "If you wrote your own profile, you can also save it yourself as /home/arch/fifa/profile-custom or something like that"
		echo "Available profiles:"
		ls -l /home/arch/fifa/profile-*
		echo "Extra info:"
		echo "There is a very basic but powerfull workflow defined by variables, phases and workers.  Depending on the profile you choose (or write yourself), these will differ."
		echo "they are very recognizable and are named like this:"
		echo " - variable -> var_<foo>"
		echo " - phase    -> phase_<bar> (a function that calls workers and maybe does some stuff by itself.  There are 4 phases: preparation, basics, system, finish. (executed in that order)"
		echo " - worker   -> worker_<baz> ( a worker function, called by a phase. implements some specific logic. eg runtime_packages, prepare_disks, package_list etc)"
		echo "If you specify a profile name other then base, the base profile will be sourced first, then the specific profile.  This way you only need to override specific things."
		echo "Notes:"
		echo " - you _can_ override _all_ variables and functions in this script, but you should be able to achieve your goals by overriding things of these 3 classes)"
		echo " - you _must_ specify a profile, to avoid errors. take 'base' if unsure"
		echo " - don't edit the base profile (or any other that comes by default), rather make your own"
	fi
}


##### "These functions would fit more in lib-ui, but we need them immediately" functions ######

die_error ()
{
	if [ "$var_UI_TYPE" = dia ]
	then
		DIALOG --msgbox "Error: $@" 0 0
	else
		echo "ERROR: $@"
	fi
	exit 2
}


notify ()
{
	if [ "$var_UI_TYPE" = dia ]
	then
		#TODO: implement this
		true
	else
		echo "$@"
	fi
}


###### Core functions ######

load_profile()
{
	[ -z "$1" ] && die_error "load_profile needs a profile argument"
	notify "Loading profile $1 ..."
	if [[ $1 =~ ^http:// ]]
	then
		profile=/home/arch/fifa/profile-downloaded-`basename $1`
		wget $1 -q -O $profile >/dev/null || die_error "Could not download profile $1" 
	else
		profile=/home/arch/fifa/profile-$1
	fi
	[ -f "$profile" ] && source "$profile" || die_error "Something went wrong while sourcing profile $profile"
}


load_library ()
{
	[ -z "$1" ] && die_error "load_library needs a library argument"
	for library in $@
	do
		notify "Loading library $library ..."
		source $library || die_error "Something went wrong while sourcing library $library"
	done
}


execute ()
{
	[ -z "$1" -o -z "$2" ] && die_error "Use the execute function like this: execute <type> <name> with type=phase/worker"
	[ "$1" != phase -a "$1" != worker ] && die_error "execute's first argument must be a valid type (phase/worker)"
	[ "$1" = phase ]  && notify "******* Executing phase $2"
	[ "$1" = worker ] && notify "*** Executing worker $2"
	if type -t $1_$2 | grep -q function
	then
		PWD_BACKUP=`pwd`
		$1_$2
		cd $PWD_BACKUP
	else
		die_error "$1 $2 is not defined!"
	fi
}



###### perform actual logic ######
echo "Welcome to $TITLE"
[ -z "$1" ] && usage && exit 1

mount -o remount,rw / &>/dev/null 

load_library /home/arch/fifa/lib/lib-*.sh

[ "$1" != base ] && load_profile base
load_profile $1

execute phase preparation
execute phase basics
execute phase system
execute phase finish