Giter Club home page Giter Club logo

utils's Introduction

utils

Build Status

utils is a repository of scripts used by the Open Computing Facility at the University of California, Berkeley.

What belongs here

Scripts for humans do

In general, scripts which might be executed by a person should go here. System scripts (things that go primarily in cronjobs or similar) should go in the ocf/puppet repo instead.

Scripts of all languages are welcome, and should be organized into appropriate directories. Use staff/ for anything that will typically only be executed by staff.

Libraries don't

If your utility is meant to be imported, it should probably go in ocflib instead. If you're writing a script whose functionality might be useful elsewhere, separate that out, put it in ocflib, and call it from a binary in this repo.

General best practices

All languages

  • Executable files should be marked executable, contain a proper shebang, and generally not have a file extension.

Python

  • Use ocflib functionality when it exists, and put reusable code there (and call it from an executable here).
  • When possible, target Python 3.5 and 3.7 (same versions as ocflib)
  • Generally follow PEP8.

Shell/Bash

  • Use /bin/bash over /bin/sh unless your script is for some alien environment where there is no bash. Don't be afraid to use bashisms.
  • Typically add set -euo pipefail, especially for any complicated scripts. This (a) stops on errors, (b) errors on accessing undefined variables, and (c) errors on failures in the middle of a pipeline. Together these make Bash into something resembling a passable programming language.
  • Quote things and otherwise follow best practices.

Other languages

  • Consider writing in Python instead.

utils's People

Contributors

abizer avatar axmmisaka avatar baisang avatar boomaa23 avatar cg505 avatar chriskuehl avatar daradib avatar dkess avatar douglaslwong avatar ethanhs avatar ethanwu10 avatar fawaf avatar fydai avatar gundralaa avatar ja5087 avatar jvperrin avatar kalissaac avatar keur avatar kpengboy avatar matthew-mcallister avatar mcint avatar mrminos avatar naderm avatar nattofriends avatar nickimpicciche avatar nikhiljha avatar oliver-ni avatar seanlobo avatar singingtelegram avatar tahabi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

utils's Issues

easywp broken

After #129 was merged, easywp does not work on new accounts because makemysql fails (since there is no existing config to update the DB password in).

signat weird problem

the python error shouldn't happen as the request doesn't require authencate at all (just curl https://orapps.berkeley.edu/StudentGroupServiceV2/service.asmx/SignatoriesActiveStudentGroups?UID=1234567).
The problems:

  1. supernova is running ldap3 2.1.1 and other machines are running ldap3 1.2.2. lower ldap version caused the respond 'calnetUid' to be a list of strings ['1234567'], but on supernova it's a string ('1234567')
  2. supernova is running ocflib june 2019 but normal computers are running ocflib sept2019.
    this pr #171 (51924bf809fbeccc9b0087f78d61b71eda47d49e) screwed up things in some functions in ocflib/account/search.py :
    e.g.
    calnet_uid = int(calnet_uid)
    return users_by_filter(
        '(calnetUid={})'.format(escape_filter_chars(calnet_uid))
    )

calnet_uid = int(calnet_uid) actually escaped filter chars, and escape_filter_chars() only takes in str, int or list will all screw it up.

My suggestions:

  1. update ldap3 on all machines
  2. update ocflib on supernova
  3. revert 51924b

Move ldap-lint to puppet

The utils repository should be reserved for scripts called by a human. ldap-lint is called daily by firestorm, so it should be moved there.

minutes: distinguish between people on/not on BoD

Right now, the minutes script leaves one giant Attendance block that lists everyone who showed up to BoD. This makes it hard to tell after the fact who joined BoD and who was just a visitor, makes it impossible to fully rebuild the membership file if it gets corrupted, and makes things like bod ls unreliable.

We should still have the minute-taker fill in a single attendance block, but after that, the script should split that block into three blocks: current BoD members, guests who joined BoD, and guests who didn't join BoD.

Give more user feedback on check/signat/etc.

It is currently unclear to the user that these commands cannot be used properly outside of supernova. This is made clear if 'usage' is viewed, but if you just enter a command unknowingly you will see a Python error on the command line. I would recommend that we implement a check to change the output and hide the error if the user is not on supernova.

better awk for ocf-tv

#39 needs to have the awk stuff in volume() improved
also it bugs out on 0% due to some spacing issue. Might be useful to forget trying to parse anything and just dump the entire line.

kill current processes on sorry

When an account is sorried, any current processes running as that user should be kill -9d on any machines they could potentially be running on (tsunami, death, vampires, segfault, corruption, and maybe more?).

Also, user crontabs should be disabled on these machines. Cron won't be able to run anything as the user but will still try, filling our logs with garbage. A recent compromise included adding stuff to crontab.

Convert python 2 scripts to python 3

There are a few Python 2 scripts left; going with our broader migration to Python 3, we should convert these holdouts over to the current decade.

The specific scripts which aren't slated for removal according to my knowledge are:

./acct/chsh
./acct/update-email
./staff/acct/note
./staff/sys/apt-dated
./staff/web/bludgeon
./net/pyrc

migrate-vm: strip CPU information from XML

when moving VMs from hypervisors with incompatible CPU types, we should strip the CPU type field from the KVM XML domain metadata so we can just start VMs easily without having to virsh edit <domname> to fix the CPU information.

Update ocf-tv script

Because of updates to ocf-tv, the current sink value will not work. This needs to be updated.

Rewrite sorry/unsorry in python

Currently sorry and unsorry are pretty complicated scripts to be written in bash and have commented out sections, shellcheck-ignored warnings, etc. It's also tough to know if things done in the sorry script are undone properly in the unsorry script (setting file permissions for instance), so rewriting these two to use common functions and better error handling (maybe even be in the same script file) would be useful.

ldap-lint should check staff groups

  • Anyone in ocfroot should be in ocfstaff
  • Anyone in ocfroot should have a /root and /admin (this involves kerberos too)

Ideally we would also list /root and /admin principals, and ensure these people are in appropriate LDAP groups. But not sure if we can do that easily without requiring ldap-lint to have a privileged kerberos bind

makemysql: automatically update db password in wordpress

If a user has a Wordpress website set up and resets their database password, the site becomes completely unusable (even to go into settings and change it). Fixing it requires SSHing in and changing the password in the configuration file.

Luckily, we can automate this with wpcli. The makemysql script should also cd into the public_html folder and run wp config set DB_PASSWORD newpasswordgoeshere. It's OK if the command fails since that just means the user doesn't have a Wordpress site.

Store .sorry and .oldshell outside of user dir

We currently store the sorry reason and old shell in the ~/.sorry and ~/.oldshell files respectively of the sorried user. This is a dangerous practice, because:

  • If the user had something valuable in the ~/.sorry file, we overwrite it.
  • If the user had an existing ~/.oldshell file, we lose the info about the old shell.
  • Worst of all, ~/.sorry could be a symlink created by an attacker to point to important system files. In that case, we would just overwrite those files. (And the scary thing is the script, running as root, actually has permissions to do this.)

We should store this information elsewhere, preferably in a directory that only we control.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.