summaryrefslogtreecommitdiffstats
path: root/alpinelinux.module
blob: eeff415748bfa2dfdad2a50bf0d502a117e4f221 (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
<?php

function alpinelinux_menu() {
    $items['admin/config/alpinelinux'] = array(
        'title' => 'Alpine Linux settings',
        'description' => 'Configure Alpine Linux settings',
        'page callback' => 'system_admin_menu_block_page',
        'access arguments' => array('admin alpinelinux'),
        //system_admin_menu_block_page needs admin inc
        'file' => 'system.admin.inc',
        'file path' => drupal_get_path('module', 'system'),
    );

    $items['admin/config/alpinelinux/settings'] = array(
        'title' => 'Settings',
        'description' => 'Configure Alpine Linux settings',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('alpinelinux_settings'),
        'access arguments' => array('admin alpinelinux'),
    );
    $items['wiki'] = array(
        'page callback' => 'alpinelinux_wiki_redirect',
        'access callback' => TRUE,
        'type' => MENU_LOCAL_TASK
    );
    $items['w'] = array(
        'page callback' => 'alpinelinux_wiki_redirect',
        'access callback' => TRUE,
        'type' => MENU_LOCAL_TASK
    );
    return $items;
}

function alpinelinux_permission() {
    return array(
        'admin alpinelinux' => array(
            'title' => t('Administer Alpine Linux settings'),
            'description' => t('Access permissions for Alpine Linux settings'),
        ),
    );
}

function alpinelinux_cron() {
        alpinelinux_latest_releases();
        alpinelinux_mirrors();
}

function alpinelinux_settings($form) {
    $form['settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('Alpine Linux settings'),
    );
    $form['settings']['alpinelinux_latest_link_x86'] = array(
        '#type' => 'textfield',
        '#title' => t('URL to latest x86 releases file'),
        '#description' => t('A text file which holds information about Alpine Linux latest releases'),
        '#default_value' => variable_get('alpinelinux_latest_link_x86', '')
    );
    $form['settings']['alpinelinux_latest_link_x86_64'] = array(
        '#type' => 'textfield',
        '#title' => t('URL to latest x86_64 releases file'),
        '#description' => t('A text file which holds information about Alpine Linux latest releases'),
        '#default_value' => variable_get('alpinelinux_latest_link_x86_64', '')
    );
    $form['settings']['alpinelinux_mirrors_link'] = array(
        '#type' => 'textfield',
        '#title' => t('URL to mirrors txt file'),
        '#description' => t('A text file which holds information about Alpine Linux mirrors'),
        '#default_value' => variable_get('alpinelinux_mirrors_link', '')
    );
    
    return system_settings_form($form);
}

function alpinelinux_latest_releases() {
    $latest = variable_get('alpinelinux_latest_link_x86', '');
    $latest = file($latest);
    $result = array();
    if ($latest) {
        foreach ($latest as $key => $line) {
            $result[$key] = explode(" ", $line);
        }
        variable_set('alpinelinux_releases_x86', $result);
    } else {
        watchdog('alpine', 'Failed to get latest x86 alpine release information', array(), WATCHDOG_WARNING, NULL);
    }
    $latest = variable_get('alpinelinux_latest_link_x86_64', '');
    $latest = file($latest);
    $result = array();
    if ($latest) {
        foreach ($latest as $key => $line) {
            $result[$key] = explode(" ", $line);
        }
        variable_set('alpinelinux_releases_x86_64', $result);
    } else {
        watchdog('alpine', 'Failed to get latest x86_64 alpine release information', array(), WATCHDOG_WARNING, NULL);
    }
}


function alpinelinux_mirrors() {
    $mirrors = variable_get('alpinelinux_mirrors_link', '');
    $mirrors = file($mirrors);
    if ($mirrors) {
        variable_set('alpinelinux_mirrors', $mirrors);
    } else {
        watchdog('alpine', 'Failed to get latest alpine mirror information', array(), WATCHDOG_WARNING, NULL);
    }
}

function alpinelinux_wiki_redirect() {
    $wiki_url = 'http://wiki.alpinelinux.org/wiki/';
    if ((arg(0) == 'wiki') || (arg(0) == 'w')) {
        $url = (arg(1)) ? $wiki_url . arg(1) : $wiki_url;
        drupal_goto($url);
    }
}